def search_for_body_of_module(self): try: utilities.find_elements_by_id(self.driver, locators.SEARCH_BOX_ID).clear() utilities.enter_text(self.driver, By.ID, locators.SEARCH_BOX_ID, constants.body_of_module_search) utilities.click_element(self.driver, By.CSS_SELECTOR, locators.SEARCH_BUTTON_CSS) utilities.wait(2) utilities.click_element(self.driver, By.XPATH, locators.SEARCH_MODULE_XPATH) utilities.wait(2) utilities.click_element(self.driver, By.CSS_SELECTOR, locators.MODULE_DISPLAY_PREVIEW_BUTTON_CSS) utilities.wait(2) utilities.switch_to_latest_tab(self.driver) body_of_module_on_preview = utilities.find_shadow_dom_element( self.driver, locators.SEARCH_BODY_ON_PREVIEW_CSS, locators.MODULE_BODY_CSS).text check_that("content of module is displayed", body_of_module_on_preview, contains_string(constants.body_of_module_search)) utilities.wait(2) except (TimeoutException, StaleElementReferenceException, NoSuchElementException) as e: lcc.log_error("Error finding element: %s" % e) lcc.log_error(e) finally: self.driver.close() utilities.switch_to_first_tab(self.driver)
def product_info_on_customer_portal(self): utilities.wait(5) utilities.page_reload(self.driver) utilities.click_element(self.driver, By.PARTIAL_LINK_TEXT, "View on Customer Portal") try: utilities.wait(5) utilities.switch_to_latest_tab(self.driver) utilities.wait(6) updated_date_on_portal = utilities.find_shadow_dom_element( self.driver, locators.UPDATED_DATE_ON_PORTAL_CSS, locators.MODULE_BODY_ON_PORTAL_CSS).get_attribute( "textContent") check_that("updated date reflected on view page", updated_date_on_portal, contains_string(self.first_pub_date_details_page)) published_date_on_portal = utilities.find_shadow_dom_element( self.driver, locators.PUBLISHED_DATE_ON_PORTAL_CSS, locators.MODULE_BODY_ON_PORTAL_CSS).get_attribute( "textContent") check_that("published date reflected on view page", published_date_on_portal, contains_string(self.last_pub_date_details_page)) except (TimeoutException, StaleElementReferenceException, NoSuchElementException) as e: lcc.log_error( "Some problem accessing the Customer Portal, please check.") lcc.log_error(e) finally: if (len(self.driver.window_handles) > 1): self.driver.close() utilities.switch_to_first_tab(self.driver)
def view_on_portal_link_test(self): try: utilities.wait(5) utilities.click_element(self.driver, By.CSS_SELECTOR, locators.VIEW_ON_PORTAL_LINK_CSS) utilities.wait(5) utilities.switch_to_latest_tab(self.driver) utilities.wait(7) lcc.log_info( "Find the CP preview in the attachment below for debugging purposes" ) self.driver.save_screenshot("cp_preview_module.png") lcc.save_attachment_file("cp_preview_module.png") check_that("View on Portal URL path", self.driver.current_url, contains_string(constants.view_on_portal_page_url)) module_id_regex = re.compile( r'^[a-zA-Z0-9]{8}-[a-zA-Z0-9]{4}-[a-zA-Z0-9]{4}-[a-zA-Z0-9]{4}-[a-zA-Z0-9]{12}$' ) current__module_id = self.driver.current_url.split("/topic/")[1] check_that("View on Portal URL id", current__module_id, match_pattern(module_id_regex)) # content_body_on_portal = utilities.find_element(self.driver, By.CSS_SELECTOR, locators.MODULE_BODY_ON_PORTAL_CSS) except (TimeoutException, StaleElementReferenceException, NoSuchElementException) as e: lcc.log_error("Error finding element!!!") lcc.log_error(e) finally: if (len(self.driver.window_handles) > 1): self.driver.close() utilities.switch_to_first_tab(self.driver)
def product_info_on_view_page(self): utilities.click_element(self.driver, By.CSS_SELECTOR, locators.MODULE_DISPLAY_PREVIEW_BUTTON_CSS) try: utilities.switch_to_latest_tab(self.driver) utilities.wait(2) product_name = utilities.find_shadow_dom_element( self.driver, locators.PRODUCT_NAME_ON_PREVIEW_CSS, locators.MODULE_BODY_CONTENT_CSS).text check_that("Product name reflected on view page", product_name, contains_string(constants.product_name)) product_version = utilities.find_shadow_dom_element( self.driver, locators.PRODUCT_VERSION_ON_PREVIEW_CSS, locators.MODULE_BODY_CONTENT_CSS).text check_that("Product version reflected on view page", product_version, contains_string(constants.product_version)) updated_date_view_page = utilities.find_shadow_dom_element( self.driver, locators.UPDATED_DATE_ON_PREVIEW_CSS, locators.MODULE_BODY_CONTENT_CSS).text.strip("Updated ") check_that("updated date reflected on view page", updated_date_view_page, contains_string(self.first_pub_date_details_page)) published_date_view_page = utilities.find_shadow_dom_element( self.driver, locators.PUBLISHED_DATE_ON_PREVIEW_CSS, locators.MODULE_BODY_CONTENT_CSS).text.strip("Published ") check_that("published date reflected on view page", published_date_view_page, contains_string(self.last_pub_date_details_page)) legal_notice = utilities.find_shadow_dom_element( self.driver, locators.LEGAL_NOTICE_ON_PREVIEW_CSS, locators.MODULE_BODY_CONTENT_CSS) check_that( "legal notice is displayed at the bottom of preview page", legal_notice.text, contains_string("Legal Notices for Trademarks")) legal_notice_href = legal_notice.get_attribute("href") check_that("verify legal notice link", legal_notice_href, contains_string(constants.legal_notice_link)) except (TimeoutException, StaleElementReferenceException, NoSuchElementException) as e: lcc.log_error("Element could not be located!!!") lcc.log_error(e) finally: if (len(self.driver.window_handles) > 1): self.driver.close() utilities.switch_to_first_tab(self.driver)
def help_doc(self): try: utilities.wait(2) utilities.click_element(self.driver, By.LINK_TEXT, locators.MENU_SEARCH_PAGE_LINK_TEXT) utilities.page_reload(self.driver) utilities.wait(1) utilities.click_element(self.driver, By.CSS_SELECTOR, locators.HELP_ICON_CLASS_NAME) utilities.click_element(self.driver, By.LINK_TEXT, locators.USER_GUIDE_LINK_TEXT) utilities.wait(2) utilities.switch_to_latest_tab(self.driver) lcc.log_info(self.driver.current_url) check_that("page url", self.driver.current_url, contains_string(constants.help_user_guide_url)) title_of_user_guide = utilities.find_shadow_dom_element(self.driver, locators.TITLE_OF_USER_GUIDE_CSS, locators.USER_GUIDE_PARENT_CSS).text check_that("title of the page", title_of_user_guide, contains_string("Help")) except (TimeoutException, NoSuchElementException) as e: lcc.log_error(e) finally: self.driver.close() utilities.switch_to_first_tab(self.driver)
def verify_attribute_text(self): try: utilities.click_element(self.driver, By.LINK_TEXT, "Search") # search_page.search_for_module_and_click(self.driver, constants.search_module_with_attribute) search_beta_page.select_repo(self.driver, fixture.repo_name) search_beta_page.search_module_and_click( self.driver, constants.search_module_with_attribute) utilities.click_element(self.driver, By.CSS_SELECTOR, locators.MODULE_DISPLAY_PREVIEW_BUTTON_CSS) utilities.wait(2) utilities.switch_to_latest_tab(self.driver) attribute_text = utilities.find_shadow_dom_element( self.driver, locators.ATTRIBUTE_ON_PREVIEW_CSS, locators.MODULE_BODY_CONTENT_CSS).text check_that( "verify attribute is resolving correctly on preview page", attribute_text, contains_string(constants.attribute)) except Exception as e: lcc.log_info(e) finally: if (len(self.driver.window_handles) > 1): self.driver.close() utilities.switch_to_first_tab(self.driver)
def publish_module(self): utilities.click_element(self.driver, By.LINK_TEXT, "Search") utilities.page_reload(self.driver) # search_page.search_for_module_and_click(self.driver, constants.module_to_be_published) search_beta_page.select_repo(self.driver, fixture.repo_name) search_beta_page.search_module_and_click( self.driver, constants.module_to_be_published) utilities.wait(10) pre_live_url = utilities.find_element(self.driver, By.LINK_TEXT, "Pre-live Customer Portal URL") print(pre_live_url.get_attribute('href')) check_that("Pre-live URL link is displayed", pre_live_url.is_displayed(), is_true()) copy_pre_live_url = utilities.find_element(self.driver, By.LINK_TEXT, "Copy pre-live URL") check_that("Copy Pre-live URL is displayed", copy_pre_live_url.is_displayed(), is_true()) utilities.click_element(self.driver, By.ID, locators.MODULE_DISPLAY_PUBLISH_BUTTON_ID) utilities.wait(20) print("Clicked publish") # The page needs a refresh because of an existing bug about the "View on Customer Portal not appearing" self.driver.refresh() utilities.find_element(self.driver, By.PARTIAL_LINK_TEXT, "View on Customer Portal") check_that( "Button contains text", utilities.get_text(self.driver, By.ID, locators.MODULE_DISPLAY_UNPUBLISH_BUTTON_ID), contains_string("Unpublish")) check_that( "Button contains text", utilities.get_text(self.driver, By.CSS_SELECTOR, locators.MODULE_DISPLAY_PREVIEW_BUTTON_CSS), contains_string("Preview")) check_that( "Copy permanent url link is displayed", utilities.get_text(self.driver, By.CSS_SELECTOR, locators.COPY_URL_LINK_CSS), contains_string(constants.copy_url_link)) check_that( "View on portal link is displayed", utilities.get_text(self.driver, By.CSS_SELECTOR, locators.VIEW_ON_PORTAL_LINK_CSS), contains_string(constants.view_on_portal_link)) # get UPLOADED date in variable and covert into desired format- (DD Month YYYY) self.first_pub_date_details_page = (utilities.get_text( self.driver, By.CSS_SELECTOR, locators.FIRST_PUB_DATE_MODULE_PAGE_CSS)) lcc.log_info("captured 1st published date from module info page : " + self.first_pub_date_details_page) # get published date in variable and convert into desired format-(DD Month YYYY) self.last_pub_date_details_page = (utilities.get_text( self.driver, By.CSS_SELECTOR, locators.LAST_PUB_DATE_MODULE_PAGE_CSS)) lcc.log_info("captured last published date from module info page : " + test_publish_module.last_pub_date_details_page) # adding checks if the module is displayed on the UI utilities.click_element(self.driver, By.CSS_SELECTOR, locators.VIEW_ON_PORTAL_LINK_CSS) utilities.wait(5) try: utilities.switch_to_latest_tab(self.driver) utilities.wait(10) check_that("View on Portal URL path", self.driver.current_url, contains_string(constants.view_on_portal_page_url)) except (TimeoutException, StaleElementReferenceException, NoSuchElementException) as e: lcc.log_error("Element could not be located!!!") lcc.log_error(e) finally: if (len(self.driver.window_handles) > 1): self.driver.close() utilities.switch_to_first_tab(self.driver)
def preview_assembly(self): test_repo_name = base.config_reader('test_repo', 'repo_name') try: # Get list of modules included modules_included = utilities.find_elements_by_css_selector( self.driver, locators.MODULES_INCLUDED_LIST_CSS) test_view_assembly.modules_count = len(modules_included) for i in range(test_view_assembly.modules_count): test_view_assembly.module_titles.append( modules_included[i].text) utilities.click_element(self.driver, By.CSS_SELECTOR, locators.MODULE_DISPLAY_PREVIEW_BUTTON_CSS) utilities.wait(5) utilities.switch_to_latest_tab(self.driver) utilities.wait(7) assembly_title = utilities.find_shadow_dom_element( self.driver, locators.DOCUMENT_TITLE, locators.MODULE_BODY_CONTENT_CSS).text print(assembly_title) check_that("Assembly title", constants.assembly_to_be_published, contains_string(assembly_title)) product_name = utilities.find_shadow_dom_element( self.driver, locators.PRODUCT_NAME_ON_PREVIEW_CSS, locators.MODULE_BODY_CONTENT_CSS).text print(product_name) check_that("Product name reflected on view page", product_name, contains_string(constants.product_name)) product_version = utilities.find_shadow_dom_element( self.driver, locators.PRODUCT_VERSION_ON_PREVIEW_CSS, locators.MODULE_BODY_CONTENT_CSS).text print(product_version) check_that("Product version reflected on view page", product_version, contains_string(constants.product_version)) image = utilities.find_shadow_dom_element( self.driver, locators.IMAGE_CSS, locators.MODULE_BODY_CONTENT_CSS) src = image.get_attribute("src") imageasset = urlparse(src) imageasset = imageasset.path.split("/")[2] cmd = "echo " + imageasset + "|base64 -d" try: # subprocess.check_call(cmd, shell=True) path = subprocess.getoutput(cmd) print("Image file path::", path) image_file = "/content/repositories/" + test_repo_name + "/entities/enterprise/assemblies/images/" + constants.image_file_name check_that("Path to image1", path, equal_to(image_file)) except subprocess.CalledProcessError as e: lcc.log_info("Unable to decode imageasset") assembly_body = utilities.get_text( self.driver, By.CSS_SELECTOR, locators.ASSEMBLY_BODY_PREVIEW_CSS) for i in range(test_view_assembly.modules_count): check_that( "Assembly body", assembly_body, contains_string(test_view_assembly.module_titles[i])) except Exception as e: lcc.log_error(e) finally: if (len(self.driver.window_handles) > 1): self.driver.close() utilities.switch_to_first_tab(self.driver)
def view_assembly_on_cp(self): test_repo_name = base.config_reader('test_repo', 'repo_name') try: utilities.page_reload(self.driver) utilities.click_element(self.driver, By.CSS_SELECTOR, locators.VIEW_ON_PORTAL_LINK_CSS) utilities.wait(5) utilities.switch_to_latest_tab(self.driver) utilities.wait(7) check_that( "URL portal is", self.driver.current_url, contains_string( "https://access.qa.redhat.com/documentation/en-us/" + constants.product_name_uri + "/" + constants.product_version + "/guide/")) assembly_title = utilities.find_shadow_dom_element( self.driver, locators.DOCUMENT_TITLE_CP, locators.MODULE_BODY_ON_PORTAL_CSS).text check_that("Assembly title", assembly_title, contains_string(constants.assembly_to_be_published)) product_name = utilities.find_shadow_dom_element( self.driver, locators.PRODUCT_NAME_ON_PREVIEW_CSS, locators.MODULE_BODY_ON_PORTAL_CSS).text check_that("Product name reflected on view page", product_name, contains_string(constants.product_name)) product_version = utilities.find_shadow_dom_element( self.driver, locators.PRODUCT_VERSION_ON_PREVIEW_CSS, locators.MODULE_BODY_ON_PORTAL_CSS).text check_that("Product version reflected on view page", product_version, contains_string(constants.product_version)) image = utilities.find_shadow_dom_element( self.driver, locators.IMAGE_CSS, locators.MODULE_BODY_ON_PORTAL_CSS) src = image.get_attribute("src") imageasset = urlparse(src) imageasset = imageasset.path.split("/")[2] cmd = "echo " + imageasset + "|base64 -d" try: # subprocess.check_call(cmd, shell=True) path = subprocess.getoutput(cmd) print("Image file path::", path) image_file = "/content/repositories/" + test_repo_name + "/entities/enterprise/assemblies/images/" + constants.image_file_name check_that("Path to image1", path, equal_to(image_file)) except subprocess.CalledProcessError as e: lcc.log_info("Unable to decode imageasset") assembly_body = utilities.get_text( self.driver, By.CSS_SELECTOR, locators.ASSEMBLY_BODY_PREVIEW_CSS) for i in range(test_view_assembly.modules_count): check_that( "Assembly body", assembly_body, contains_string(test_view_assembly.module_titles[i])) guides_content_related = utilities.find_shadow_dom_element( self.driver, locators.CONTENT_RELATED_TO_GUIDES, locators.MODULE_BODY_ON_PORTAL_CSS) self.driver.execute_script("arguments[0].scrollIntoView();", guides_content_related) utilities.wait(20) check_that("Content related to this guide setcion", guides_content_related.is_displayed(), equal_to(True)) # utilities.click_element(self.driver, By.XPATH, "//summary[text()='Content related to this guide']") additional_res_guide = utilities.find_shadow_dom_element( self.driver, locators.CONTENT_RELATED_GUIDES_RESOURCES, locators.MODULE_BODY_ON_PORTAL_CSS) check_that( "Content related to this guide setcion to contain Addtional resources setion", additional_res_guide.is_displayed(), equal_to(True)) except Exception as e: lcc.log_error(e) finally: if (len(self.driver.window_handles) > 1): self.driver.close() utilities.switch_to_first_tab(self.driver)
def view_content_on_cp(self): # # try: test_repo_name = base.config_reader('test_repo', 'repo_name') utilities.click_element(self.driver, By.LINK_TEXT, "Search") utilities.wait(5) # search_page.search_for_module_and_click(self.driver, constants.published_module) search_beta_page.select_repo(self.driver, fixture.repo_name) search_beta_page.search_module_and_click(self.driver, constants.published_module) utilities.wait(5) try: adoc_file_path = display_module_page.get_path_to_adoc(self.driver) utilities.click_element(self.driver, By.CSS_SELECTOR, locators.VIEW_ON_PORTAL_LINK_CSS) utilities.switch_to_latest_tab(self.driver) utilities.wait(6) content_body_on_portal = self.driver.find_element_by_css_selector( locators.MODULE_BODY_ON_PORTAL_CSS) # Verify content displayed on CP check_that( "Module title is displayed", utilities.find_shadow_dom_element( self.driver, locators.MODULE_TITLE_ON_PORTAL_CSS, locators.MODULE_BODY_ON_PORTAL_CSS).get_attribute( "textContent"), equal_to(constants.published_module)) check_that( "Product name displayed on Customer Portal", utilities.find_shadow_dom_element( self.driver, locators.CP_PRODUCT_NAME_CSS, locators.MODULE_BODY_ON_PORTAL_CSS).get_attribute( "textContent"), equal_to(constants.product_name)) check_that( "Product version displayed on Customer Portal", utilities.find_shadow_dom_element( self.driver, locators.CP_PRODUCT_VERSION_CSS, locators.MODULE_BODY_ON_PORTAL_CSS).get_attribute( "textContent"), equal_to(constants.product_version)) legal_notice = utilities.find_shadow_dom_element( self.driver, locators.LEGAL_NOTICE_ON_PORTAL_CSS, locators.MODULE_BODY_ON_PORTAL_CSS) check_that( "legal notice is displayed at the bottom of preview page", legal_notice.get_attribute("textContent"), contains_string("Legal Notices for Trademarks")) legal_notice_href = legal_notice.get_attribute("href") check_that("verify legal notice link", legal_notice_href, contains_string(constants.legal_notice_link)) image = utilities.find_shadow_dom_element( self.driver, locators.IMAGE_CSS, locators.MODULE_BODY_ON_PORTAL_CSS) src = image.get_attribute("src") imageasset = urlparse(src) imageasset = imageasset.path.split("/")[2] cmd = "echo " + imageasset + "|base64 -d" try: # subprocess.check_call(cmd, shell=True) path = subprocess.getoutput(cmd) print("Image file path::", path) print("File name::", constants.image_file_name) print("Path to adoc::", adoc_file_path) p1 = os.path.split(adoc_file_path) image_file = "/" + p1[ 0] + "/images/" + constants.image_file_name # image_file = "/content/repositories/" + test_repo_name + "/entities/enterprise/modules/images/" + constants.image_file_name check_that("Path to image1", path, equal_to(image_file)) except subprocess.CalledProcessError as e: lcc.log_info("Unable to decode imageasset") except Exception as e: lcc.log_info(e) finally: if (len(self.driver.window_handles) > 1): self.driver.close() utilities.switch_to_first_tab(self.driver)