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 switch_to_latest_tab(driver): wait(5) driver.switch_to.window(driver.window_handles[1]) lcc.log_info( "Find the CP preview in the attachment below for debugging purposes") random = generate_random_string(3) file_name = "cp_preview_" + random + ".png" driver.save_screenshot(file_name) lcc.save_attachment_file(file_name)
def test(self, project_dir): # image from https://pixabay.com/en/cake-lemon-sweet-yellow-food-2700645/ image_path = osp.join(project_dir, "cake.jpg") lcc.set_step("Attachment") lcc.save_attachment_file(image_path) lcc.set_step("Image attachment") lcc.save_image_file(image_path)
def add_file_to_report(self, kind, filename, file_description, data=None): try: if kind == "file" and data is None: lcc.set_step("Attachment file") lcc.save_attachment_file( self.get_file_attachment_path(filename), file_description) elif kind == "image" and data is None: lcc.set_step("Image attachment") lcc.save_image_file(self.get_file_attachment_path(filename), file_description) elif kind == "file" and data is not None: lcc.set_step("Attachment file content") lcc.save_attachment_content(data, filename, file_description) elif kind == "image" and data is not None: lcc.set_step("Image attachment content") lcc.save_image_content(data, filename, file_description) except FileNotFoundError: lcc.log_error("File or image does not exist!")
def modules_assemblies_list(self): utilities.wait(1) module_title_list = utilities.find_elements_by_css_selector( self.driver, locators.MODULE_TITLES_CSS) modules_count = len(module_title_list) modules = modules_count - 1 lcc.log_info("Modules displayed: %s " % str(modules)) for i in range(1, modules_count): check_that("Modules listed for selected repo", module_title_list[i].text, contains_string(self.module_prefix)) assembly_title_list = utilities.find_elements_by_css_selector( self.driver, locators.ASSEMBLY_TITLES_CSS) assembly_count = len(assembly_title_list) assemblies = assembly_count - 1 lcc.log_info("Assemblies displayed: %s" % str(assemblies)) for i in range(1, assembly_count): check_that("Assemblies listed for selected repo", assembly_title_list[i].text, contains_string(self.assembly_prefix)) lcc.log_info( "Find the Search beta page preview in the attachment below:") self.driver.save_screenshot("search_beta_repo_selected.png") lcc.save_attachment_file("search_beta_repo_selected.png")
def capture_screenshot(driver, target_path=os.path.join(Global.SCREENSHOTS_DIR, "screenshot.png")): driver.save_screenshot(target_path) lcc.save_attachment_file(filename=target_path, description="Click here to view the screenshot")
def do(): filename = osp.join(tmpdir.strpath, "somefile.txt") with open(filename, "w") as fh: fh.write("some other content") lcc.save_attachment_file(filename, "some other file")