2
2
import os
3
3
import subprocess
4
4
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
5
25
6
26
7
27
def invalid_run_command ():
@@ -23,6 +43,14 @@ def invalid_run_command():
23
43
24
44
25
45
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 ("\n Warning: chromedriver not found. Installing now:" )
51
+ sb_install .main (override = "chromedriver" )
52
+ sys .argv = sys_args # Put back the original sys args
53
+
26
54
dir_path = os .path .dirname (os .path .realpath (__file__ ))
27
55
num_args = len (sys .argv )
28
56
if sys .argv [0 ].split ('/' )[- 1 ] == "seleniumbase" or (
0 commit comments