Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion combo_e2e/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ class Config(BaseConfig):
# chrome driver downloader config (https://chromedriver.chromium.org/)
CHROME_DRIVER_URL = "https://chromedriver.storage.googleapis.com/"
CHROME_DRIVER_VER = "LATEST_RELEASE"
NEW_CHROME_DRIVER_VER = 115

CHROME_DRIVER_LAST_KNOWN_URL = "https://googlechromelabs.github.io/chrome-for-testing/last-known-good-versions-with-downloads.json"
CHROME_DRIVER_PLATFORM = 'linux64'
NEW_CHROME_DRIVER_URL = "https://storage.googleapis.com/chrome-for-testing-public/{version}/{platform}/"
NEW_CHROME_DRIVER_FILE_NAME = "chromedriver-{platform}.zip"
# Major versions of chrome and chrome driver must match
# If you encounter an error: This version of ChromeDriver only supports Chrome version XXX
# then you need to get correct version from https://chromedriver.chromium.org/downloads and enter below
Expand All @@ -47,7 +53,7 @@ class Config(BaseConfig):
# if empty string, then the default path in tmp is used
CHROME_DRIVER_PATH = ""
# re download driver every time tests are run
RELOAD_DRIVER = False
RELOAD_DRIVER = True
# kill driver after tests (in case of False browser won't close)
KILL_DRIVER = True
# changes selenium default load timeout
Expand Down
4 changes: 1 addition & 3 deletions combo_e2e/driver/driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,9 @@
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
from selenium.webdriver.remote import remote_connection
from selenium.webdriver.remote.command import Command
from selenium.webdriver.remote.webdriver import WebDriver
from selenium.webdriver.remote.remote_connection import LOGGER
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
from selenium.webdriver.remote.remote_connection import LOGGER
from selenium.webdriver.remote.webdriver import WebDriver

Expand Down
40 changes: 33 additions & 7 deletions combo_e2e/helpers/chromedriver_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,11 @@ class ChromeDriverLoader:
"""

driver_name: str = "chromedriver"
zip_driver_path: str = "chromedriver-{platform}"
_path_to_store: Path = None
path_to_download: Path = None
driver_path: str = None
version: str = ""

@classmethod
def download(cls, path_to_download: Path, driver_path: Path) -> None:
Expand All @@ -62,7 +64,7 @@ def download(cls, path_to_download: Path, driver_path: Path) -> None:
logger.info(" Starting download chrome driver")
version = cls._get_latest_version()
archive_path = cls._download(version)
cls.driver_path = cls._unzip(archive_path)
cls.driver_path = cls._unzip(archive_path, version=version)
logger.info(
"Prepare tests stage. Chrome driver downloaded and saved in %s",
cls.driver_path,
Expand Down Expand Up @@ -98,14 +100,31 @@ def _get(cls, url: str) -> Response:
def _get_latest_version(cls):
version = config.DEFAULT_DRIVER_VER
if not config.DEFAULT_DRIVER_VER:
res = cls._get(urljoin(config.CHROME_DRIVER_URL, config.CHROME_DRIVER_VER))
version = res.content.decode("utf-8").strip()
res = cls._get(config.CHROME_DRIVER_LAST_KNOWN_URL)
try:
versions = res.json()
version = versions.get("channels", {}).get("Stable", {}).get("version")
except Exception as e:
raise ChromeDriverLoaderException(
f"Cannot get chromedriver version. Url: {config.CHROME_DRIVER_LAST_KNOWN_URL}. "
f"Response: {res.text}"
)
return version

@classmethod
def _is_old_version(cls, version: str) -> bool:
major_version = int(version.split(".")[0])
return major_version < config.NEW_CHROME_DRIVER_VER

@classmethod
def _download(cls, version: str) -> Path:
file_relative_path = str(Path(version).joinpath(config.CHROME_DRIVER_FILE_NAME))
download_url = urljoin(config.CHROME_DRIVER_URL, file_relative_path)
if cls._is_old_version(version):
file_relative_path = str(Path(version).joinpath(config.CHROME_DRIVER_FILE_NAME))
download_url = urljoin(config.CHROME_DRIVER_URL, file_relative_path)
else:
file_name = config.NEW_CHROME_DRIVER_FILE_NAME.format(platform=config.CHROME_DRIVER_PLATFORM)
chrome_driver_url = config.NEW_CHROME_DRIVER_URL.format(version=version, platform=config.CHROME_DRIVER_PLATFORM)
download_url = urljoin(chrome_driver_url, file_name)
res = cls._get(download_url)
return cls._save_zip_to_tmp(res.content)

Expand All @@ -117,13 +136,20 @@ def _save_zip_to_tmp(cls, data: bytes) -> Path:
return path_to_write

@classmethod
def _unzip(cls, archive_path: Path) -> str:
def _unzip(cls, archive_path: Path, version: str) -> str:
archive = zipfile.ZipFile(file=archive_path)
driver_file_path = cls.make_driver_full_path()
if driver_file_path.exists():
logger.info("Remove previouse driver at: %s", driver_file_path)
driver_file_path.unlink()
archive.extract(cls.driver_name, path=str(cls._path_to_store))

if cls._is_old_version(version):
archive.extract(member=cls.driver_name, path=str(cls._path_to_store))
else:
zip_driver_file_path = f"{cls.zip_driver_path.format(platform=config.CHROME_DRIVER_PLATFORM)}/{cls.driver_name}"
with open(cls._path_to_store.joinpath(cls.driver_name), "wb") as f:
f.write(archive.read(zip_driver_file_path))

archive.close()
if not driver_file_path.exists():
raise ChromeDriverLoaderException(
Expand Down