Skip to content

Commit 383602b

Browse files
committed
Update how python finds the driver and browser in tests
1 parent 84ae5a4 commit 383602b

File tree

5 files changed

+38
-18
lines changed

5 files changed

+38
-18
lines changed

py/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ BROWSER_VERSIONS = [
7272

7373
TEST_DEPS = [
7474
requirement("attrs"),
75+
requirement("bazel_runfiles"),
7576
requirement("debugpy"),
7677
requirement("filetype"),
7778
requirement("idna"),

py/conftest.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import socket
2121
import subprocess
2222
import time
23+
from runfiles import Runfiles
2324
from test.selenium.webdriver.common.network import get_lan_ip
2425
from test.selenium.webdriver.common.webserver import SimpleWebServer
2526
from urllib.request import urlopen
@@ -191,6 +192,16 @@ def get_options(driver_class, config):
191192
bidi = bool(config.option.bidi)
192193
options = None
193194

195+
# Check to see if the `browser_path` exists
196+
if browser_path:
197+
if not os.path.exists(browser_path):
198+
# Maybe it's hiding in the runfiles
199+
r = Runfiles.Create()
200+
rlocation_path = r.Rlocation(browser_path)
201+
if not os.path.exists(rlocation_path):
202+
raise Exception("Unable to find browser at " + browser_path)
203+
browser_path = rlocation_path
204+
194205
if browser_path or browser_args:
195206
if not options:
196207
options = getattr(webdriver, f"{driver_class}Options")()
@@ -226,6 +237,14 @@ def get_service(driver_class, executable):
226237
if not executable:
227238
return None
228239

240+
# Make sure the executable exists
241+
if not os.path.exists(executable):
242+
r = Runfiles.Create()
243+
rlocation_path = r.Rlocation(executable)
244+
if not os.path.exists(rlocation_path):
245+
raise Exception("Unable to find driver executable: " + executable)
246+
executable = rlocation_path
247+
229248
module = getattr(webdriver, driver_class.lower())
230249
service = module.service.Service(executable_path=executable)
231250

py/private/browsers.bzl

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,40 +15,40 @@ headless_args = select({
1515

1616
chrome_args = select({
1717
"@selenium//common:use_pinned_linux_chrome": [
18-
"--driver-binary=$(location @linux_chromedriver//:chromedriver)",
19-
"--browser-binary=$(location @linux_chrome//:chrome-linux64/chrome)",
18+
"--driver-binary=$(rlocationpath @linux_chromedriver//:chromedriver)",
19+
"--browser-binary=$(rlocationpath @linux_chrome//:chrome-linux64/chrome)",
2020
"--browser-args=--disable-dev-shm-usage",
2121
"--browser-args=--no-sandbox",
2222
],
2323
"@selenium//common:use_pinned_macos_chrome": [
24-
"--driver-binary=$(location @mac_chromedriver//:chromedriver)",
25-
"--browser-binary=$(location @mac_chrome//:Chrome.app)/Contents/MacOS/Chrome",
24+
"--driver-binary=$(rlocationpath @mac_chromedriver//:chromedriver)",
25+
"--browser-binary=$(rlocationpath @mac_chrome//:Chrome.app)/Contents/MacOS/Chrome",
2626
],
2727
"//conditions:default": [],
2828
}) + headless_args
2929

3030
edge_args = select({
3131
"@selenium//common:use_pinned_linux_edge": [
32-
"--driver-binary=$(location @linux_edgedriver//:msedgedriver)",
33-
"--browser-binary=$(location @linux_edge//:opt/microsoft/msedge/microsoft-edge)",
32+
"--driver-binary=$(rlocationpath @linux_edgedriver//:msedgedriver)",
33+
"--browser-binary=$(rlocationpath @linux_edge//:opt/microsoft/msedge/microsoft-edge)",
3434
"--browser-args=--disable-dev-shm-usage",
3535
"--browser-args=--no-sandbox",
3636
],
3737
"@selenium//common:use_pinned_macos_edge": [
38-
"--driver-binary=$(location @mac_edgedriver//:msedgedriver)",
39-
"--browser-binary='$(location @mac_edge//:Edge.app)/Contents/MacOS/Microsoft Edge'",
38+
"--driver-binary=$(rlocationpath @mac_edgedriver//:msedgedriver)",
39+
"--browser-binary='$(rlocationpath @mac_edge//:Edge.app)/Contents/MacOS/Microsoft Edge'",
4040
],
4141
"//conditions:default": [],
4242
}) + headless_args
4343

4444
firefox_args = select({
4545
"@selenium//common:use_pinned_linux_firefox": [
46-
"--driver-binary=$(location @linux_geckodriver//:geckodriver)",
47-
"--browser-binary=$(location @linux_firefox//:firefox/firefox)",
46+
"--driver-binary=$(rlocationpath @linux_geckodriver//:geckodriver)",
47+
"--browser-binary=$(rlocationpath @linux_firefox//:firefox/firefox)",
4848
],
4949
"@selenium//common:use_pinned_macos_firefox": [
50-
"--driver-binary=$(location @mac_geckodriver//:geckodriver)",
51-
"--browser-binary=$(location @mac_firefox//:Firefox.app)/Contents/MacOS/firefox",
50+
"--driver-binary=$(rlocationpath @mac_geckodriver//:geckodriver)",
51+
"--browser-binary=$(rlocationpath @mac_firefox//:Firefox.app)/Contents/MacOS/firefox",
5252
],
5353
"//conditions:default": [],
5454
}) + headless_args

py/requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
async-generator==1.10
22
attrs==23.2.0
3+
bazel_runfiles==1.2.0
34
certifi==2023.11.17
45
cffi==1.16.0
56
cryptography==42.0.8

py/requirements_lock.txt

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ attrs==23.2.0 \
1818
# -r py/requirements.txt
1919
# outcome
2020
# trio
21+
bazel-runfiles==1.2.0 \
22+
--hash=sha256:08cb0c7e43c260fa5b1a6ab88ddba79d0e6f85c365483bf26aab74713bbdb2df
23+
# via -r py/requirements.txt
2124
certifi==2023.11.17 \
2225
--hash=sha256:9b469f3a900bf28dc19b8cfbf8019bf47f7fdd1a65a1d4ffb98fc14166beb4d1 \
2326
--hash=sha256:e036ab49d5b79556f99cfc2d9320b34cfbe5be05c5871b51de9329f0603b0474
@@ -288,9 +291,7 @@ jaraco-classes==3.3.0 \
288291
jeepney==0.8.0 \
289292
--hash=sha256:5efe48d255973902f6badc3ce55e2aa6c5c3b3bc642059ef3a91247bcfcc5806 \
290293
--hash=sha256:c0a454ad016ca575060802ee4d590dd912e35c122fa04e70306de3d076cce755
291-
# via
292-
# keyring
293-
# secretstorage
294+
# via secretstorage
294295
keyring==24.3.0 \
295296
--hash=sha256:4446d35d636e6a10b8bce7caa66913dd9eca5fd222ca03a3d42c38608ac30836 \
296297
--hash=sha256:e730ecffd309658a08ee82535a3b5ec4b4c8669a9be11efb66249d8e0aeb9a25
@@ -518,9 +519,7 @@ rich==13.7.0 \
518519
secretstorage==3.3.3 \
519520
--hash=sha256:2403533ef369eca6d2ba81718576c5e0f564d5cca1b58f73a8b23e7d4eeebd77 \
520521
--hash=sha256:f356e6628222568e3af06f2eba8df495efa13b3b63081dafd4f7d9a7b7bc9f99
521-
# via
522-
# -r py/requirements.txt
523-
# keyring
522+
# via -r py/requirements.txt
524523
sniffio==1.3.1 \
525524
--hash=sha256:2f6da418d1f1e0fddd844478f41680e794e6051915791a034ff65e5f100525a2 \
526525
--hash=sha256:f4324edc670a0f49750a81b895f35c3adb843cca46f0530f79fc1babb23789dc

0 commit comments

Comments
 (0)