def f(context): # Here it also can have long spinners with sel.ajax_timeout(90): toolbar.select('Lifecycle', tb_item) provider = context['provider'] template_name = context['template_name'] template_select_form.template_table._update_cache() template = template_select_form.template_table.find_row_by_cells({ 'Name': template_name, 'Provider': provider if isinstance(provider, basestring) else provider.name }) if template: sel.click(template) # In order to mitigate the sometimes very long spinner timeout, raise the timeout with sel.ajax_timeout(90): if current_version() < "5.4": sel.click(submit_button) else: sel.click( form_buttons.FormButton("Continue", force_click=True)) else: raise TemplateNotFound( 'Unable to find template "{}" for provider "{}"'.format( template_name, provider.key))
def test_provider_add_with_bad_port(provider): """ Tests provider add with bad port (incorrect)""" provider.port = 8888 with error.expected('Credential validation was not successful: Unable to connect to {}:8888' .format(provider.hostname)): with sel.ajax_timeout(120): provider.create(validate_credentials=True)
def test_hawkular_crud(provider): """Test provider add with good credentials. """ with sel.ajax_timeout(120): provider.create(cancel=False, validate_credentials=True) # UI validation, checks whether data provided from Hawkular provider matches data in UI provider.validate_stats(ui=True) # DB validation, checks whether data provided from Hawkular provider matches data in DB provider.validate_stats() # validates Properties section of provider's summary page provider.validate_properties() # validates that provider is refreshed in DB and in UI assert provider.is_refreshed(method='ui'), "Provider is not refreshed in UI" assert provider.is_refreshed(method='db'), "Provider is not refreshed in DB" old_name = provider.name with update(provider): provider.name = str(uuid.uuid4()) # random uuid with update(provider): provider.name = old_name # old name provider.delete(cancel=False) provider.wait_for_delete()
def select_provision_image(template_name, provider): """ Navigate to provision and select the template+click continue, leaving UI on provision form :param template_name: The image/template name to select :param provider: Provider where the image/template resides :return: none """ logger.debug( 'Selecting an image {} from provider {} for provisioning'.format( template_name, provider.name)) navigate_to(Instance, 'Provision') template = image_select_form.template_table.find_row_by_cells({ 'Name': template_name, 'Provider': provider.name }) if template: sel.click(template) # In order to mitigate the sometimes very long spinner timeout, raise the timeout with sel.ajax_timeout(90): sel.click(form_buttons.FormButton("Continue", force_click=True)) else: raise TemplateNotFound( 'Unable to find template "{}" for provider "{}"'.format( template_name, provider.key))
def test_hawkular_crud(provider): """Test provider add with good credentials. """ with sel.ajax_timeout(120): provider.create(cancel=False, validate_credentials=True) # UI validation, checks whether data provided from Hawkular provider matches data in UI provider.validate_stats(ui=True) # DB validation, checks whether data provided from Hawkular provider matches data in DB provider.validate_stats() # validates Properties section of provider's summary page provider.validate_properties() # validates that provider is refreshed in DB and in UI assert provider.is_refreshed( method='ui'), "Provider is not refreshed in UI" assert provider.is_refreshed( method='db'), "Provider is not refreshed in DB" old_name = provider.name with update(provider): provider.name = str(uuid.uuid4()) # random uuid with update(provider): provider.name = old_name # old name provider.delete(cancel=False) provider.wait_for_delete()
def login(username, password, submit_method=_js_auth_fn): """ Login to CFME with the given username and password. Optionally, submit_method can be press_enter_after_password to use the enter key to login, rather than clicking the button. Args: user: The username to fill in the username field. password: The password to fill in the password field. submit_method: A function to call after the username and password have been input. Raises: RuntimeError: If the login fails, ie. if a flash message appears """ if not logged_in() or username is not current_username(): if logged_in(): logout() # workaround for strange bug where we are logged out # as soon as we click something on the dashboard sel.sleep(1.0) logger.debug('Logging in as user %s' % username) fill(form, {'username': username, 'password': password}) with sel.ajax_timeout(90): submit_method() flash.assert_no_errors() thread_locals.current_user = User(username, password, _full_name())
def test_provider_add_with_bad_hostname(provider): """ Tests provider add with bad hostname (incorrect)""" provider.hostname = 'incorrect' with error.expected( 'Credential validation was not successful: Unable to connect to incorrect:{}' .format(provider.port)): with sel.ajax_timeout(120): provider.create(validate_credentials=True)
def test_provider_add_with_bad_port(provider): """ Tests provider add with bad port (incorrect)""" provider.endpoints['default'].api_port = 8888 with error.expected( 'Credential validation was not successful: Unable to connect to {}:8888' .format(provider.hostname)): with sel.ajax_timeout(120): provider.create(validate_credentials=True)
def login(user, submit_method=_js_auth_fn): """ Login to CFME with the given username and password. Optionally, submit_method can be press_enter_after_password to use the enter key to login, rather than clicking the button. Args: user: The username to fill in the username field. password: The password to fill in the password field. submit_method: A function to call after the username and password have been input. Raises: RuntimeError: If the login fails, ie. if a flash message appears """ if not user: username = conf.credentials['default']['username'] password = conf.credentials['default']['password'] cred = Credential(principal=username, secret=password) user = User(credential=cred) if not logged_in() or user.credential.principal is not current_username(): if logged_in(): logout() # workaround for strange bug where we are logged out # as soon as we click something on the dashboard sel.sleep(1.0) logger.debug('Logging in as user %s', user.credential.principal) try: fill(form, {'username': user.credential.principal, 'password': user.credential.secret}) except sel.InvalidElementStateException as e: logger.warning("Got an error. Details follow.") msg = str(e).lower() if "element is read-only" in msg: logger.warning("Got a read-only login form, will reload the browser.") # Reload browser quit() ensure_browser_open() sel.sleep(1.0) sel.wait_for_ajax() # And try filling the form again fill(form, {'username': user.credential.principal, 'password': user.credential.secret}) else: logger.warning("Unknown error, reraising.") logger.exception(e) raise with sel.ajax_timeout(90): submit_method() flash.assert_no_errors() user.full_name = _full_name() store.user = user
def login(user, submit_method=_js_auth_fn): """ Login to CFME with the given username and password. Optionally, submit_method can be press_enter_after_password to use the enter key to login, rather than clicking the button. Args: user: The username to fill in the username field. password: The password to fill in the password field. submit_method: A function to call after the username and password have been input. Raises: RuntimeError: If the login fails, ie. if a flash message appears """ if not user: username = conf.credentials['default']['username'] password = conf.credentials['default']['password'] cred = Credential(principal=username, secret=password) user = User(credential=cred) if not logged_in() or user.credential.principal is not current_username(): if logged_in(): logout() # workaround for strange bug where we are logged out # as soon as we click something on the dashboard sel.sleep(1.0) logger.debug('Logging in as user %s' % user.credential.principal) try: fill(form, {'username': user.credential.principal, 'password': user.credential.secret}) except sel.InvalidElementStateException as e: logger.warning("Got an error. Details follow.") msg = str(e).lower() if "element is read-only" in msg: logger.warning("Got a read-only login form, will reload the browser.") # Reload browser quit() ensure_browser_open() sel.sleep(1.0) sel.wait_for_ajax() # And try filling the form again fill(form, {'username': user.credential.principal, 'password': user.credential.secret}) else: logger.warning("Unknown error, reraising.") logger.exception(e) raise with sel.ajax_timeout(90): submit_method() flash.assert_no_errors() user.full_name = _full_name() store.user = user
def f(context): # Here it also can have long spinners with sel.ajax_timeout(90): toolbar.select("Lifecycle", tb_item) provider = context["provider"] template_name = context["template_name"] template_select_form.template_table._update_cache() template = template_select_form.template_table.find_row_by_cells( {"Name": template_name, "Provider": provider if isinstance(provider, basestring) else provider.name} ) if template: sel.click(template) # In order to mitigate the sometimes very long spinner timeout, raise the timeout with sel.ajax_timeout(90): if current_version() < "5.4": sel.click(submit_button) else: sel.click(form_buttons.FormButton("Continue", force_click=True)) else: raise TemplateNotFound('Unable to find template "{}" for provider "{}"'.format(template_name, provider.key))
def step(self, *args, **kwargs): lcl_btn("Provision VMs") # choosing template and going further template_select_form.template_table._update_cache() template = template_select_form.template_table.find_row_by_cells({ 'Name': self.obj.template_name, 'Provider': self.obj.provider.name }) if template: sel.click(template) # In order to mitigate the sometimes very long spinner timeout, raise the timeout with sel.ajax_timeout(90): sel.click(form_buttons.FormButton("Continue", force_click=True)) else: raise TemplateNotFound('Unable to find template "{}" for provider "{}"'.format( self.obj.template_name, self.obj.provider.key))
def select_provision_image(template_name, provider): """ Navigate to provision and select the template+click continue, leaving UI on provision form :param template_name: The image/template name to select :param provider: Provider where the image/template resides :return: none """ logger.debug('Selecting an image {} from provider {} for provisioning' .format(template_name, provider.name)) navigate_to(Instance, 'Provision') template = image_select_form.template_table.find_row_by_cells({ 'Name': template_name, 'Provider': provider.name }) if template: sel.click(template) # In order to mitigate the sometimes very long spinner timeout, raise the timeout with sel.ajax_timeout(90): sel.click(form_buttons.FormButton("Continue", force_click=True)) else: raise TemplateNotFound('Unable to find template "{}" for provider "{}"'.format( template_name, provider.key))
def logged_in(): ensure_browser_open() with sel.ajax_timeout(90): sel.wait_for_ajax() # This is called almost everywhere, protects from spinner return sel.is_displayed(dashboard.page.user_dropdown)
def logged_in(): ensure_browser_open() with sel.ajax_timeout(90): sel.wait_for_ajax( ) # This is called almost everywhere, protects from spinner return sel.is_displayed(dashboard.page.user_dropdown)