예제 #1
0
	def dump(instance_identifier, driver: ChromeDriver = None, with_screenshot = False, with_stacktrace=False, print_stacktrace=False):
		"""Dumps to the filesystem a file containing the tacktrace and/or a screenshot of the current page

		Args:
			instance_identifier (str): Unique identifier
			driver (ChromeDriver, optional): WebDriver instance to use for the screenshot. Defaults to None.
			with_screenshot (bool, optional): Whether to print a screenshot of the current webpage to file. Defaults to False.
			with_stacktrace (bool, optional): Whether to save the stacktrace to file. Defaults to False.
			print_stacktrace (bool, optional): Whether to print the stacktrace to screen. Defaults to False.
		"""
		if print_stacktrace:
			print("Stacktrace:")
			traceback.print_stack()

		CREATED_FILES = []
		
		FILE_PATH = os.path.dirname(os.path.realpath(getEntryPoint()))
		dump_time = datetime.now().strftime('%Y%m%d_%H%M%S')

		exception_log_filename = os.path.join(FILE_PATH, f"Debug-{dump_time}-{instance_identifier}.log")
		exception_png_filename = os.path.join(FILE_PATH, f"Debug-{dump_time}-{instance_identifier}.png")

		if with_stacktrace:
			with open(exception_log_filename, "w") as stacktrace_file:
				traceback.print_stack(file=stacktrace_file)
				CREATED_FILES.append(exception_log_filename)

		if driver and with_screenshot:
			driver.save_screenshot(exception_png_filename)
			CREATED_FILES.append(exception_png_filename)
		
		return CREATED_FILES
예제 #2
0
def test_cached_driver_manual_setup():
    config = Configuration(config_folder=os.path.dirname(__file__), file_name="wd_config.ini", section="ChromeDriver")
    version = "2.26"
    os_type = "linux"
    driver = ChromeDriver(version=version,
                          os_type=os_type)
    driver.config = config
    with pytest.raises(IOError) as ex:
        cache.get_cached_binary(driver)
    assert ex.value.args[1] == 'Is a directory'
예제 #3
0
def test_should_be_true_for_cached_driver(os_type):
    name = "chromedriver"
    version = "2.26"
    url = "http://chromedriver.storage.googleapis.com"
    driver = ChromeDriver(driver_url=url,
                          name=name,
                          version=version,
                          os_type=os_type)
    cache.download_driver(driver)
    assert cache.get_cached_binary(driver.name, driver.get_version(), os_type)
예제 #4
0
def test_should_be_false_for_new_driver():
    name = "chromedriver"
    version = "2.26"
    url = "http://chromedriver.storage.googleapis.com"
    driver = ChromeDriver(driver_url=url,
                          name=name,
                          version=version,
                          os_type="")
    cache_path = cache.get_cache_path()
    if os.path.exists(cache_path):
        shutil.rmtree(cache_path)
    assert cache.get_cached_binary(
        driver.name, driver.get_version(), os_type="win") is None
예제 #5
0
def test_can_download_chrome_driver(delete_drivers_dir, version):
    driver = ChromeDriver(
        name="chromedriver",
        version=version,
        os_type="win32",
        url="http://chromedriver.storage.googleapis.com",
        latest_release_url=
        "http://chromedriver.storage.googleapis.com/LATEST_RELEASE",
        chrome_type=ChromeType.GOOGLE)

    file = download_file(driver.get_url())
    assert file.filename == "driver.zip"
    archive = save_file(file, driver_directory)
    assert archive.unpack(driver_directory) == ["chromedriver.exe"]
예제 #6
0
def test_cache_driver_version():
    name = "chromedriver"
    version = "2.26"
    url = "http://chromedriver.storage.googleapis.com"
    os_type = "mac64"
    driver = ChromeDriver(driver_url=url,
                          name=name,
                          version=version,
                          os_type=os_type)
    cache.download_driver(driver)
    binary = cache.get_cached_binary(driver.name, driver.get_version(),
                                     os_type)
    assert binary
    assert os.path.join(cache.get_cache_path(), name, version,
                        name) == binary.path
예제 #7
0
    def __init__(
            self,
            version="latest",
            os_type=utils.os_type(),
            path=None,
            name="chromedriver",
            url="https://chromedriver.storage.googleapis.com",
            latest_release_url="https://chromedriver.storage.googleapis.com/LATEST_RELEASE",
            chrome_type=ChromeType.GOOGLE,
            logger: logging.Logger = None,
            logginglevel=logging.INFO,
            loggingfile: str = None,
            cache_valid_range=1):
        super().__init__(path,
                         logger=logger,
                         logginglevel=logginglevel,
                         loggingfile=loggingfile,
                         cache_valid_range=cache_valid_range)

        self.driver = ChromeDriver(name=name,
                                   version=version,
                                   os_type=os_type,
                                   url=url,
                                   latest_release_url=latest_release_url,
                                   chrome_type=chrome_type)
 def __init__(self, version=None, os_type=utils.os_type()):
     # type: (str, str) -> None
     super(ChromeDriverManager, self).__init__()
     # there is no driver with 64 bit
     if os_type == "win64":
         os_type = "win32"
     self.driver = ChromeDriver(version=version, os_type=os_type)
예제 #9
0
def test_can_download_chrome_driver_for_os(os_type):
    delete_cache()
    driver = ChromeDriver(version="2.26",
                          os_type=os_type)

    binary = cache.download_driver(driver)
    assert binary.name == "chromedriver"
예제 #10
0
def test_should_be_false_for_new_driver():
    version = "2.25"
    driver = ChromeDriver(version=version,
                          os_type="win")
    cache_path = cache.get_cache_path()
    if os.path.exists(cache_path):
        shutil.rmtree(cache_path)
    assert cache.get_cached_binary(driver) is None
예제 #11
0
 def __init__(self,
              version="latest",
              name="chromedriver",
              url="http://chromedriver.storage.googleapis.com",
              os_type=OSUtils.os_type()):
     DriverManager.__init__(self)
     self.driver = ChromeDriver(driver_url=url,
                                name=name,
                                version=version,
                                os_type=os_type)
예제 #12
0
def test_cache_driver_version():
    name = "chromedriver"
    version = "2.26"
    os_type = "mac64"
    driver = ChromeDriver(version=version,
                          os_type=os_type)
    cache.download_driver(driver)
    binary = cache.get_cached_binary(driver)
    assert binary
    assert os.path.join(cache.get_cache_path(), name, version, os_type, name) == binary.path
예제 #13
0
def browser():
    browser.driver = ChromeDriver(os_type="windows", version="latest")
    # login to keeptit
    LoginPage().open_url().login_as(user=BY_DEFAULT)
    # teardown method - delete all created test devices before test starts
    MainPage().delete_all_test_items_in_table()
    b = {}
    yield b
    # teardown method - delete all created test devices after test is completed
    MainPage().delete_all_test_items_in_table()
    MainPage().log_out()
예제 #14
0
def test_can_download_chrome_driver_for_os(os_type):
    delete_cache()
    name = "chromedriver"
    version = "2.26"
    url = "http://chromedriver.storage.googleapis.com"
    driver = ChromeDriver(driver_url=url,
                          name=name,
                          version=version,
                          os_type=os_type)

    binary = cache.download_driver(driver)
    assert binary.name == name
예제 #15
0
    def __init__(self, version="latest",
                 os_type=utils.os_type(),
                 path=None,
                 name="chromedriver",
                 url="http://chromedriver.storage.googleapis.com",
                 latest_release_url="http://chromedriver.storage.googleapis.com/LATEST_RELEASE"):
        super(ChromeDriverManager, self).__init__(path)

        self.driver = ChromeDriver(name=name,
                                   version=version,
                                   os_type=os_type,
                                   url=url,
                                   latest_release_url=latest_release_url)
예제 #16
0
 def __init__(self, version="latest",
              os_type=utils.os_type(),
              path=None,
              name="chromedriver",
              url="http://chromedriver.storage.googleapis.com",
              latest_release_url="http://chromedriver.storage.google"
              "apis.com/LATEST_RELEASE",
              chrome_type=ChromeType.GOOGLE,
              DEBUG_LOGGING=True):
     super(ChromeDriverManager, self).__init__(path)
     self.DEBUG_LOGGING = DEBUG_LOGGING
     self.driver = ChromeDriver(name=name,
                                version=version,
                                os_type=os_type,
                                url=url,
                                latest_release_url=latest_release_url,
                                chrome_type=chrome_type)
예제 #17
0
    def __init__(
            self,
            version="latest",
            os_type=utils.os_type(),
            path=None,
            name="chromedriver",
            url="http://chromedriver.storage.googleapis.com",
            latest_release_url="http://chromedriver.storage.googleapis.com/LATEST_RELEASE",
            chrome_type=ChromeType.GOOGLE,
            log_level=logging.INFO):
        super().__init__(path, log_level=log_level)

        self.driver = ChromeDriver(name=name,
                                   version=version,
                                   os_type=os_type,
                                   url=url,
                                   latest_release_url=latest_release_url,
                                   chrome_type=chrome_type)
예제 #18
0
    def __init__(self, version="latest",
                 os_type=utils.os_type(),
                 path=None,
                 name="chromedriver",
                 url="https://registry.npmmirror.com/-/binary/chromedriver",
                 latest_release_url="https://registry.npmmirror.com/-/binary/chromedriver/LATEST_RELEASE",
                 chrome_type=ChromeType.GOOGLE,
                 log_level=logging.INFO,
                 print_first_line=True,
                 cache_valid_range=1):
        super().__init__(path, log_level=log_level, print_first_line=print_first_line,
                         cache_valid_range=cache_valid_range)

        self.driver = ChromeDriver(name=name,
                                   version=version,
                                   os_type=os_type,
                                   url=url,
                                   latest_release_url=latest_release_url,
                                   chrome_type=chrome_type)
예제 #19
0
 def __init__(self, version=None, os_type=utils.os_type()):
     DriverManager.__init__(self)
     # there is no driver with 64 bit
     if os_type == "win64":
         os_type = "win32"
     self.driver = ChromeDriver(version=version, os_type=os_type)
예제 #20
0
def test_should_be_true_for_cached_driver(os_type):
    version = "2.10"
    driver = ChromeDriver(version=version,
                          os_type=os_type)
    cache.download_driver(driver)
    assert cache.get_cached_binary(driver)