Example #1
0
    def Start(self):
        """
        Opens the browser maximized and goes to defined URL.

        Usage:

        >>> # Calling the method:
        >>> oHelper.Start()
        """
        print("Starting the browser")
        if self.config.browser.lower() == "firefox":
            if sys.platform == 'linux':
                driver_path = os.path.join(os.path.dirname(__file__),
                                           r'drivers/linux64/geckodriver')
            else:
                driver_path = os.path.join(
                    os.path.dirname(__file__),
                    r'drivers\\windows\\geckodriver.exe')
            log_path = os.devnull

            options = FirefoxOpt()
            options.set_headless(self.config.headless)
            self.driver = webdriver.Firefox(firefox_options=options,
                                            executable_path=driver_path,
                                            log_path=log_path)
        elif self.config.browser.lower() == "chrome":
            driver_path = os.path.join(os.path.dirname(__file__),
                                       r'drivers\\windows\\chromedriver.exe')
            options = ChromeOpt()
            options.set_headless(self.config.headless)
            options.add_argument('--log-level=3')
            if self.config.headless:
                options.add_argument('force-device-scale-factor=0.77')

            self.driver = webdriver.Chrome(chrome_options=options,
                                           executable_path=driver_path)
        elif self.config.browser.lower() == "electron":
            driver_path = os.path.join(
                os.path.dirname(__file__),
                r'drivers\\windows\\electron\\chromedriver.exe'
            )  # TODO chromedriver electron version
            options = ChromeOpt()
            options.add_argument('--log-level=3')
            options.binary_location = self.config.electron_binary_path
            self.driver = webdriver.Chrome(chrome_options=options,
                                           executable_path=driver_path)

        if not self.config.browser.lower() == "electron":
            if self.config.headless:
                self.driver.set_window_position(0, 0)
                self.driver.set_window_size(1366, 768)
            else:
                self.driver.maximize_window()

            self.driver.get(self.config.url)

        self.wait = WebDriverWait(self.driver, 90)
Example #2
0
    def Start(self):
        """
        Opens the browser maximized and goes to defined URL.

        Usage:

        >>> # Calling the method:
        >>> oHelper.Start()
        """
        print("Starting the browser")
        if self.config.browser.lower() == "firefox":
            driver_path = os.path.join(os.path.dirname(__file__),
                                       r'drivers\\geckodriver.exe')
            log_path = os.path.join(os.path.dirname(__file__),
                                    r'geckodriver.log')
            options = FirefoxOpt()
            options.set_headless(self.config.headless)
            self.driver = webdriver.Firefox(firefox_options=options,
                                            executable_path=driver_path,
                                            log_path=log_path)
        elif self.config.browser.lower() == "chrome":
            driver_path = os.path.join(os.path.dirname(__file__),
                                       r'drivers\\chromedriver.exe')
            options = ChromeOpt()
            options.set_headless(self.config.headless)
            self.driver = webdriver.Chrome(chrome_options=options,
                                           executable_path=driver_path)

        self.driver.maximize_window()
        self.driver.get(self.config.url)
        self.wait = WebDriverWait(self.driver, 5)
Example #3
0
    def __init__(self, config_path=""):
        """
        Definition of each global variable:

        base_container: A variable to contain the layer element to be used on all methods.

        errors: A list that contains every error that should be sent to log at the end of the execution.

        language: Contains the terms defined in the language defined in config or found in the page.

        log: Object that controls the logs of the entire application.

        log.station: Property of the log that contains the machine's hostname.

        log_file: A variable to control when to generate a log file of each execution of web_scrap. (Debug purposes)

        wait: The global Selenium Wait defined to be used in the entire application.
        """
        if config_path == "":
            config_path = os.path.join(sys.path[0], r"config.json")
        self.config = ConfigLoader(config_path)

        if self.config.browser.lower() == "firefox":
            driver_path = os.path.join(os.path.dirname(__file__),
                                       r'drivers\\geckodriver.exe')
            log_path = os.path.join(os.path.dirname(__file__),
                                    r'geckodriver.log')
            options = FirefoxOpt()
            options.set_headless(self.config.headless)
            self.driver = webdriver.Firefox(firefox_options=options,
                                            executable_path=driver_path,
                                            log_path=log_path)
        elif self.config.browser.lower() == "chrome":
            driver_path = os.path.join(os.path.dirname(__file__),
                                       r'drivers\\chromedriver.exe')
            options = ChromeOpt()
            options.set_headless(self.config.headless)
            self.driver = webdriver.Chrome(chrome_options=options,
                                           executable_path=driver_path)

        self.driver.maximize_window()
        self.driver.get(self.config.url)

        #Global Variables:

        self.wait = WebDriverWait(self.driver, 5)

        self.language = LanguagePack(
            self.config.language) if self.config.language else ""
        self.log = Log(folder=self.config.log_folder)
        self.log.station = socket.gethostname()

        self.base_container = "body"
        self.errors = []
        self.config.log_file = False
Example #4
0
    def Start(self):
        """
        Opens the browser maximized and goes to defined URL.

        Usage:

        >>> # Calling the method:
        >>> oHelper.Start()
        """

        logger().info(f'TIR Version: {__version__}')
        logger().info("Starting the browser")
        if self.config.browser.lower() == "firefox":
            if sys.platform == 'linux':
                driver_path = os.path.join(os.path.dirname(__file__),
                                           r'drivers/linux64/geckodriver')
            else:
                driver_path = os.path.join(
                    os.path.dirname(__file__),
                    r'drivers\\windows\\geckodriver.exe')
            log_path = os.devnull

            firefox_options = FirefoxOpt()
            firefox_options.set_headless(self.config.headless)
            self.driver = webdriver.Firefox(options=firefox_options,
                                            executable_path=driver_path,
                                            log_path=log_path)
        elif self.config.browser.lower() == "chrome":
            driver_path = os.path.join(os.path.dirname(__file__),
                                       r'drivers\\windows\\chromedriver.exe')
            chrome_options = ChromeOpt()
            chrome_options.set_headless(self.config.headless)
            chrome_options.add_argument('--log-level=3')
            if self.config.headless:
                chrome_options.add_argument('force-device-scale-factor=0.77')

            self.driver = webdriver.Chrome(options=chrome_options,
                                           executable_path=driver_path)
        elif self.config.browser.lower() == "electron":
            driver_path = os.path.join(
                os.path.dirname(__file__),
                r'drivers\\windows\\electron\\chromedriver.exe')
            chrome_options = ChromeOpt()
            chrome_options.add_argument('--log-level=3')
            chrome_options.add_argument(
                f'--environment="{self.config.environment}"')
            chrome_options.add_argument(f'--url="{self.config.url}"')
            chrome_options.add_argument(
                f'--program="{self.config.start_program}"')
            chrome_options.add_argument('--quiet')
            chrome_options.binary_location = self.config.electron_binary_path
            self.driver = webdriver.Chrome(options=chrome_options,
                                           executable_path=driver_path)

        if not self.config.browser.lower() == "electron":
            if self.config.headless:
                self.driver.set_window_position(0, 0)
                self.driver.set_window_size(1366, 768)
            else:
                self.driver.maximize_window()

            self.driver.get(self.config.url)

        self.wait = WebDriverWait(self.driver, self.config.time_out)