コード例 #1
0
 def setUpClass(cls):
     curr_dir = os.path.dirname(os.path.abspath(__file__))
     cls.output_dir = os.path.abspath(
         os.path.join(curr_dir, '..', '..', 'output_dir'))
     cls.creator = WebDriverCreator(cls.output_dir)
コード例 #2
0
def creator():
    curr_dir = os.path.dirname(os.path.abspath(__file__))
    output_dir = os.path.abspath(
        os.path.join(curr_dir, '..', '..', 'output_dir'))
    return WebDriverCreator(output_dir)
コード例 #3
0
    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"])