Skip to content

Commit 1dc7363

Browse files
committed
Make sure chromedriver is available for Selenium Grid use
1 parent 30ed10b commit 1dc7363

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

seleniumbase/utilities/selenium_grid/grid_hub.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,18 @@
22
import os
33
import subprocess
44
import sys
5+
from seleniumbase import drivers # webdriver storage folder for SeleniumBase
6+
DRIVER_DIR = os.path.dirname(os.path.realpath(drivers.__file__))
7+
# Make sure that the SeleniumBase DRIVER_DIR is at the top of the System PATH
8+
# (Changes to the System PATH with os.environ only last during the test run)
9+
if not os.environ["PATH"].startswith(DRIVER_DIR):
10+
# Remove existing SeleniumBase DRIVER_DIR from System PATH if present
11+
os.environ["PATH"] = os.environ["PATH"].replace(DRIVER_DIR, "")
12+
# If two path separators are next to each other, replace with just one
13+
os.environ["PATH"] = os.environ["PATH"].replace(
14+
os.pathsep + os.pathsep, os.pathsep)
15+
# Put the SeleniumBase DRIVER_DIR at the beginning of the System PATH
16+
os.environ["PATH"] = DRIVER_DIR + os.pathsep + os.environ["PATH"]
517

618

719
def invalid_run_command():

seleniumbase/utilities/selenium_grid/grid_node.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,26 @@
22
import os
33
import subprocess
44
import sys
5+
from seleniumbase import drivers # webdriver storage folder for SeleniumBase
6+
DRIVER_DIR = os.path.dirname(os.path.realpath(drivers.__file__))
7+
# Make sure that the SeleniumBase DRIVER_DIR is at the top of the System PATH
8+
# (Changes to the System PATH with os.environ only last during the test run)
9+
if not os.environ["PATH"].startswith(DRIVER_DIR):
10+
# Remove existing SeleniumBase DRIVER_DIR from System PATH if present
11+
os.environ["PATH"] = os.environ["PATH"].replace(DRIVER_DIR, "")
12+
# If two path separators are next to each other, replace with just one
13+
os.environ["PATH"] = os.environ["PATH"].replace(
14+
os.pathsep + os.pathsep, os.pathsep)
15+
# Put the SeleniumBase DRIVER_DIR at the beginning of the System PATH
16+
os.environ["PATH"] = DRIVER_DIR + os.pathsep + os.environ["PATH"]
17+
18+
19+
def is_chromedriver_on_path():
20+
paths = os.environ["PATH"].split(os.pathsep)
21+
for path in paths:
22+
if os.path.exists(path + '/' + "chromedriver"):
23+
return True
24+
return False
525

626

727
def invalid_run_command():
@@ -23,6 +43,14 @@ def invalid_run_command():
2343

2444

2545
def main():
46+
# Install chromedriver if not installed
47+
if not is_chromedriver_on_path():
48+
from seleniumbase.console_scripts import sb_install
49+
sys_args = sys.argv # Save a copy of current sys args
50+
print("\nWarning: chromedriver not found. Installing now:")
51+
sb_install.main(override="chromedriver")
52+
sys.argv = sys_args # Put back the original sys args
53+
2654
dir_path = os.path.dirname(os.path.realpath(__file__))
2755
num_args = len(sys.argv)
2856
if sys.argv[0].split('/')[-1] == "seleniumbase" or (

0 commit comments

Comments
 (0)