def update_provider(self, add_provider=True): self.web_session.logger.info( "Checking if provider exist and add if it does not.") if add_provider: self.add_provider(delete_if_provider_present=False) navigate(self.web_session).get("{}//ems_middleware/show_list".format( self.web_session.MIQ_URL)) assert ui_utils(self.web_session).waitForTextOnPage( "Middleware Providers", 30) self.web_driver.find_element_by_xpath( "//input[contains(@type,'checkbox')]").click() self.web_driver.find_element_by_xpath( "//button[@title='Configuration']").click() self.ui_utils.waitForElementOnPage( By.XPATH, "//a[contains(.,'Edit Selected Middleware Provider')]", 5) elem_editprovider_link = self.web_driver.find_element_by_xpath( "//a[contains(.,'Edit Selected Middleware Provider')]") elem_editprovider_link.click() ui_utils(self.web_session).sleep(10) assert ui_utils(self.web_session).waitForTextOnPage("Name", 30) self.edit_provider_form_cfme_newvalues() self.validate_provider() self.edit_save_cfme() self.verify_edit_provider_success_newvalues() self.edit_provider_form_cfme_originalvalues() self.validate_provider() self.edit_save_cfme() self.verify_edit_provider_success_originalvalues()
def refresh_provider(self): self.web_driver.find_element_by_xpath("//button[@title='Configuration']").click() el = self.web_driver.find_element_by_xpath("//a[@id='ems_container_vmdb_choice__ems_container_refresh']") assert self.ui_utils.wait_until_element_displayed(el, 5) el.click() ui_utils(self.web_session).accept_alert(10) ui_utils(self.web_session).waitForTextOnPage("Refresh Provider initiated", 15)
def navigate_to_all_alerts(self): navigate(self.web_session).get("{}/miq_policy/explorer".format( self.web_session.MIQ_URL)) assert ui_utils(self.web_session).waitForTextOnPage("All Alerts", 15) self.web_session.web_driver.find_element_by_xpath( "//li[@title='All Alerts']").click() ui_utils(self.web_session).sleep(20)
def update_provider(self, add_provider=True): self.web_session.logger.info("Checking if provider exist and add if it does not.") if add_provider: self.add_provider(delete_if_provider_present=False) navigate(self.web_session).get("{}/ems_middleware/show_list?type=list".format(self.web_session.MIQ_URL)) assert ui_utils(self.web_session).waitForTextOnPage("Middleware Providers", 30) assert ui_utils(self.web_session).waitForTextOnPage("Hostname", 30) self.web_driver.find_element_by_xpath("//input[contains(@type,'checkbox')]").click() self.web_driver.find_element_by_xpath("//button[@title='Configuration']").click() self.ui_utils.waitForElementOnPage(By.XPATH, "//a[contains(.,'Edit Selected Middleware Provider')]", 5) elem_editprovider_link = self.web_driver.find_element_by_xpath( "//a[contains(.,'Edit Selected Middleware Provider')]") elem_editprovider_link.click() ui_utils(self.web_session).sleep(10) assert ui_utils(self.web_session).waitForTextOnPage("Name", 30) self.edit_provider_form_cfme_newvalues() self.validate_provider() self.edit_save_cfme() self.verify_edit_provider_success_newvalues() self.edit_provider_form_cfme_originalvalues() self.validate_provider() self.edit_save_cfme() self.verify_edit_provider_success_originalvalues()
def validate_providers_details(self): # Test to validate hawkular provider details like name, hostname, port number # and to validate number of middleware servers, deployments and datasources in releationships section. self.web_session.logger.info("Begin providers details test.") NavigationTree(self.web_session).navigate_to_middleware_providers_view() providers_ui = table(self.web_session).get_middleware_providers_table() servers_hawk = self.hawkular_api.get_hawkular_servers() deployments_hawk = self.hawkular_api.get_hawkular_deployments() datasources_hawk = self.hawkular_api.get_hawkular_datasources() for prov_ui in providers_ui: if prov_ui.get('Name') == self.web_session.HAWKULAR_PROVIDER_NAME: ui_utils(self.web_session).click_on_row_containing_text(self.web_session.HAWKULAR_PROVIDER_NAME) assert ui_utils(self.web_session).waitForTextOnPage("Status", 15) providers_details_ui = ui_utils(self.web_session).get_generic_table_as_dict() assert (providers_details_ui.get('Name') == self.web_session.HAWKULAR_PROVIDER_NAME), "Provider name mismatch" assert (providers_details_ui.get('Host Name') == self.web_session.HAWKULAR_HOSTNAME), "Hostname mismatch" assert (providers_details_ui.get('Port') == self.web_session.HAWKULAR_PORT), "Port Number mismatch" assert providers_details_ui.get('Middleware Servers') == str(len(servers_hawk)), "Number of servers mismatch" self.web_session.logger.debug("UI Deploys: {} HW Deploys: {}".format(providers_details_ui.get('Middleware Deployments'), str(len(deployments_hawk)))) # assert providers_details_ui.get('Middleware Deployments') == str(len(deployments_hawk)), "Number of Deployments mismatch" assert providers_details_ui.get('Middleware Datasources') == str(len(datasources_hawk)), "Number of Datasources mismatch" return True
def delete_hawkular_provider(self): NavigationTree( self.web_session).navigate_to_middleware_providers_view() assert ui_utils(self.web_session).waitForTextOnPage( "Middleware Providers", 30) self.web_session.logger.info("Deleting the provider- {}".format( self.web_session.HAWKULAR_HOSTNAME)) self.web_driver.find_element_by_xpath( "//input[contains(@type,'checkbox')]").click() self.web_driver.find_element_by_xpath( "//button[@title='Configuration']").click() self.web_driver.find_element_by_xpath( "//a[@title='Remove selected Middleware Providers from the VMDB']" ).click() self.web_driver.switch_to_alert().accept() assert ui_utils(self.web_session).waitForTextOnPage( "Delete initiated", 15) # Verify if the provider is deleted from the provider list. assert ui_utils(self.web_session).waitForElementOnPage( By.XPATH, "//a[@title='{}']".format(self.web_session.HAWKULAR_PROVIDER_NAME), 120, exist=False) if not ui_utils(self.web_session).isTextOnPage( self.web_session.HAWKULAR_PROVIDER_NAME): self.web_session.logger.info( "The provider - {} - is deleted successfully".format( self.web_session.HAWKULAR_HOSTNAME))
def execute_command(self, command, time_to_wait=30): ssh_result = {} self.web_session.logger.info( 'Execute command \"{}\" on IP \"{}\".'.format(command, self.ip)) try: stdin, stdout, stderr = self.ssh.exec_command(command) with timeout(time_to_wait): while not stdout.channel.exit_status_ready(): self.web_session.logger.debug( 'Exit status not ready after command execute: {}'. format(command)) ui_utils(self.web_session).sleep(1) if stdout.channel.exit_status == 0: ssh_result['output'] = stdout.read() else: ssh_result['output'] = stderr.read() ssh_result['result'] = stdout.channel.exit_status except Exception, e: self.web_session.logger.error( 'Failed to execute command \"{}\" on IP \"{}\".'.format( command, self.ip)) ssh_result['output'] = e ssh_result['result'] = -1
def add_provider(self, delete_if_provider_present=True, port=None, validate_provider=True): self.provider_name = self.web_session.HAWKULAR_PROVIDER_NAME self.host_name = self.web_session.HAWKULAR_HOSTNAME self.port = self.web_session.HAWKULAR_PORT if port == None else port self.hawkular_user = self.web_session.HAWKULAR_USERNAME self.hawkular_password = self.web_session.HAWKULAR_PASSWORD # Check if any provider already exist. If exist, first delete all the providers and then add a provider. if self.does_provider_exist(): self.web_session.logger.info("Middleware Provider already exist.") if delete_if_provider_present: self.delete_provider(delete_all_providers=True) else: return else: self.web_session.logger.info("Adding Middleware Provider to ManageIQ instance") navigate(self.web_session).get("{}/ems_middleware/show_list?type=list".format(self.web_session.MIQ_URL)) assert ui_utils(self.web_session).waitForTextOnPage("Middleware Providers", 60) self.web_driver.find_element_by_xpath("//button[@title='Configuration']").click() self.ui_utils.waitForElementOnPage(By.XPATH, "//a[@title='Add a New Middleware Provider']", 5) elem_add_new_provider = self.web_driver.find_element_by_xpath("//a[@title='Add a New Middleware Provider']") elem_add_new_provider.click() self.web_driver.implicitly_wait(15) assert ui_utils(self.web_session).waitForTextOnPage("Add New Middleware Provider", 15) ui_utils(self.web_session).sleep(2) self.web_session.logger.info("The appliance version in use is: {} ".format(self.web_session.appliance_version)) self.submit_provider_form_cfme(validate_provider) self.verify_add_provider_success()
def recheck_authentication(self): # Test for Authentication->Recheck Authentication' on hawkular provider self.web_session.logger.info( "Begin test for Authentication->Recheck Authentication.") navigate(self.web_session).get( "{}//ems_middleware/show_list?type=list".format( self.web_session.MIQ_URL)) ui_utils(self.web_session).click_on_row_containing_text( self.web_session.HAWKULAR_PROVIDER_NAME) self.web_driver.find_element_by_xpath( "//h1[contains(.,'Hawkular-Provider (Summary)')]") self.web_driver.find_element_by_xpath( "//button[@title='Authentication']").click() assert self.ui_utils.waitForElementOnPage( By.ID, 'ems_middleware_authentication_choice__ems_middleware_recheck_auth_status', 5) self.web_driver.find_element_by_id( 'ems_middleware_authentication_choice__ems_middleware_recheck_auth_status' ).click() ui_utils(self.web_session).sleep(2) assert ui_utils(self.web_session).waitForTextOnPage( "Authentication status will be saved and workers will be restarted for the selected Middleware Provider", 15) return True
def nav_to_single_server(self): navigate(self.web_session).get("{}/middleware_domain/show_list".format( self.web_session.MIQ_URL)) assert self.ui_utils.waitForTextOnPage(self.provider_name, 30) domains_ui = self.ui_utils.get_list_table() if not domains_ui: self.web_session.logger.warning("No Domains found.") pytest.skip("Skip test - No Domains found.") self.domains.nav_to_all_middleware_server_groups( domains_ui[0].get('Domain Name')) assert ui_utils(self.web_session).waitForTextOnPage( "Server Group Name", 30) self.web_session.web_driver.find_element_by_xpath( "//td[contains(.,'main-server-group')]").click() assert ui_utils(self.web_session).waitForTextOnPage( "Middleware Servers", 30) self.web_session.web_driver.find_element_by_xpath( "//td[contains(.,'Middleware Servers')]").click() assert ui_utils(self.web_session).waitForTextOnPage("server-one", 30) self.web_session.web_driver.find_element_by_xpath( "//td[contains(.,'server-one')]").click() assert ui_utils(self.web_session).waitForTextOnPage("Properties", 30) return True
def submit_provider_form_cfme(self, validate_provider=True): # Enter the form details and submit if the appliance version is CFME Downstream self.web_driver.find_element_by_xpath("//button[@data-id='emstype']").click() assert ui_utils(self.web_session).waitForTextOnPage("Hawkular", 30) self.web_driver.find_element_by_xpath("//span[contains(.,'Hawkular')]").click() assert ui_utils(self.web_session).waitForTextOnPage("Hostname", 30) self.web_driver.find_element_by_xpath("//input[@id='ems_name']").send_keys(self.provider_name) self.web_driver.find_element_by_xpath("//input[@id='default_hostname']").send_keys(self.host_name) self.web_driver.find_element_by_xpath("//input[@id='default_api_port']").clear() self.web_driver.find_element_by_xpath("//input[@id='default_api_port']").send_keys(self.port) self.web_driver.find_element_by_xpath("//button[@data-id='default_security_protocol']").click() assert ui_utils(self.web_session).waitForTextOnPage("Non-SSL", 30) self.web_driver.find_element_by_xpath("//span[contains(.,'Non-SSL')]").click() self.web_driver.find_element_by_xpath("//input[@id='default_userid']").send_keys(self.hawkular_user) self.web_driver.find_element_by_xpath("//input[@id='default_password']").send_keys( self.hawkular_password) #if not self.MIQ_BASE_VERSION == self.appliance_version: # self.web_driver.find_element_by_class_name("validate_button").click() if validate_provider: self.validate_provider() self.save_provider()
def refresh_provider(self): self.web_driver.find_element_by_xpath( "//button[@title='Configuration']").click() self.web_driver.find_element_by_id( 'ems_middleware_vmdb_choice__ems_middleware_refresh').click() self.web_driver.switch_to_alert().accept() ui_utils(self.web_session).waitForTextOnPage( "Refresh Provider initiated", 15)
def verify_edit_provider_success_originalvalues(self): assert ui_utils(self.web_session).isElementPresent(By.XPATH, "//td[contains(.,'{}')]".format( self.web_session.HAWKULAR_PROVIDER_NAME)) assert ui_utils(self.web_session).isElementPresent(By.XPATH, "//td[contains(.,'{}')]".format( self.web_session.HAWKULAR_HOSTNAME)) assert ui_utils(self.web_session).isElementPresent(By.XPATH, "//td[contains(.,'{}')]".format( self.web_session.HAWKULAR_PORT)) self.web_session.logger.info("The middleware provider is edited to the original values successfully.")
def select_event_group(self, group): # Select group from timeline ex: Application assert self.ui_utils.waitForTextOnPage("Options", 15) self.web_driver.find_element_by_xpath("//button[contains(@data-id,'tl_category_management')]").click() self.ui_utils.waitForElementOnPage(By.XPATH, "//a[contains(.,'{}')]".format(group), 5) self.web_driver.find_element_by_xpath("//a[contains(.,'{}')]".format(group)).click() ui_utils(self.web_session).sleep(5) return True
def edit_alert(self): self.navigate_to_all_alerts() ui_utils(self.web_session).get_list_table_as_elements() ui_utils(self.web_session).click_on_row_containing_text( self.alert_desc) assert ui_utils(self.web_session).waitForTextOnPage("Info", 90) self.web_session.web_driver.find_element_by_xpath( "//button[@title='Configuration']").click() self.web_session.web_driver.find_element_by_xpath( ".//*[@id='miq_alert_vmdb_choice__alert_edit']").click() assert ui_utils(self.web_session).waitForTextOnPage("Description", 90) self.web_session.web_driver.find_element_by_xpath( "//input[@id='description']").clear() self.web_session.web_driver.find_element_by_xpath( "//input[@id='description']").send_keys(self.editalert_desc) self.web_session.web_driver.find_element_by_xpath( ".//*[@id='value_mw_greater_than']").clear() self.web_session.web_driver.find_element_by_xpath( ".//*[@id='value_mw_greater_than']").send_keys('5') self.web_session.web_driver.find_element_by_xpath( ".//*[@id='value_mw_less_than']").clear() self.web_session.web_driver.find_element_by_xpath( ".//*[@id='value_mw_less_than']").send_keys('4') ui_utils(self.web_session).sleep(10) self.web_session.web_driver.find_element_by_xpath( "//button[contains(.,'Save')]").click() assert ui_utils(self.web_session).waitForTextOnPage( 'Alert "{}" was saved'.format(self.editalert_desc), 50) return True
def clear_all_providers(self): self.web_session.logger.info("Deleting all the providers from providers list.") self.web_driver.find_element_by_xpath("//input[@id='masterToggle']").click() self.web_driver.find_element_by_xpath("//button[@title='Configuration']").click() self.web_driver.find_element_by_xpath( "//a[@title='Remove selected Middleware Providers from the VMDB']").click() self.web_driver.switch_to_alert().accept() assert ui_utils(self.web_session).waitForTextOnPage( "Delete initiated", 15) assert ui_utils(self.web_session).refresh_until_text_appears("No Records Found", 300) self.web_session.logger.info("All the middleware providers are deleted successfully.")
def verify_edit_provider_success_originalvalues(self): assert ui_utils(self.web_session).isElementPresent( By.XPATH, "//td[contains(.,'{}')]".format( self.web_session.HAWKULAR_PROVIDER_NAME)) assert ui_utils(self.web_session).isElementPresent( By.XPATH, "//td[contains(.,'{}')]".format( self.web_session.HAWKULAR_HOSTNAME)) assert ui_utils(self.web_session).isElementPresent( By.XPATH, "//td[contains(.,'{}')]".format(self.web_session.HAWKULAR_PORT)) self.web_session.logger.info( "The middleware provider is edited to the original values successfully." )
def verify_all_providers_deleted(self): navigate(self.web_session).get("{}/ems_middleware/show_list".format(self.web_session.MIQ_URL)) assert ui_utils(self.web_session).waitForTextOnPage("Middleware Providers", 15) while True: if (self.web_driver.find_element_by_xpath( "//strong[contains(.,'No Records Found.')]").is_displayed() and not self.does_provider_exist()): self.web_session.logger.info("All the middleware providers are deleted successfully.") break else: self.web_driver.refresh() ui_utils(self.web_session).sleep(5) return True
def edit_provider_form_cfme_originalvalues(self): # Edit and save the name to default value.( This will additionally check edit from the provider details page) navigate(self.web_session).get("{}/ems_middleware/show_list".format(self.web_session.MIQ_URL)) ui_utils(self.web_session).click_on_row_containing_text(self.web_session.PROVIDER) self.web_driver.find_element_by_xpath("//button[@title='Configuration']").click() self.ui_utils.waitForElementOnPage(By.XPATH, "//a[@title='Edit this Middleware Provider']", 5) self.web_driver.find_element_by_xpath("//a[@title='Edit this Middleware Provider']").click() ui_utils(self.web_session).sleep(15) assert ui_utils(self.web_session).waitForTextOnPage("Name", 30) self.web_driver.find_element_by_xpath("//input[@id='ems_name']").clear() self.web_driver.find_element_by_xpath("//input[@id='ems_name']").send_keys(self.web_session.HAWKULAR_PROVIDER_NAME)
def validate_provider(self): #validate = WebDriverWait(self.web_driver, 10).until(EC.element_to_be_clickable( # (By.XPATH, "//button[@title='Validate the credentials by logging into the Server']"))) #validate.click() self.web_driver.find_element_by_class_name("validate_button").click() assert ui_utils(self.web_session).waitForTextOnPage( 'Credential validation was successful', 60)
def __init__(self, web_session): self.web_session = web_session self.web_driver = web_session.web_driver self.ui_utils = ui_utils(self.web_session) self.hawkular_api = hawkular_api(self.web_session) self.db = db(self.web_session) self.appliance_version = self.web_session.appliance_version
def verify_all_providers_deleted(self): navigate(self.web_session).get("{}//ems_middleware/show_list".format( self.web_session.MIQ_URL)) assert ui_utils(self.web_session).waitForTextOnPage( "Middleware Providers", 15) while True: if self.web_driver.find_element_by_xpath( "//strong[contains(.,'No Records Found.')]").is_displayed( ): self.web_session.logger.info( "All the middleware providers are deleted successfully.") break else: self.web_driver.refresh() ui_utils(self.web_session).sleep(5) return True
def delete_provider(self, delete_all_providers=True): navigate(self.web_session).get("{}//ems_middleware/show_list".format( self.web_session.MIQ_URL)) assert ui_utils(self.web_session).waitForTextOnPage( "Middleware Providers", 30) view(self.web_session).list_View() assert ui_utils(self.web_session).waitForTextOnPage( self.web_session.HAWKULAR_PROVIDER_NAME, 30) self.ui_utils.sleep(15) # Delete the provider if delete_all_providers: self.clear_all_providers() else: self.delete_hawkular_provider()
def __init__(self, web_session): self.web_session = web_session self.web_driver = web_session.web_driver self.ui_utils = ui_utils(self.web_session) self.hawkular_api = hawkular_api(self.web_session) self.provider_name = self.web_session.HAWKULAR_PROVIDER_NAME self.hostname = self.web_session.HAWKULAR_HOSTNAME
def delete_alert(self, alertdesc): self.navigate_to_all_alerts() ui_utils(self.web_session).get_list_table_as_elements() if ui_utils(self.web_session).get_elements_containing_text(alertdesc): ui_utils(self.web_session).click_on_row_containing_text(alertdesc) assert ui_utils(self.web_session).waitForTextOnPage('Alert "{}"'.format(alertdesc), 90) self.web_session.web_driver.find_element_by_xpath("//button[@title='Configuration']").click() assert ui_utils(self.web_session).waitForTextOnPage("Copy", 90) self.web_session.web_driver.find_element_by_xpath("//a[@id='miq_alert_vmdb_choice__alert_delete']").click() ui_utils(self.web_session).accept_alert(20) assert ui_utils(self.web_session).waitForTextOnPage('Alert "{}": Delete successful'.format(alertdesc), 50) self.web_session.logger.info("The alert {} is removed successfully.".format(alertdesc)) return True
def delete_saved_search(self): self.navigate_to_saved_filter() self.ui_utils.waitForTextOnPage(self.search_provider_name, 15) self.web_driver.find_element_by_xpath("//a[contains(.,'{}')]".format( self.search_provider_name)).click() self.ui_utils.sleep(10) self.web_driver.find_element_by_xpath( "//button[@id='adv_search']").click() assert self.ui_utils.waitForTextOnPage("Advanced Search", 15) self.web_driver.find_element_by_xpath( "//a[contains(.,'Delete')]").click() ui_utils(self.web_session).accept_alert(10) assert self.ui_utils.waitForTextOnPage("Delete successful", 15) return True
def edit_save_cfme(self): # Wait till Save button is enabled before click edit_save_cfme = WebDriverWait(self.web_driver, 30).until( EC.element_to_be_clickable((By.XPATH, "//button[contains(.,'Save')]"))) edit_save_cfme.click() assert ui_utils(self.web_session).waitForTextOnPage('saved', 15)
def __init__(self, web_session): self.web_session = web_session self.web_driver = web_session.web_driver self.ui_utils = ui_utils(self.web_session) self.domains = domains(self.web_session) self.servers = servers(self.web_session) self.provider_name = self.web_session.HAWKULAR_PROVIDER_NAME
def add_provider(self, delete_if_provider_present=True, port=None, validate_provider=True): self.provider_name = self.web_session.HAWKULAR_PROVIDER_NAME self.host_name = self.web_session.HAWKULAR_HOSTNAME self.port = self.web_session.HAWKULAR_PORT if port == None else port self.hawkular_user = self.web_session.HAWKULAR_USERNAME self.hawkular_password = self.web_session.HAWKULAR_PASSWORD # Check if any provider already exist. If exist, first delete all the providers and then add a provider. if self.does_provider_exist(): self.web_session.logger.info("Middleware Provider already exist.") if delete_if_provider_present: self.delete_provider(delete_all_providers=True) else: return else: self.web_session.logger.info( "Adding Middleware Provider to ManageIQ instance") navigate(self.web_session).get("{}//ems_middleware/show_list".format( self.web_session.MIQ_URL)) assert ui_utils(self.web_session).waitForTextOnPage( "Middleware Providers", 15) self.web_driver.find_element_by_xpath( "//button[@title='Configuration']").click() self.ui_utils.waitForElementOnPage( By.XPATH, "//a[@title='Add a New Middleware Provider']", 5) elem_add_new_provider = self.web_driver.find_element_by_xpath( "//a[@title='Add a New Middleware Provider']") elem_add_new_provider.click() self.web_driver.implicitly_wait(15) assert ui_utils(self.web_session).waitForTextOnPage( "Add New Middleware Provider", 15) ui_utils(self.web_session).sleep(2) self.web_session.logger.info( "The appliance version in use is: {} ".format( self.web_session.appliance_version)) self.submit_provider_form_cfme(validate_provider) self.verify_add_provider_success()
def loginSkip(self, username, password, wait_for, wait_for_TODO=None): ui_utils(self.web_session).waitForTextOnPage('TODO text', 2) res = self.web_session.find_element_by_xpath( xpath="//*[contains(text(),'TODO login')]") if not res: return self.web_session.logger.info("Login with:") self.web_session.logger.info(self.web_session.BASE_URL) self.web_session.logger.info(self.web_session.BASE_LOGIN_PATH) navigate(self.web_session).get( "{}".format(self.web_session.BASE_URL + self.web_session.BASE_LOGIN_PATH), wait_for=self.web_session.TX_SIGNIN) if wait_for_TODO: # TODO removed non-public stuff for custom login pass assert ui_utils(self.web_session).waitForTextOnPage(wait_for, 300)
def delete_hawkular_provider(self): NavigationTree(self.web_session).navigate_to_middleware_providers_view() assert ui_utils(self.web_session).waitForTextOnPage("Middleware Providers", 30) self.web_session.logger.info("Deleting the provider- {}".format(self.web_session.HAWKULAR_HOSTNAME)) self.web_driver.find_element_by_xpath("//input[contains(@type,'checkbox')]").click() self.web_driver.find_element_by_xpath("//button[@title='Configuration']").click() self.web_driver.find_element_by_xpath( "//a[@title='Remove selected Middleware Providers from the VMDB']").click() self.web_driver.switch_to_alert().accept() assert ui_utils(self.web_session).waitForTextOnPage("Delete initiated", 15) # Verify if the provider is deleted from the provider list. assert ui_utils(self.web_session).waitForElementOnPage(By.XPATH, "//a[@title='{}']".format( self.web_session.HAWKULAR_PROVIDER_NAME), 120, exist=False) if not ui_utils(self.web_session).isTextOnPage(self.web_session.HAWKULAR_PROVIDER_NAME): self.web_session.logger.info( "The provider - {} - is deleted successfully".format(self.web_session.HAWKULAR_HOSTNAME))
def edit_save_cfme(self): # Wait till Save button is enabled before click edit_save_cfme = WebDriverWait(self.web_driver, 30).until( EC.element_to_be_clickable( (By.XPATH, "//button[contains(.,'Save')]"))) edit_save_cfme.click() assert ui_utils(self.web_session).waitForTextOnPage('saved', 15)
def verify_edit_provider_success_newvalues(self): # Verify if the provider name, is successfully updated and shown in UI assert ui_utils(self.web_session).isElementPresent( By.XPATH, "//td[contains(.,'{}')]".format(self.web_session.PROVIDER)) self.web_session.logger.info( "The middleware provider is edited successfully.")
def delete_provider(self, delete_all_providers=True): NavigationTree(self.web_session).navigate_to_middleware_providers_view() assert ui_utils(self.web_session).waitForTextOnPage("Middleware Providers", 30) # Delete the provider if delete_all_providers: self.clear_all_providers() else: self.delete_hawkular_provider()
def clear_all_providers(self): self.web_session.logger.info( "Deleting all the providers from providers list.") self.web_driver.find_element_by_xpath( "//input[@id='masterToggle']").click() self.web_driver.find_element_by_xpath( "//button[@title='Configuration']").click() self.web_driver.find_element_by_xpath( "//a[@title='Remove selected Middleware Providers from the VMDB']" ).click() self.web_driver.switch_to_alert().accept() assert ui_utils(self.web_session).waitForTextOnPage( "Delete initiated", 15) assert ui_utils(self.web_session).refresh_until_text_appears( "No Records Found", 300) self.web_session.logger.info( "All the middleware providers are deleted successfully.")
def login(self, username, password): self.username = username self.password = password elem = self.web_driver.find_element_by_id("user_name") elem.send_keys(self.username) elem = self.web_driver.find_element_by_id("user_password") elem.send_keys(self.password) elem.send_keys(Keys.RETURN) assert ui_utils(self.web_session).waitForTextOnPage(LOGIN_TEXT, 15)
def nav_to_single_server(self): navigate(self.web_session).get("{}/middleware_domain/show_list".format(self.web_session.MIQ_URL)) assert self.ui_utils.waitForTextOnPage(self.provider_name, 30) domains_ui = self.ui_utils.get_list_table() if not domains_ui: self.web_session.logger.warning("No Domains found.") pytest.skip("Skip test - No Domains found.") self.domains.nav_to_all_middleware_server_groups(domains_ui[0].get('Domain Name')) assert ui_utils(self.web_session).waitForTextOnPage("Server Group Name", 30) self.web_session.web_driver.find_element_by_xpath("//td[contains(.,'main-server-group')]").click() assert ui_utils(self.web_session).waitForTextOnPage("Middleware Servers", 30) self.web_session.web_driver.find_element_by_xpath("//td[contains(.,'Middleware Servers')]").click() assert ui_utils(self.web_session).waitForTextOnPage("server-one", 30) self.web_session.web_driver.find_element_by_xpath("//td[contains(.,'server-one')]").click() assert ui_utils(self.web_session).waitForTextOnPage("Properties", 30) return True
def get_hawkular_deployments(self): deployments = [] with timeout(seconds=30, error_message="Timed out - No Deployments Returned"): while True: try: rows = self.__hawkular__.inventory.list_server_deployment() if rows: for deployment in rows: dict = {} dict['Nativeid'] = deployment.id dict['Name'] = deployment.name dict['path'] = deployment.path deployments.append(dict) break else: ui_utils(self.web_session).sleep(2) except Exception, e: self.__exception_handler(e)
def verify_refresh_status_success(self): refresh_value_success = "Success" self.refresh_provider() # Refresh the page till till the table value for Last Refresh shows the value - Success assert ui_utils(self.web_session).refresh_until_text_appears(refresh_value_success, 300) provider_details = ui_utils(self.web_session).get_generic_table_as_dict() # Verify if the 'Last Refresh' value from table contains 'Success: refresh_status = provider_details.get("Last Refresh") if str(refresh_status).__contains__(refresh_value_success): self.web_session.logger.info("The Last refresh status is - " + refresh_status) return True else: return False
def __init__(self, web_session): self.web_session = web_session self.web_driver = web_session.web_driver self.ui_utils = ui_utils(self.web_session) self.hawkular_api = hawkular_api(self.web_session) try: self.db = db(self.web_session) except Exception, e: self.web_session.logger.warning("Unable to connecto to database. {}".format(e))
def navigate_to_timeline(self): navigate(self.web_session).get("{}//ems_middleware/show_list?type=list".format(self.web_session.MIQ_URL)) ui_utils(self.web_session).waitForTextOnPage(self.web_session.HAWKULAR_PROVIDER_NAME, 10) ui_utils(self.web_session).click_on_row_containing_text(self.web_session.HAWKULAR_PROVIDER_NAME) ui_utils(self.web_session).waitForTextOnPage('Relationships', 10) self.web_driver.find_element_by_xpath("//button[@title='Monitoring']").click() el = self.web_driver.find_element_by_xpath("//a[contains(@id,'timeline')]") self.ui_utils.wait_until_element_displayed(el, 5) el.click() ui_utils(self.web_session).sleep(60) self.ui_utils.waitForTextOnPage('Options', 120)
def does_provider_exist(self): self.web_session.logger.info("Checking if provider exists") # For performance reasons, check if the provider is present via DB providers = db(self.web_session).get_providers() provider = ui_utils(self.web_session).find_row_in_list(providers, 'name', self.web_session.HAWKULAR_PROVIDER_NAME) if provider: return True else: self.web_session.logger.info("Middleware Provider does not exist.") return False
def delete_provider(self, delete_all_providers=True): navigate(self.web_session).get("{}/ems_middleware/show_list?type=list".format(self.web_session.MIQ_URL)) assert ui_utils(self.web_session).waitForTextOnPage(self.web_session.HAWKULAR_PROVIDER_NAME, 30) self.ui_utils.sleep(15) # Delete the provider if delete_all_providers: self.clear_all_providers() else: self.delete_hawkular_provider()
def delete_provider(self, delete_all_providers=True): NavigationTree( self.web_session).navigate_to_middleware_providers_view() assert ui_utils(self.web_session).waitForTextOnPage( "Middleware Providers", 30) # Delete the provider if delete_all_providers: self.clear_all_providers() else: self.delete_hawkular_provider()
def __init__(self, web_session): self.web_session = web_session self.web_driver = web_session.web_driver self.ui_utils = ui_utils(self.web_session) self.hawkular_api = hawkular_api(self.web_session) try: self.db = db(self.web_session) except Exception, e: self.web_session.logger.warning( "Unable to connecto to database. {}".format(e))
def does_provider_exist(self): self.web_session.logger.info("Checking if provider exists") # For performance reasons, check if the provider is present via DB providers = db(self.web_session).get_providers() provider = ui_utils(self.web_session).find_row_in_list( providers, 'name', self.web_session.HAWKULAR_PROVIDER_NAME) if provider: return True else: return False
def verify_event(self, event_type): try: el = self.web_driver.find_element_by_xpath( "//*[@id = 'chart_placeholder']//*[name() = 'svg']//*[name() = 'text']") except: assert False, 'No Timeline events found' # Verify event where type for successful event is 'ok' and for unsuccessful event is 'error' self.ui_utils.wait_until_element_displayed(el, 60) el.click() assert ui_utils(self.web_session).waitForTextOnPage("hawkular_deployment.{}".format(event_type), 120) return True
def submit_provider_form_cfme(self, validate_provider=True): # Enter the form details and submit if the appliance version is CFME Downstream self.web_driver.find_element_by_xpath("//input[@id='ems_name']").send_keys(self.provider_name) self.web_driver.find_element_by_xpath("//button[contains(.,'<Choose>')]").click() assert ui_utils(self.web_session).waitForTextOnPage("OpenShift", 15) self.web_driver.find_element_by_xpath("//a[contains(.,'OpenShift')]").click() self.web_driver.find_element_by_xpath("//input[@id='default_hostname']").send_keys(self.host_name) # self.web_driver.find_element_by_xpath("//input[@id='default_api_port']").send_keys(self.port) self.web_driver.find_element_by_xpath("//button[@data-id='default_security_protocol']").click() assert ui_utils(self.web_session).waitForTextOnPage("SSL without validation", 15) self.web_driver.find_element_by_xpath("//a[contains(.,'SSL without validation')]").click() self.web_driver.find_element_by_xpath("//input[@id='default_password']").send_keys(self.openshift_token) if validate_provider: self.validate_provider() self.save_provider()
def login(self, username, password): navigate(self.web_session).get("{}".format(self.web_session.MIQ_URL), wait_for="Username") self.username = username self.password = password elem = self.web_driver.find_element_by_id("user_name") elem.send_keys(self.username) elem = self.web_driver.find_element_by_id("user_password") elem.send_keys(self.password) elem.send_keys(Keys.RETURN) assert ui_utils(self.web_session).waitForTextOnPage(LOGIN_TEXT, 15)
def add_mm_openshift_provider(self, delete_if_provider_present=True, port=None, validate_provider=True): self.provider_name = self.web_session.OPENSHIFT_PROVIDER_NAME self.host_name = self.web_session.OPENSHIFT_HOSTNAME self.port = self.web_session.OPENSHIFT_PORT if port == None else port self.openshift_user = self.web_session.OPENSHIFT_USERNAME self.openshift_token= self.openshift_utils.get_token() ui_utils(self.web_session).sleep(2) # Check if any provider already exist. If exist, first delete all the providers and then add a provider. if db(self.web_session).is_container_provider_present(self.web_session.OPENSHIFT_PROVIDER_NAME): self.web_session.logger.info("Container Provider already exist.") return else: self.web_session.logger.info("Adding openshift Middleware Provider to ManageIQ instance") navigate(self.web_session).get("{}//ems_container/show_list".format(self.web_session.MIQ_URL)) assert ui_utils(self.web_session).waitForTextOnPage("Containers Providers", 15) self.web_driver.find_element_by_xpath("//button[@title='Configuration']").click() self.ui_utils.waitForElementOnPage(By.XPATH,"//a[@title='Add a new Containers Provider']", 5) elem_add_new_provider = self.web_driver.find_element_by_xpath("//a[@title='Add a new Containers Provider']") elem_add_new_provider.click() self.web_driver.implicitly_wait(15) assert ui_utils(self.web_session).waitForTextOnPage("Add New Containers Provider", 50) ui_utils(self.web_session).sleep(2) self.web_session.logger.info("The appliance version in use is: {} ".format(self.web_session.appliance_version)) self.submit_provider_form_cfme(validate_provider) self.verify_add_provider_success()
def does_provider_exist(self): self.web_session.logger.info("Checking if provider exists") # navigate_to_providers NavigationTree(self.web_session).navigate_to_middleware_providers_view() if ui_utils(self.web_session).isElementPresent(By.XPATH, "//span[contains(.,'(Item 0 of 0)')]"): self.web_session.logger.info("Middleware Provider does not exist.") return False else: self.web_session.logger.info("Middleware Provider already exist.") return True
def edit_alert(self): self.navigate_to_all_alerts() ui_utils(self.web_session).get_list_table_as_elements() ui_utils(self.web_session).click_on_row_containing_text(self.alert_desc) assert ui_utils(self.web_session).waitForTextOnPage('Alert "{}"'.format(self.alert_desc), 90) self.web_session.web_driver.find_element_by_xpath("//button[@title='Configuration']").click() assert ui_utils(self.web_session).waitForTextOnPage("Copy", 90) self.web_session.web_driver.find_element_by_xpath("//a[@id='miq_alert_vmdb_choice__alert_edit']").click() assert ui_utils(self.web_session).waitForTextOnPage("Description", 90) self.web_session.web_driver.find_element_by_xpath("//input[@id='description']").clear() self.web_session.web_driver.find_element_by_xpath("//input[@id='description']").send_keys(self.editalert_desc) self.web_session.web_driver.find_element_by_xpath(".//*[@id='value_mw_greater_than']").clear() self.web_session.web_driver.find_element_by_xpath(".//*[@id='value_mw_greater_than']").send_keys('5') self.web_session.web_driver.find_element_by_xpath(".//*[@id='value_mw_less_than']").clear() self.web_session.web_driver.find_element_by_xpath(".//*[@id='value_mw_less_than']").send_keys('4') ui_utils(self.web_session).sleep(10) self.web_session.web_driver.find_element_by_xpath("//button[contains(.,'Save')]").click() assert ui_utils(self.web_session).waitForTextOnPage('Alert "{}" was saved'.format(self.editalert_desc), 50) return True
def execute_command(self, command): ssh_result = {} self.web_session.logger.info('Execute command \"{}\" on IP \"{}\".'.format(command, self.ip)) try: stdin, stdout, stderr = self.ssh.exec_command(command) while not stdout.channel.exit_status_ready(): self.web_session.logger.info('Exit status not ready after command execute: {}'.format(command)) ui_utils(self.web_session).sleep(1) if stdout.channel.exit_status == 0: ssh_result['output'] = stdout.read() else: ssh_result['output'] = stderr.read() ssh_result['result'] = stdout.channel.exit_status except Exception, e: self.web_session.logger.error('Failed to execute command \"{}\" on IP \"{}\".'.format(command, self.ip)) ssh_result['output'] = e ssh_result['result'] = -1
def clear_all_providers(self): self.web_session.logger.info("Deleting all the providers from providers list.") if not self.appliance_version == self.MIQ_BASE_VERSION: self.web_driver.find_element_by_xpath("//input[@title='Select All']").click() self.web_driver.find_element_by_xpath("//button[@title='Configuration']").click() assert self.ui_utils.waitForElementOnPage(By.XPATH, "//a[@id='ems_middleware_vmdb_choice__ems_middleware_delete']", 5) self.web_driver.find_element_by_xpath( "//a[@id='ems_middleware_vmdb_choice__ems_middleware_delete']").click() else: self.ui_utils.waitForElementOnPage(By.XPATH, "//input[@ng-click='paginationCtrl.onSelectAll({isSelected: isChecked})']", 5) self.web_driver.find_element_by_xpath("//input[@ng-click='paginationCtrl.onSelectAll({isSelected: isChecked})']").click() self.web_driver.find_element_by_xpath("//button[@title='Configuration']").click() assert self.ui_utils.waitForElementOnPage(By.XPATH, "//a[@id='ems_middleware_vmdb_choice__ems_middleware_delete']", 5) self.web_driver.find_element_by_xpath( "//a[@id='ems_middleware_vmdb_choice__ems_middleware_delete']").click() ui_utils(self.web_session).accept_alert(10) assert ui_utils(self.web_session).waitForTextOnPage("Delete initiated", 30) self.verify_all_providers_deleted()
def validate_providers_list(self): # Test to validate provider list page in UI and validate matching providers hostname, port number self.web_session.logger.info("Begin providers list test.") navigate(self.web_session).get("{}/ems_middleware/show_list?type=list".format(self.web_session.MIQ_URL)) assert ui_utils(self.web_session).waitForTextOnPage(self.web_session.HAWKULAR_PROVIDER_NAME, 30) providers_ui = self.ui_utils.get_list_table() assert len(providers_ui) > 0, "Providers list is empty." for prov_ui in providers_ui: if prov_ui.get('Name') == self.web_session.HAWKULAR_PROVIDER_NAME: assert (prov_ui.get('Hostname') == self.web_session.HAWKULAR_HOSTNAME), "Hostname mismatch" assert (prov_ui.get('Port') == self.web_session.HAWKULAR_PORT), "Port Number mismatch" return True