Skip to content

Commit 279f0d4

Browse files
authored
Merge pull request #387 from seleniumbase/webdriver-upgrades
Webdriver Upgrades
2 parents e003980 + a4b6dd5 commit 279f0d4

File tree

6 files changed

+109
-38
lines changed

6 files changed

+109
-38
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
[<img src="https://cdn2.hubspot.net/hubfs/100006/images/sb_logo_7.png" title="SeleniumBase" align="center" height="200">](https://github.com/seleniumbase/SeleniumBase/blob/master/README.md)
1+
[<img src="https://cdn2.hubspot.net/hubfs/100006/images/sb_logo_a.png" title="SeleniumBase" align="center" height="150">](https://github.com/seleniumbase/SeleniumBase/blob/master/README.md)
22

33
All-in-one framework for fast & simple browser automation and end-to-end testing.
44

@@ -690,4 +690,4 @@ If you see something, say something! We are very active in resolving issues. [<i
690690

691691
[https://github.com/mdmintz](https://github.com/mdmintz)<br />
692692

693-
[<img src="https://cdn2.hubspot.net/hubfs/100006/images/super_logo_3n.png" title="SeleniumBase" height="45">](https://github.com/seleniumbase/SeleniumBase/blob/master/README.md) <br /> [<img src="https://img.shields.io/badge/license-MIT-22BBCC.svg" alt=" " />](https://github.com/seleniumbase/SeleniumBase/blob/master/LICENSE)
693+
[<img src="https://cdn2.hubspot.net/hubfs/100006/images/super_logo_5e.png" title="SeleniumBase" height="45">](https://github.com/seleniumbase/SeleniumBase/blob/master/README.md) <br /> [<img src="https://img.shields.io/badge/license-MIT-22BBCC.svg" alt=" " />](https://github.com/seleniumbase/SeleniumBase/blob/master/LICENSE)

seleniumbase/console_scripts/sb_install.py

Lines changed: 26 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
iedriver|operadriver} [OPTIONS]
77
Options:
88
VERSION Specify the version.
9-
(Default Chromedriver version = 2.44)
9+
(Default chromedriver version = 2.44)
1010
Use "latest" for the latest version.
1111
-p OR --path Also copy the driver to /usr/local/bin
1212
Example:
@@ -51,7 +51,7 @@ def invalid_run_command():
5151
exp += " iedriver, operadriver)\n"
5252
exp += " Options:\n"
5353
exp += " VERSION Specify the version.\n"
54-
exp += " (Default Chromedriver version = 2.44)\n"
54+
exp += " (Default chromedriver version = 2.44)\n"
5555
exp += ' Use "latest" for the latest version.\n'
5656
exp += " -p OR --path Also copy the driver to /usr/local/bin\n"
5757
exp += " Example:\n"
@@ -79,7 +79,12 @@ def make_executable(file_path):
7979
os.chmod(file_path, mode)
8080

8181

82-
def main():
82+
def main(override=None):
83+
if override == "chromedriver":
84+
sys.argv = ["seleniumbase", "install", "chromedriver"]
85+
if override == "geckodriver":
86+
sys.argv = ["seleniumbase", "install", "geckodriver"]
87+
8388
num_args = len(sys.argv)
8489
if sys.argv[0].split('/')[-1].lower() == "seleniumbase" or (
8590
sys.argv[0].split('\\')[-1].lower() == "seleniumbase"):
@@ -123,7 +128,7 @@ def main():
123128
elif "win32" in sys_plat or "win64" in sys_plat or "x64" in sys_plat:
124129
file_name = "chromedriver_win32.zip" # Works for win32 / win_x64
125130
else:
126-
raise Exception("Cannot determine which version of Chromedriver "
131+
raise Exception("Cannot determine which version of chromedriver "
127132
"to download!")
128133
found_chromedriver = False
129134
if get_latest:
@@ -138,9 +143,9 @@ def main():
138143
if not found_chromedriver:
139144
url_request = requests.get(download_url)
140145
if found_chromedriver or url_request.ok:
141-
print("\nChromedriver version for download = %s" % use_version)
146+
print("\n* chromedriver version for download = %s" % use_version)
142147
else:
143-
raise Exception("Could not find Chromedriver to download!\n")
148+
raise Exception("Could not find chromedriver to download!\n")
144149
elif name == "geckodriver" or name == "firefoxdriver":
145150
use_version = DEFAULT_GECKODRIVER_VERSION
146151
found_geckodriver = False
@@ -174,7 +179,7 @@ def main():
174179
elif "win32" in sys_plat or "win64" in sys_plat or "x64" in sys_plat:
175180
file_name = "geckodriver-%s-win64.zip" % use_version
176181
else:
177-
raise Exception("Cannot determine which version of Geckodriver "
182+
raise Exception("Cannot determine which version of geckodriver "
178183
"(Firefox Driver) to download!")
179184
download_url = ("https://github.com/mozilla/geckodriver/"
180185
"releases/download/"
@@ -183,9 +188,9 @@ def main():
183188
if not found_geckodriver:
184189
url_request = requests.get(download_url)
185190
if found_geckodriver or url_request.ok:
186-
print("\nGeckodriver version for download = %s" % use_version)
191+
print("\n* geckodriver version for download = %s" % use_version)
187192
else:
188-
raise Exception("\nCould not find the specified Geckodriver "
193+
raise Exception("\nCould not find the specified geckodriver "
189194
"version to download!\n")
190195
elif name == "edgedriver" or name == "msedgedriver":
191196
name = "edgedriver"
@@ -314,18 +319,13 @@ def main():
314319
for f_name in contents:
315320
new_file = downloads_folder + '/' + str(f_name)
316321
print("The file [%s] was saved to:\n%s\n" % (f_name, new_file))
317-
print("Making [%s] executable ..." % f_name)
322+
print("Making [%s %s] executable ..." % (f_name, use_version))
318323
make_executable(new_file)
319-
print("[%s] is now ready for use!\n" % f_name)
320-
print('(If running on a Selenium Grid, copy [%s] to your '
321-
'System PATH.\n'
322-
' E.g. to the "/usr/local/bin/" folder on Linux '
323-
'systems.)\n' % name)
324-
print("Location of [%s %s]:\n%s" % (
325-
f_name, use_version, new_file))
324+
print("[%s] is now ready for use!" % f_name)
326325
if copy_to_path and os.path.exists(LOCAL_PATH):
327326
path_file = LOCAL_PATH + f_name
328327
shutil.copyfile(new_file, path_file)
328+
make_executable(path_file)
329329
print("Also copied to: %s" % path_file)
330330
print("")
331331
elif name == "edgedriver" or name == "msedgedriver":
@@ -367,12 +367,10 @@ def main():
367367
os.rmdir(downloads_folder + '/' + "Driver_Notes/")
368368
print("The file [%s] was saved to:\n%s\n" % (
369369
driver_file, driver_path))
370-
print("Making [%s] executable ..." % driver_file)
370+
print("Making [%s %s] executable ..." % (driver_file, use_version))
371371
make_executable(driver_path)
372-
print("[%s] is now ready for use!\n" % driver_file)
372+
print("[%s] is now ready for use!" % driver_file)
373373
print("Add folder path of Edge to System Environmental Variables!")
374-
print("\nLocation of [%s %s]:\n%s" % (
375-
driver_file, use_version, driver_path))
376374
print("")
377375
elif name == "operadriver":
378376
if len(contents) != 3:
@@ -403,14 +401,13 @@ def main():
403401
shutil.copyfile(inner_driver, driver_path)
404402
print("The file [%s] was saved to:\n%s\n" % (
405403
driver_file, driver_path))
406-
print("Making [%s] executable ..." % driver_file)
404+
print("Making [%s %s] executable ..." % (driver_file, use_version))
407405
make_executable(driver_path)
408-
print("[%s] is now ready for use!\n" % driver_file)
409-
print("Location of [%s %s]:\n%s" % (
410-
driver_file, use_version, driver_path))
406+
print("[%s] is now ready for use!" % driver_file)
411407
if copy_to_path and os.path.exists(LOCAL_PATH):
412408
path_file = LOCAL_PATH + driver_file
413409
shutil.copyfile(driver_path, path_file)
410+
make_executable(path_file)
414411
print("Also copied to: %s" % path_file)
415412
# Clean up extra files
416413
if os.path.exists(inner_driver):
@@ -444,18 +441,13 @@ def main():
444441
for f_name in contents:
445442
new_file = downloads_folder + '/' + str(f_name)
446443
print("The file [%s] was saved to:\n%s\n" % (f_name, new_file))
447-
print("Making [%s] executable ..." % f_name)
444+
print("Making [%s %s] executable ..." % (f_name, use_version))
448445
make_executable(new_file)
449-
print("[%s] is now ready for use!\n" % f_name)
450-
print('(If running on a Selenium Grid, copy [%s] to your '
451-
'System PATH.\n'
452-
' E.g. to the "/usr/local/bin/" folder on Linux '
453-
'systems.)\n' % name)
454-
print("Location of [%s %s]:\n%s" % (
455-
f_name, use_version, new_file))
446+
print("[%s] is now ready for use!" % f_name)
456447
if copy_to_path and os.path.exists(LOCAL_PATH):
457448
path_file = LOCAL_PATH + f_name
458449
shutil.copyfile(new_file, path_file)
450+
make_executable(path_file)
459451
print("Also copied to: %s" % path_file)
460452
print("")
461453
elif len(contents) == 0:
@@ -467,7 +459,7 @@ def main():
467459
if "Driver" in file_name or "driver" in file_name:
468460
print("Making [%s] executable ..." % file_name)
469461
make_executable(file_path)
470-
print("[%s] is now ready for use!\n" % file_name)
462+
print("[%s] is now ready for use!" % file_name)
471463
print("Location of [%s]:\n%s\n" % (file_name, file_path))
472464

473465

seleniumbase/core/browser_launcher.py

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,15 @@
2020
from seleniumbase import extensions # browser extensions storage folder
2121
urllib3.disable_warnings()
2222
DRIVER_DIR = os.path.dirname(os.path.realpath(drivers.__file__))
23-
if DRIVER_DIR not in os.environ["PATH"]:
23+
# Make sure that the SeleniumBase DRIVER_DIR is at the top of the System PATH
24+
# (Changes to the System PATH with os.environ only last during the test run)
25+
if not os.environ["PATH"].startswith(DRIVER_DIR):
26+
# Remove existing SeleniumBase DRIVER_DIR from System PATH if present
27+
os.environ["PATH"] = os.environ["PATH"].replace(DRIVER_DIR, "")
28+
# If two path separators are next to each other, replace with just one
29+
os.environ["PATH"] = os.environ["PATH"].replace(
30+
os.pathsep + os.pathsep, os.pathsep)
31+
# Put the SeleniumBase DRIVER_DIR at the beginning of the System PATH
2432
os.environ["PATH"] = DRIVER_DIR + os.pathsep + os.environ["PATH"]
2533
EXTENSIONS_DIR = os.path.dirname(os.path.realpath(extensions.__file__))
2634
DISABLE_CSP_ZIP_PATH = "%s/%s" % (EXTENSIONS_DIR, "disable_csp.zip")
@@ -65,6 +73,22 @@ def make_driver_executable_if_not(driver_path):
6573
make_executable(driver_path)
6674

6775

76+
def is_chromedriver_on_path():
77+
paths = os.environ["PATH"].split(os.pathsep)
78+
for path in paths:
79+
if os.path.exists(path + '/' + "chromedriver"):
80+
return True
81+
return False
82+
83+
84+
def is_geckodriver_on_path():
85+
paths = os.environ["PATH"].split(os.pathsep)
86+
for path in paths:
87+
if os.path.exists(path + '/' + "geckodriver"):
88+
return True
89+
return False
90+
91+
6892
def _add_chrome_proxy_extension(
6993
chrome_options, proxy_string, proxy_user, proxy_pass):
7094
""" Implementation of https://stackoverflow.com/a/35293284 for
@@ -466,6 +490,14 @@ def get_local_driver(
466490
options.add_argument('-headless')
467491
if LOCAL_GECKODRIVER and os.path.exists(LOCAL_GECKODRIVER):
468492
make_driver_executable_if_not(LOCAL_GECKODRIVER)
493+
elif not is_geckodriver_on_path():
494+
if not "".join(sys.argv) == "-c": # Skip if multithreaded
495+
from seleniumbase.console_scripts import sb_install
496+
sys_args = sys.argv # Save a copy of current sys args
497+
print("\nWarning: geckodriver not found."
498+
" Installing now:")
499+
sb_install.main(override="geckodriver")
500+
sys.argv = sys_args # Put back the original sys args
469501
firefox_driver = webdriver.Firefox(
470502
firefox_profile=profile,
471503
capabilities=firefox_capabilities,
@@ -532,6 +564,13 @@ def get_local_driver(
532564
extension_zip, extension_dir)
533565
if LOCAL_CHROMEDRIVER and os.path.exists(LOCAL_CHROMEDRIVER):
534566
make_driver_executable_if_not(LOCAL_CHROMEDRIVER)
567+
elif not is_chromedriver_on_path():
568+
if not "".join(sys.argv) == "-c": # Skip if multithreaded
569+
from seleniumbase.console_scripts import sb_install
570+
sys_args = sys.argv # Save a copy of current sys args
571+
print("\nWarning: chromedriver not found. Installing now:")
572+
sb_install.main(override="chromedriver")
573+
sys.argv = sys_args # Put back the original sys args
535574
return webdriver.Chrome(options=chrome_options)
536575
except Exception as e:
537576
if headless:

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 (

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545

4646
setup(
4747
name='seleniumbase',
48-
version='1.32.9',
48+
version='1.32.10',
4949
description='Fast, Easy, and Reliable Browser Automation & Testing.',
5050
long_description=long_description,
5151
long_description_content_type='text/markdown',

0 commit comments

Comments
 (0)