Exemplo n.º 1
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
Exemplo n.º 2
0
    def __init__(self, config_path="", autostart=True):
        """
        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.
        """
        #Global Variables:

        if config_path == "":
            config_path = os.path.join(sys.path[0], r"config.json")
        self.config = ConfigLoader(config_path)
        self.config.autostart = autostart

        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.test_case = []
        self.last_test_case = None
        self.message = ""
        self.expected = True

        try:
            self.log.user = os.getlogin()
        except Exception:
            import getpass
            self.log.user = getpass.getuser()

        self.base_container = "body"
        self.errors = []
        self.config.log_file = False
        self.tmenu_out_iframe = False

        if autostart:
            self.Start()