def capture_page_screenshot_extension(prefix="", postfix="", add_time_stamp=True, add_test_case_name=True, add_file_path_to_list="${list of screenshots}", output_dir="Artifacts/Screenshots"): output_dir_normalized = validate_create_artifacts_dir(output_dir) if add_time_stamp: current_time = " " + DateTime.get_current_date(result_format="%Y.%m.%d_%H.%M.%S") else: current_time = "" if add_test_case_name: test_case_name = bi().get_variable_value("${TEST_NAME}") else: test_case_name = "" output_file = output_dir_normalized + "/" + prefix + test_case_name + postfix + current_time + ".png" output_file_normalized = os.path.normpath(output_file) # sl()driver.get_screenshot_as_file(output_file_normalized) sl().capture_page_screenshot(output_file_normalized) results = bi().run_keyword_and_return_status("Variable Should Exist", add_file_path_to_list) if not results: bi()._get_var_name(add_file_path_to_list) list_with_files = bi().create_list(output_file_normalized) bi().set_test_variable(add_file_path_to_list, list_with_files) else: list_with_files = bi().create_list(output_file_normalized) list_with_files = bi().run_keyword("Combine Lists", add_file_path_to_list, list_with_files) bi().set_test_variable(add_file_path_to_list, list_with_files) return output_file_normalized
def set_browser_size_and_position(self, width=WIDTH_DEFAULT, height=HEIGHT_DEFAULT, x=0, y=0): sl().set_window_size(width, height) sl().set_window_position(x, y)
def open_new_tab(self, url): """Hack it use Control +t to open new tab""" driver = sl().driver body = driver.find_element_by_tag_name("body") body.send_keys(Keys.CONTROL + "t") time.sleep(2) sl().go_to(url)
def click_element_extended_and_wait( self, locator, sleep, modifier=False, action_chain=False, timeout=None, error_msg=None, reason=None, ): sl().click_element_extended(locator, timeout, error_msg) bi().sleep(sleep, reason)
def click_element_extended(locator, timeout=None, error_msg=None): """Click element proceed with following steps 1.wait_until_page_contains_element 2.wait_until_element_is_visible_wait_until_element_is_visible 3.mouse_over""" sl().wait_until_page_contains_element(locator, timeout, error_msg) sl().wait_until_element_is_visible(locator, timeout, error_msg) sl().mouse_over(locator) sl().click_element(locator)
def double_click_element_extended(self, locator, modifier=False, action_chain=False, timeout=None, error=None): """ Double Click element proceed with following steps * wait_until_page_contains_element * wait_until_element_is_visible_wait_until_element_is_visible * scroll_element_into_view * mouse_over * double_click_element """ sl().wait_until_page_contains_element(locator, timeout, error) sl().wait_until_element_is_visible(locator, timeout, error) sl().scroll_element_into_view(locator) sl().mouse_over(locator) sl().double_click_element(locator, modifier=modifier, action_chain=action_chain)
def element_attribute_should_be(self, locator, attribute, attribute_value_expected, msg=None, values=True): actual_value = sl().get_element_attribute(locator + "@" + attribute) # noinspection PyProtectedMember actual_value, attribute_value_expected = [ bi()._convert_to_string(i) for i in (actual_value, attribute_value_expected) ] bi()._should_be_equal(actual_value, attribute_value_expected, msg, values)
def go_to_smart(self, url): """Redirect only in on different url""" current_url = sl().get_location() if url != current_url: sl().go_to(url)
def close_tab(self): """Hack it use Control +w to close tab""" driver = sl().driver body = driver.find_element_by_tag_name("body") body.send_keys(Keys.CONTROL + "w")
def press_key_python(self, command, locator="//body", strategy="XPATH"): """Hack !!! example argument | Keys.CONTROL + 't' |Keys.TAB + Keys.SHIFT""" driver = sl().driver element = driver.find_element(eval("By." + strategy), locator) element.send_keys(eval(command))
def switch_tab_by_id(self, id_tab): """Hack it use Control + 1,2,3 etc to switch tab""" driver = sl().driver body = driver.find_element_by_tag_name("body") body.send_keys(Keys.CONTROL + id_tab) time.sleep(4)
def __init__(self): self.SELENIUM_LIBRARY = sl()
def import_jQuery(self): sl().execute_javascript(self.JQUERY_JS)
def import_xpath2(self): sl().execute_javascript(self.XPATH2_JS)
def open_browser_extension( self, url, browser="ff", width=WIDTH_DEFAULT, height=HEIGHT_DEFAULT, x="0", y="0", alias=None, remote_url=False, desired_capabilities=None, ff_profile_dir=None, selenium_timeout=SELENIUM_TIMEOUT, keyword_to_run_on_failure="Capture Page Screenshot Extension", ): sl().open_browser( "about:blank", browser, alias, remote_url, desired_capabilities, ff_profile_dir, ) sl().set_window_position(x, y) sl().set_window_size(width, height) sl().set_selenium_timeout(selenium_timeout) sl().register_keyword_to_run_on_failure(keyword_to_run_on_failure) sl().go_to(url)
def double_click_element_extended(locator, timeout=None, error=None): sl().wait_until_page_contains_element(locator, timeout, error) sl().wait_until_element_is_visible(locator, timeout, error) sl().mouse_over(locator) sl().double_click_element(locator)