Make sure chromedriver is available for Selenium Grid use
This commit is contained in:
parent
30ed10b219
commit
1dc7363cc2
|
@ -2,6 +2,18 @@ import codecs
|
|||
import os
|
||||
import subprocess
|
||||
import sys
|
||||
from seleniumbase import drivers # webdriver storage folder for SeleniumBase
|
||||
DRIVER_DIR = os.path.dirname(os.path.realpath(drivers.__file__))
|
||||
# Make sure that the SeleniumBase DRIVER_DIR is at the top of the System PATH
|
||||
# (Changes to the System PATH with os.environ only last during the test run)
|
||||
if not os.environ["PATH"].startswith(DRIVER_DIR):
|
||||
# Remove existing SeleniumBase DRIVER_DIR from System PATH if present
|
||||
os.environ["PATH"] = os.environ["PATH"].replace(DRIVER_DIR, "")
|
||||
# If two path separators are next to each other, replace with just one
|
||||
os.environ["PATH"] = os.environ["PATH"].replace(
|
||||
os.pathsep + os.pathsep, os.pathsep)
|
||||
# Put the SeleniumBase DRIVER_DIR at the beginning of the System PATH
|
||||
os.environ["PATH"] = DRIVER_DIR + os.pathsep + os.environ["PATH"]
|
||||
|
||||
|
||||
def invalid_run_command():
|
||||
|
|
|
@ -2,6 +2,26 @@ import codecs
|
|||
import os
|
||||
import subprocess
|
||||
import sys
|
||||
from seleniumbase import drivers # webdriver storage folder for SeleniumBase
|
||||
DRIVER_DIR = os.path.dirname(os.path.realpath(drivers.__file__))
|
||||
# Make sure that the SeleniumBase DRIVER_DIR is at the top of the System PATH
|
||||
# (Changes to the System PATH with os.environ only last during the test run)
|
||||
if not os.environ["PATH"].startswith(DRIVER_DIR):
|
||||
# Remove existing SeleniumBase DRIVER_DIR from System PATH if present
|
||||
os.environ["PATH"] = os.environ["PATH"].replace(DRIVER_DIR, "")
|
||||
# If two path separators are next to each other, replace with just one
|
||||
os.environ["PATH"] = os.environ["PATH"].replace(
|
||||
os.pathsep + os.pathsep, os.pathsep)
|
||||
# Put the SeleniumBase DRIVER_DIR at the beginning of the System PATH
|
||||
os.environ["PATH"] = DRIVER_DIR + os.pathsep + os.environ["PATH"]
|
||||
|
||||
|
||||
def is_chromedriver_on_path():
|
||||
paths = os.environ["PATH"].split(os.pathsep)
|
||||
for path in paths:
|
||||
if os.path.exists(path + '/' + "chromedriver"):
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
def invalid_run_command():
|
||||
|
@ -23,6 +43,14 @@ def invalid_run_command():
|
|||
|
||||
|
||||
def main():
|
||||
# Install chromedriver if not installed
|
||||
if not is_chromedriver_on_path():
|
||||
from seleniumbase.console_scripts import sb_install
|
||||
sys_args = sys.argv # Save a copy of current sys args
|
||||
print("\nWarning: chromedriver not found. Installing now:")
|
||||
sb_install.main(override="chromedriver")
|
||||
sys.argv = sys_args # Put back the original sys args
|
||||
|
||||
dir_path = os.path.dirname(os.path.realpath(__file__))
|
||||
num_args = len(sys.argv)
|
||||
if sys.argv[0].split('/')[-1] == "seleniumbase" or (
|
||||
|
|
Loading…
Reference in New Issue