def test_get_config(): assert config.get_config("ScreenshotType") == "screenshot" assert config.get_config("DefaultDocument") is True assert config.get_config( "MatchingInputElement") == SearchStrategies.MATCHING_INPUT_ELEMENT assert config.get_config("CssSelectors") is True assert config.get_config("TextMatch") == SearchStrategies.TEXT_MATCH
def test_reset_config(): old_val = config.set_config("ScreenshotType", "full_screen") assert old_val == "screenshot" resetted_val = config.reset_config("ScreenshotType") assert resetted_val == "screenshot" old_val = config.set_config("DefaultDocument", False) assert old_val is True resetted_val = config.reset_config("DefaultDocument") assert resetted_val is True old_val = config.set_config("ScreenshotType", "full_screen") assert old_val == "screenshot" old_val = config.set_config("DefaultDocument", False) assert old_val is True old_val = config.set_config("CaseInsensitive", True) assert old_val is False assert config.get_config("CaseInsensitive") is True # should automatically change ContainingTextMatch assert config.get_config( "ContainingTextMatch" ) == SearchStrategies.CONTAINING_TEXT_MATCH_CASE_INSENSITIVE resetted_val = config.reset_config("CaseInsensitive") assert resetted_val is False assert config.get_config( "ContainingTextMatch" ) == SearchStrategies.CONTAINING_TEXT_MATCH_CASE_SENSITIVE config.reset_config() assert config.get_config("ScreenshotType") == "screenshot" assert config.get_config("DefaultDocument") is True
def test_set_config(): old_val = config.set_config("ScreenshotType", "full_screen") assert old_val == "screenshot" assert config.get_config("ScreenshotType") == "full_screen" assert CONFIG["ScreenshotType"] == "full_screen" old_val = config.set_config("DefaultDocument", False) assert old_val is True assert config.get_config("DefaultDocument") is False assert CONFIG["DefaultDocument"] is False
def inner(*args, **kwargs): kwargs = {k.lower(): v for k, v in kwargs.items()} # Kwargs keys to lowercase if 'type_secret' not in str(keyword_method): logger.debug('args: {}, kwargs: {}'.format(args, kwargs)) try: time.sleep( timestr_to_secs(kwargs.get('delay', CONFIG['Delay']))) run_before_kw = CONFIG['RunBefore'] valid_pw = ['click', 'get_text', 'drop_down'] if run_before_kw and any(pw in str(keyword_method) for pw in valid_pw): logger.info( 'executing run before kw {}'.format(run_before_kw)) eval(run_before_kw) # pylint: disable=W0123 logger.trace(keyword_method) logger.trace(args, kwargs) return keyword_method(*args, **kwargs) except Exception as e: # pylint: disable=W0703 logger.debug(traceback.format_exc()) if not self._is_run_on_failure_keyword(keyword_method): if not util.par2bool(kwargs.get('skip_screenshot', False)): BuiltIn().run_keyword(self._run_on_failure_keyword) devmode = util.par2bool(BuiltIn().get_variable_value( '${DEV_MODE}', False)) if devmode and not config.get_config('Debug_Run'): Dialogs.pause_execution( 'Keyword {} {} {} failed. \n' 'Got {}'.format( str(keyword_method).split(' ')[1].upper(), str(args), str(kwargs), e)) debug.debug_on() else: raise
def test_reset_config(): old_val = config.set_config("ScreenshotType", "full_screen") assert old_val == "screenshot" resetted_val = config.reset_config("ScreenshotType") assert resetted_val == "screenshot" old_val = config.set_config("DefaultDocument", False) assert old_val is True resetted_val = config.reset_config("DefaultDocument") assert resetted_val is True old_val = config.set_config("ScreenshotType", "full_screen") assert old_val == "screenshot" old_val = config.set_config("DefaultDocument", False) assert old_val is True config.reset_config() assert config.get_config("ScreenshotType") == "screenshot" assert config.get_config("DefaultDocument") is True
def test_set_config(): old_val = config.set_config("ScreenshotType", "full_screen") assert old_val == "screenshot" assert config.get_config("ScreenshotType") == "full_screen" assert CONFIG["ScreenshotType"] == "full_screen" old_val = config.set_config("DefaultDocument", False) assert old_val is True assert config.get_config("DefaultDocument") is False assert CONFIG["DefaultDocument"] is False old_val = config.set_config("RunBefore", "text.verify_no_text('Loading')") assert old_val == None new_kw = ["VerifyText", "Test", "timeout=10"] old_val = config.set_config("RunBefore", new_kw) assert old_val == "text.verify_no_text('Loading')" new_kw = "Verify Something" old_val = config.set_config("RunBefore", new_kw) assert old_val == ["VerifyText", "Test", "timeout=10"] assert CONFIG["RunBefore"] == "Verify Something" config.reset_config("RunBefore") assert CONFIG["RunBefore"] == None
def log_screenshot_file(filepath): """Log screenshot file to robot framework log. Uses robot.utils.get_link_path to determine the relative path to the robot framework log file. Parameters ---------- filepath : str Filepath to the screenshot file. """ try: robot_output = BuiltIn().get_variable_value('${OUTPUT DIR}') if not config.get_config("OSScreenshots"): logger.info('Current url is: {}'.format(get_url())) link = get_link_path(filepath, robot_output) logger.info( '<a href="{0}"><img src="{0}" width="800px"></a>'.format(link), html=True) except RobotNotRunningError: return
def test_non_existing_parameter(): with pytest.raises(ValueError): config.get_config("new") with pytest.raises(ValueError): config.set_config("new", 100)
def save_screenshot(filename='screenshot_{}.png', folder=SCREEN_SHOT_DIR_NAME, pyautog=False): """Save screenshot of web page to a file. If robot framework is running then screenshots are saved to ${OUTPUT DIR}/screenshots. Otherwise the file is saved to current working directory. If there is no write access to cwd (jupyter in windows for example seems set cwd to system32) screenshot dir is set to operating systems temp directory. Parameters ---------- filename : str (default 'screenshot_{}.png') filename where the screenshot will be saved folder : str (default SCREEN_SHOT_DIR_NAME) folder where screenshot will be saved pyautog : bool (default False) True if pyautogui shall be used for screenshots and False if selenium shall be used Returns ------- str Filepath to the saved file. """ test_name = None try: robot_output = BuiltIn().get_variable_value('${OUTPUT DIR}') test_name = BuiltIn().get_variable_value('${TEST NAME}') screen_shot_dir = os.path.join(robot_output, folder) except RobotNotRunningError: screen_shot_dir = os.path.join(os.getcwd(), folder) if not os.access(screen_shot_dir, os.W_OK): screen_shot_dir = os.path.join(gettempdir(), folder) if not os.path.isdir(screen_shot_dir): os.makedirs(screen_shot_dir) if filename == 'screenshot_{}.png' and test_name is None: filename = filename.format(uuid4()) elif filename == 'screenshot_{}.png': name_with_underscores = test_name.replace(" ", "_") valid_name = _remove_invalid_chars(name_with_underscores) filename = "screenshot-" + valid_name + "-{}".format(uuid4()) + '.png' filepath = os.path.join(screen_shot_dir, filename) if pyautog is True or config.get_config("OSScreenshots"): # try to remove image, needed for scrot > 0.9 try: os.remove(filepath) except OSError: pass pyscreenshot(filepath) logger.info('Saved screenshot to {}'.format(filepath)) return filepath driver = browser.get_current_browser() if driver: try: saved = driver.save_screenshot(filepath) except (UnexpectedAlertPresentException, WebDriverException, QWebDriverError, InvalidSessionIdException): saved = pyscreenshot(filepath) if not saved: raise ValueError( 'Saving screenshot to {} did not succeed'.format(filepath)) logger.info('Saved screenshot to {}'.format(filepath)) return filepath