Beispiel #1
0
    def test_match_latest_executable__version_has_four_components(
            self, dir_function, test_utils):
        basedir = dir_function.path
        test_utils.create_empty_file(basedir, 'chromedriver_91.0.4472.19.exe')
        test_utils.create_empty_file(basedir, 'chromedriver_89.0.4389.23.exe')
        result = utils.match_latest_executable_path('chromedriver*', basedir)
        assert result == os.path.join(basedir, 'chromedriver_91.0.4472.19.exe')

        test_utils.create_empty_file(basedir, 'geckodriver_91.0.4472.19')
        test_utils.create_empty_file(basedir, 'geckodriver_89.0.4389.23')
        result = utils.match_latest_executable_path('geckodriver*', basedir)
        assert result == os.path.join(basedir, 'geckodriver_91.0.4472.19')
Beispiel #2
0
 def validate_exec_path(browser_name, exec_path_setting, settings):
     executable_path = settings[exec_path_setting]
     if executable_path:
         matched_executable_path = utils.match_latest_executable_path(
             executable_path)
         if matched_executable_path:
             try:
                 yield matched_executable_path
             except:
                 msg = (
                     'Could not start {} driver using the path \'{}\'\n'
                     'verify that the {} setting points to a valid webdriver executable.'
                     .format(browser_name, executable_path,
                             exec_path_setting))
                 execution.logger.error(msg)
                 execution.logger.info(traceback.format_exc())
                 raise Exception(msg)
         else:
             msg = 'No executable file found using path {}'.format(
                 executable_path)
             execution.logger.error(msg)
             raise Exception(msg)
     else:
         msg = '{} setting is not defined'.format(exec_path_setting)
         execution.logger.error(msg)
         raise Exception(msg)
Beispiel #3
0
 def test_match_latest_executable_path_exe(self, dir_function, test_utils):
     """test that match_latest works for filenames ending in .exe"""
     basedir = dir_function.path
     test_utils.create_empty_file(basedir, 'chromedriver_2.4.exe')
     test_utils.create_empty_file(basedir, 'chromedriver_2.3.exe')
     test_utils.create_empty_file(basedir, 'geckodriver_5.6.7.exe')
     result = utils.match_latest_executable_path('chromedriver*', basedir)
     assert result == os.path.join(basedir, 'chromedriver_2.4.exe')
Beispiel #4
0
 def test_asterisk_subdir(self, dir_function, test_utils):
     """test that '*' wildcard can be used for dirs"""
     basedir = dir_function.path
     path = os.path.join(basedir, 'drivers')
     test_utils.create_empty_file(path, 'chromedriver_2.2')
     test_utils.create_empty_file(path, 'chromedriver_2.4')
     result = utils.match_latest_executable_path('./*/chromedriver*', basedir)
     assert result == os.path.join(path, 'chromedriver_2.4')
Beispiel #5
0
 def test_match_latest_executable_path__absolute_path(self, dir_function, test_utils):
     """an absolute path can be passed"""
     basedir = dir_function.path
     test_utils.create_empty_file(basedir, 'chromedriver_2.2')
     test_utils.create_empty_file(basedir, 'chromedriver_2.3')
     abspath = os.path.join(os.path.abspath(basedir), 'chromedriver_2.3')
     result = utils.match_latest_executable_path(abspath, basedir)
     assert result == os.path.join(basedir, 'chromedriver_2.3')
Beispiel #6
0
 def test_no_asterisk(self, dir_function, test_utils):
     """test that match_latest still works using
     no wildcards
     """
     basedir = dir_function.path
     path = os.path.join(basedir, 'drivers')
     test_utils.create_empty_file(path, 'chromedriver_2.2')
     test_utils.create_empty_file(path, 'chromedriver_2.4')
     result = utils.match_latest_executable_path('./drivers/chromedriver_2.2', basedir)
     assert result == os.path.join(path, 'chromedriver_2.2')
Beispiel #7
0
 def test_match_latest_executable_path__compare_versions_not_strings(self, dir_function, test_utils):
     """2.12 should be higher than 2.9
     (but it's when not comparing just strings)
     e.g. '2.9' > '2.12'
     """
     basedir = dir_function['path']
     test_utils.create_empty_file(basedir, 'chromedriver_2.9')
     test_utils.create_empty_file(basedir, 'chromedriver_2.12')
     result = utils.match_latest_executable_path('chromedriver*')
     assert result == os.path.join(basedir, 'chromedriver_2.12')
Beispiel #8
0
 def test_match_latest_executable_path(self, dir_function, test_utils):
     """the latest version filepath matching glob pattern
     is returned
     """
     basedir = dir_function.path
     test_utils.create_empty_file(basedir, 'chromedriver_2.2')
     test_utils.create_empty_file(basedir, 'chromedriver_2.4')
     test_utils.create_empty_file(basedir, 'chromedriver_2.3')
     test_utils.create_empty_file(basedir, 'geckodriver_5.6.7')
     result = utils.match_latest_executable_path('chromedriver*', basedir)
     assert result == os.path.join(basedir, 'chromedriver_2.4')
Beispiel #9
0
 def test_match_latest_executable_path_subdir(self, dir_function, test_utils):
     """test that match_latest works passing a rel path
     to a subdir
     """
     basedir = dir_function.path
     path = os.path.join(basedir, 'drivers')
     test_utils.create_empty_file(path, 'chromedriver_2.2')
     test_utils.create_empty_file(path, 'chromedriver_2.4')
     test_utils.create_empty_file(path, 'chromedriver_2.3')
     test_utils.create_empty_file(path, 'geckodriver_5.6.7')
     result = utils.match_latest_executable_path('./drivers/chromedriver*', basedir)
     assert result == os.path.join(path, 'chromedriver_2.4')
Beispiel #10
0
 def validate_exec_path(browser_name, exec_path_setting, settings):
     executable_path = settings[exec_path_setting]
     if executable_path:
         matched_executable_path = utils.match_latest_executable_path(
             executable_path, execution.testdir)
         if matched_executable_path:
             try:
                 yield matched_executable_path
             except:
                 msg = f"Could not start {browser_name} driver using the path '{executable_path}'\n" \
                       f"verify that the {exec_path_setting} setting points to a valid webdriver executable."
                 execution.logger.error(msg)
                 execution.logger.info(traceback.format_exc())
                 raise Exception(msg)
         else:
             msg = f'No executable file found using path {executable_path}'
             execution.logger.error(msg)
             raise Exception(msg)
     else:
         msg = f'{exec_path_setting} setting is not defined'
         execution.logger.error(msg)
         raise Exception(msg)
Beispiel #11
0
 def test_match_latest_executable_path__no_match(self, dir_function):
     result = utils.match_latest_executable_path(dir_function.path,
                                                 dir_function.path)
     assert result is None
Beispiel #12
0
def open_browser(browser_id=None):
    """Open a browser.

    When opening more than one browser instance per test
    provide a browser_id to switch between browsers later on
    """
    msg_could_not_start_driver = (
        'Could not start {} driver using the path \'{}\', '
        'check the settings file.')
    driver = None
    browser_definition = execution.browser_definition
    settings = execution.settings
    if browser_definition['remote'] is True:
        driver = webdriver.Remote(
            command_executor=settings['remote_url'],
            desired_capabilities=browser_definition['capabilities'])
    elif browser_definition['name'] == 'firefox':
        if settings['geckodriver_path']:
            executable_path = utils.match_latest_executable_path(
                settings['geckodriver_path'])
            try:
                driver = webdriver.Firefox(executable_path=executable_path)
            except:
                execution.logger.error(
                    msg_could_not_start_driver.format(
                        'firefox', settings['geckodriver_path']))
                execution.logger.info(traceback.format_exc())
                raise Exception(msg)
        else:
            raise Exception('geckodriver_path setting is not defined')
    elif browser_definition['name'] == 'chrome':
        if settings['chromedriver_path']:
            try:
                executable_path = utils.match_latest_executable_path(
                    settings['chromedriver_path'])
                chrome_options = Options()
                chrome_options.add_argument('--start-maximized')
                driver = webdriver.Chrome(executable_path=executable_path,
                                          chrome_options=chrome_options)
            except:
                execution.logger.error(
                    msg_could_not_start_driver.format(
                        'chrome', settings['chromedriver_path']))
                execution.logger.info(traceback.format_exc())
                raise Exception(msg)
        else:
            raise Exception('chromedriver_path setting is not defined')
    elif browser_definition['name'] == 'chrome-headless':
        if settings['chromedriver_path']:
            try:
                executable_path = utils.match_latest_executable_path(
                    settings['chromedriver_path'])
                options = webdriver.ChromeOptions()
                options.add_argument('headless')
                options.add_argument('--window-size=1600,1600')
                driver = webdriver.Chrome(executable_path=executable_path,
                                          chrome_options=options)
            except:
                execution.logger.error(
                    msg_could_not_start_driver.format(
                        'chrome', settings['chromedriver_path']))
                execution.logger.info(traceback.format_exc())
                raise Exception(msg)
        else:
            raise Exception('chromedriver_path setting is not defined')
    elif browser_definition['name'] == 'ie':
        if settings['iedriver_path']:
            try:
                executable_path = utils.match_latest_executable_path(
                    settings['iedriver_path'])
                driver = webdriver.Ie(executable_path=executable_path)
            except:
                execution.logger.error(
                    msg_could_not_start_driver.format(
                        'internet explorer', settings['geckodriver_path']))
                execution.logger.info(traceback.format_exc())
                raise Exception(msg)
        else:
            raise Exception('iedriver_path setting is not defined')
    elif browser_definition['name'] == 'ie-remote':
        driver = webdriver.Remote(command_executor=settings['remote_url'],
                                  desired_capabilities=DesiredCapabilities.IE)
    elif browser_definition['name'] == 'chrome-remote-headless':
        options = webdriver.ChromeOptions()
        options.add_argument('headless')
        desired_capabilities = options.to_capabilities()
        driver = webdriver.Chrome(command_executor=settings['remote_url'],
                                  desired_capabilities=desired_capabilities)
    elif browser_definition['name'] == 'chrome-remote':
        driver = webdriver.Remote(
            command_executor=settings['remote_url'],
            desired_capabilities=DesiredCapabilities.CHROME)
    elif browser_definition['name'] == 'firefox-remote':
        driver = webdriver.Remote(
            command_executor=settings['remote_url'],
            desired_capabilities=DesiredCapabilities.FIREFOX)
    else:
        raise Exception('Error: {} is not a valid driver'.format(
            browser_definition['name']))

    driver.maximize_window()

    # bind _find and _find_all methods to driver instance
    driver.find = types.MethodType(_find, driver)
    driver.find_all = types.MethodType(_find_all, driver)

    if not browser_id:
        if len(execution.browsers) == 0:
            execution.browsers['main'] = driver
        else:
            browser_id = 'browser{}'.format(len(execution.browsers) + 1)
            execution.browsers[browser_id] = driver
    else:
        execution.browsers[browser_id] = driver
    if not execution.browser:
        execution.browser = driver