def login(username, password, submit_method=_click_on_login): """ 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 """ # TODO: Should probably do the username check here, but there are pretty usernames to deal with # e.g. 'admin' shows up in the UI as 'Administrator' if not logged_in(): # 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}) submit_method() flash.assert_no_errors()
def login(username, password, submit_method=_click_on_login): """ 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}) submit_method() flash.assert_no_errors() thread_locals.current_user = User(username, password, _full_name())
def create(self): # Create has sequential forms, the first is only the provider type navigate_to(self, 'Add') # For element not found exception (To be removed) sel.sleep(5) sel.select("//select[@id='st_prov_type']", self.provider_type or self.item_type or 'Generic') sel.wait_for_element(basic_info_form.name_text) catalog = fakeobject_or_object(self.catalog, "name", "Unassigned") dialog = fakeobject_or_object(self.dialog, "name", "No Dialog") # Need to provide the (optional) provider name to the form, not the object provider_name = None provider_required_types = ['AnsibleTower', 'Orchestration'] if self.item_type in provider_required_types \ or self.provider_type in provider_required_types: provider_name = self.provider.name # For tests where orchestration template is None orch_template = None if self.orch_template: orch_template = self.orch_template.template_name fill(basic_info_form, {'name_text': self.name, 'description_text': self.description, 'display_checkbox': self.display_in, 'select_catalog': catalog.name, 'select_dialog': dialog.name, 'select_orch_template': orch_template, 'select_provider': provider_name, 'select_config_template': self.config_template}) if not (self.item_type in provider_required_types): sel.click(basic_info_form.field_entry_point) if version.current_version() < "5.7": dynamic_tree.click_path("Datastore", self.domain, "Service", "Provisioning", "StateMachines", "ServiceProvision_Template", "default") else: entry_tree.click_path("Datastore", self.domain, "Service", "Provisioning", "StateMachines", "ServiceProvision_Template", "default") sel.click(basic_info_form.apply_btn) if version.current_version() >= "5.7" and self.item_type == "AnsibleTower": sel.click(basic_info_form.retirement_entry_point) entry_tree.click_path("Datastore", self.domain, "Service", "Retirement", "StateMachines", "ServiceRetirement", "Generic") sel.click(basic_info_form.apply_btn) if self.catalog_name is not None \ and self.provisioning_data is not None \ and not isinstance(self.provider, NoneType): tabstrip.select_tab("Request Info") tabstrip.select_tab("Catalog") template = template_select_form.template_table.find_row_by_cells({ 'Name': self.catalog_name, 'Provider': self.provider.name }) sel.click(template) request_form.fill(self.provisioning_data) sel.click(template_select_form.add_button)
def order(self): navigate_to(self, 'Order') if self.stack_data: stack_form.fill(self.stack_data) if self.dialog_values: dialog_form.fill(self.dialog_values) sel.click(form_buttons.submit) # TO DO - needs to be reworked and remove sleep sel.sleep(5) flash.assert_success_message("Order Request was Submitted")
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 add_button(self): view = navigate_to(self, 'AddButton') view.fill({'btn_text': "btn_text", 'btn_hvr_text': "btn_descr", 'btn_image': "Button Image 1", 'select_dialog': self.dialog, 'system_process': "Request", 'request': "InspectMe"}) view.add_button.click() view = self.create_view(DetailsCatalogItemView) sel.sleep(5) assert view.is_displayed view.flash.assert_success_message('Button "btn_descr" was added')
def select_security_group(sg): '''Workaround for select box that is immediately replaced by the same select box no matter what selenium clicks on (but works fine manually). For now only selects one item even though it's a multiselect. ''' val = sel.get_attribute("//select[@id='environment__security_groups']/option[.='%s']" % sg, 'value') sel.browser().execute_script( "$j('#environment__security_groups').val('%s');" "$j.ajax({type: 'POST', url: '/miq_request/prov_field_changed/new'," " data: {'environment__security_groups':'%s'}})" % (val, val)) sel.wait_for_ajax() sel.sleep(1)
def select_security_group(sg): '''Workaround for select box that is immediately replaced by the same select box no matter what selenium clicks on (but works fine manually). For now only selects one item even though it's a multiselect. ''' val = sel.get_attribute( "//select[@id='environment__security_groups']/option[.='%s']" % sg, 'value') sel.browser().execute_script( "$j('#environment__security_groups').val('%s');" "$j.ajax({type: 'POST', url: '/miq_request/prov_field_changed/new'," " data: {'environment__security_groups':'%s'}})" % (val, val)) sel.wait_for_ajax() sel.sleep(1)
def select_security_group(sg): """TODO: Not even sure this is needed any more, but removal of it is not part of this PR""" sel.wait_for_ajax() sel.sleep(1)