def driver(): firefox_options = Options() firefox_options.add_argument("-headless") driver = webdriver.Firefox(firefox_options=firefox_options, projectname="CI - Python") yield driver driver.quit()
def browser(config): # Initialize shared arguments kwargs = { 'projectname': config['testproject_projectname'], 'token': config['testproject_token'] } # Initialize the TestProject WebDriver instance # Note that these objects use the same API as Selenium WebDriver # The only thing different is the initialization call # Therefore, any WebDriver-based project can easily be retrofitted to use TestProject! if config['browser'] == 'Firefox': b = webdriver.Firefox(**kwargs) elif config['browser'] == 'Chrome': b = webdriver.Chrome(**kwargs) elif config['browser'] == 'Headless Chrome': opts = ChromeOptions() opts.add_argument('headless') b = webdriver.Chrome(chrome_options=opts, **kwargs) else: raise Exception(f'Browser "{config["browser"]}" is not supported') # Make its calls wait for elements to appear b.implicitly_wait(config['implicit_wait']) # Return the WebDriver instance for the setup yield b # Quit the WebDriver instance for the cleanup b.quit()
def driver(): firefox_options = Options() firefox_options.add_argument("-headless") driver = webdriver.Firefox(firefox_options=firefox_options, project_name="CI - Python") driver.set_window_size(1920, 1080) yield driver driver.quit()
def driver(): os.environ["TP_AGENT_URL"] = "http://localhost:8787" driver = webdriver.Firefox( token="MSlM0L0EXHkqZ0CLf98m9Qn4YRcBoPaaxsMEDsH6FrQ1", project_name="Demo Project", job_name="AirBnb Test") step_settings = StepSettings( timeout=15000, screenshot_condition=TakeScreenshotConditionType.Failure) with DriverStepSettings(driver, step_settings): yield driver driver.quit()
def driver(): # Define a different port for the 2nd container os.environ["TP_AGENT_URL"] = "http://localhost:8787" driver = webdriver.Firefox( token="kJCeheoppFyo8uaZ17k0JQyBck1qLIf5ZrynbI6t7Fk1", project_name="Ran's Project", job_name="Python Test Check") step_settings = StepSettings( timeout=15000, screenshot_condition=TakeScreenshotConditionType.Failure) with DriverStepSettings(driver, step_settings): yield driver driver.quit()
def init_testproject_driver( self, browser: str = "firefox", url: Optional[str] = None, timeout: Optional[int] = 5000, project_name: Optional[str] = "TestProject Robot", job_name: Optional[str] = "Robot Job", desired_capabilities: Union[str, dict, None] = None, disabled_reports: Optional[bool] = False, dev_token: Optional[str] = os.getenv("TP_DEV_TOKEN"), ): logger.console(f"Initializing TestProject Library for Robot v{definitions.get_lib_version()}...") # # Make sure development token is set # if not dev_token: # BuiltIn().fatal_error( # "******************************************************************************\n" # "* TestProject Development token not set! *\n" # "* Please use the 'dev_token' argument of the 'init_testproject_driver' *\n" # "* keyword, or set the 'TP_DEV_TOKEN' environment variable. *\n" # "******************************************************************************" # ) driver = None # Check if instance of Options to pass to the driver. if not isinstance(desired_capabilities, (ChromeOptions, FirefoxOptions, IeOptions)): desired_capabilities = self._build_capabilities( WebDriverCreator(os.getcwd())._parse_capabilities(capabilities=desired_capabilities, browser=browser), browser ) # If headless, override and start a clean headless session. if "headless" in browser: type = browser.split("headless", 1)[1] if type == "chrome": desired_capabilities = ChromeOptions() elif type == "firefox": desired_capabilities = FirefoxOptions() else: raise ValueError("Headless is supported for FireFox and Chrome only") desired_capabilities.add_argument("--headless") browser = type if browser in self.FIREFOX_NAMES: driver = webdriver.Firefox( firefox_options=desired_capabilities, token=dev_token, projectname=project_name, jobname=job_name, disable_reports=disabled_reports, ) elif browser in self.CHROME_NAMES: driver = webdriver.Chrome( chrome_options=desired_capabilities, token=dev_token, projectname=project_name, jobname=job_name, disable_reports=disabled_reports, ) elif browser in self.IE_NAMES: driver = webdriver.Ie( ie_options=desired_capabilities, token=dev_token, projectname=project_name, jobname=job_name, disable_reports=disabled_reports, ) elif browser == "edge": driver = webdriver.Edge( edge_options=desired_capabilities, token=dev_token, projectname=project_name, jobname=job_name, disable_reports=disabled_reports, ) elif browser == "safari": driver = webdriver.Safari( desired_capabilities=desired_capabilities, token=dev_token, projectname=project_name, jobname=job_name, disable_reports=disabled_reports, ) else: raise ValueError("Unsupported Browser, please look at the official TestProject library documentation") driver.report().disable_command_reports(True) driver.set_script_timeout(timeout) driver.report().step(message="Set timeout", description=f"Time out was set to {timeout}", passed=True) try: driver.get(url) driver.report().step(message=f"Navigated to {url}", description=f"Successfully navigated to {url}", passed=True) except Exception: driver.report().step(message=f"Failed to open {url}", description=f"Failed to open {url}", passed=True) raise self.library.register_driver(driver=driver, alias="testproject_driver") self.__reporter = driver.report() self.__reporter.exclude_test_names(["run_cli", "main"])
def driver(): driver = webdriver.Firefox(firefox_options=Options(), project_name="Examples", job_name=None) yield driver driver.quit()