def test_create_instance():
    with patch("atexit.register", autospec=True)as mock_register:
        driver = chrome_driver.create_instance(headless=True)
        try:
            assert type(driver) is Chrome
            mock_register.assert_called_once_with(driver.quit)
        finally:
            driver.quit()
def test_create_instance_with_user_data_dir():
    with TemporaryDirectory() as tmp_dir:
        user_data_dir = Path(tmp_dir).joinpath("chrome_user_data_dir")
        assert not user_data_dir.exists()
        driver = chrome_driver.create_instance(headless=True, user_data_dir=user_data_dir)
        try:
            assert user_data_dir.exists()
        finally:
            driver.quit()
def test_create_instance_with_downloads_dir():
    with TemporaryDirectory() as tmp_dir:
        downloads_dir = Path(tmp_dir).joinpath("chrome_downloads")
        assert not downloads_dir.exists()
        driver = chrome_driver.create_instance(headless=True, downloads_dir=downloads_dir)
        try:
            assert downloads_dir.exists()
        finally:
            driver.quit()
Beispiel #4
0
def init_driver(headless: bool):
    try:
        _log.info("Initializing driver... (headless: %s)", headless)
        driver = chrome_driver.create_instance(headless=headless)
    except Exception as err:
        raise RuntimeError("Could not create driver instance!") from err

    driver.set_page_load_timeout(10)
    SharedDriver.set_instance(driver)
def main():
    from hed_utils.selenium import chrome_driver, SharedDriver
    from hed_utils.support import log
    log.init(logging.DEBUG)

    driver = chrome_driver.create_instance()
    SharedDriver.set_instance(driver)

    urls = [
        "https://youtube.com", "https://facebook.com",
        "https://stackoverflow.com"
    ]

    for url in urls:
        get_load_stats(SharedDriver(), url)