Skip to content

Commit 69e394c

Browse files
committed
use chromedriver's new download api for chrome >= 115
1 parent f890885 commit 69e394c

2 files changed

Lines changed: 42 additions & 9 deletions

File tree

autoparaselenium/browsers/chrome.py

Lines changed: 36 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -65,14 +65,41 @@ def setup_driver(pwd: Path) -> None:
6565
chrome_version = __get_chrome_version()
6666
driver_version = __get_chromedriver_version(pwd)
6767
if driver_version is None or driver_version < chrome_version:
68-
r = requests.get(
69-
"https://chromedriver.storage.googleapis.com"
70-
f"/LATEST_RELEASE_{chrome_version}"
71-
)
72-
version = r.text.strip()
73-
if (pwd / "chromedriver").exists():
74-
os.remove(pwd / "chromedriver")
75-
__setup_driver(version)(pwd)
68+
print(driver_version, chrome_version)
69+
# chromedriver changed its LATEST_RELEASE_{version} api and download link
70+
# for chrome >= 115
71+
if chrome_version < 115:
72+
r = requests.get(
73+
"https://chromedriver.storage.googleapis.com"
74+
f"/LATEST_RELEASE_{chrome_version}"
75+
)
76+
version = r.text.strip()
77+
if (pwd / "chromedriver").exists():
78+
os.remove(pwd / "chromedriver")
79+
__setup_driver_old(version)(pwd)
80+
else:
81+
r = requests.get(
82+
"https://googlechromelabs.github.io/chrome-for-testing/"
83+
"latest-versions-per-milestone-with-downloads.json"
84+
)
85+
supported_platforms = {
86+
"linux64": "linux",
87+
"mac-x64": "darwin",
88+
"win64": "win",
89+
}
90+
downloads = {
91+
supported_platforms.get(entry["platform"]): [
92+
entry["url"],
93+
su.unzip,
94+
]
95+
for entry in (
96+
r.json()["milestones"][str(chrome_version)]
97+
["downloads"]["chromedriver"]
98+
)
99+
}
100+
if (pwd / "chromedriver").exists():
101+
os.remove(pwd / "chromedriver")
102+
su.setup_driver(downloads, __platform_drivers, pwd)
76103
os.chmod(pwd / "chromedriver", stat.S_IEXEC)
77104

78105

@@ -128,7 +155,7 @@ def __get_options(conf: Conf) -> Options:
128155
"linux": "/usr/bin/google-chrome",
129156
}
130157

131-
__setup_driver = lambda version: partial(
158+
__setup_driver_old = lambda version: partial(
132159
su.setup_driver,
133160
{
134161
"win": [

autoparaselenium/setup_utils.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,12 @@ def setup_driver(platform_install, platform_drivers, pwd: Path) -> None:
3737
if not Path(pwd / platform_drivers[platform]).exists():
3838
__download_and_extract(*platform_install[platform], pwd)
3939

40+
# sometimes webdriver is nested in a folder after zip extraction
41+
if not Path(pwd / platform_drivers[platform]).exists():
42+
(pwd / platform_drivers[platform]).hardlink_to(
43+
next(pwd.rglob(platform_drivers[platform]))
44+
)
45+
4046

4147
def __download_and_extract(url: str, extract: Callable[[str, str], None], pwd: Path) -> None:
4248
download(url, pwd / "temp")

0 commit comments

Comments
 (0)