Skip to content

Commit 86a6466

Browse files
authored
Merge pull request #678 from seleniumbase/grid-update-and-driver-install-update
Updates to Selenium Grid and WebDriver installation
2 parents 7c931aa + 27b9322 commit 86a6466

File tree

11 files changed

+85
-37
lines changed

11 files changed

+85
-37
lines changed
Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,22 @@
1+
examples.test_fail.MyTestClass.test_find_army_of_robots_on_xkcd_desert_island
2+
----------------------------------------------------
13
Last Page: https://xkcd.com/731/
2-
Browser: firefox
3-
Timestamp: 1540898481
4+
Browser: firefox
5+
Timestamp: 1599068455 (Unix Timestamp)
6+
Date: Wednesday, September 2, 2020
7+
Time: 1:40:55 PM (EDT, UTC-05:00)
8+
----------------------------------------------------
49
Traceback: File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/unittest/case.py", line 615, in run
510
testMethod()
6-
File "/Users/michael/github/SeleniumBase/examples/test_fail.py", line 12, in test_find_army_of_robots_on_xkcd_desert_island
11+
File "/Users/michael/github/SeleniumBase/examples/test_fail.py", line 17, in test_find_army_of_robots_on_xkcd_desert_island
712
self.assert_element("div#ARMY_OF_ROBOTS", timeout=1)
8-
File "/Users/michael/github/SeleniumBase/seleniumbase/fixtures/base_case.py", line 2166, in assert_element
13+
File "/Users/michael/github/SeleniumBase/seleniumbase/fixtures/base_case.py", line 4931, in assert_element
914
self.wait_for_element_visible(selector, by=by, timeout=timeout)
10-
File "/Users/michael/github/SeleniumBase/seleniumbase/fixtures/base_case.py", line 2143, in wait_for_element_visible
15+
File "/Users/michael/github/SeleniumBase/seleniumbase/fixtures/base_case.py", line 3290, in wait_for_element_visible
1116
self.driver, selector, by, timeout)
12-
File "/Users/michael/github/SeleniumBase/seleniumbase/fixtures/page_actions.py", line 239, in wait_for_element_visible
13-
selector, timeout, plural))
14-
Exception: Element {div#ARMY_OF_ROBOTS} was not visible after 1 second!
17+
File "/Users/michael/github/SeleniumBase/seleniumbase/fixtures/page_actions.py", line 299, in wait_for_element_visible
18+
timeout_exception(NoSuchElementException, message)
19+
File "/Users/michael/github/SeleniumBase/seleniumbase/fixtures/page_actions.py", line 117, in timeout_exception
20+
raise exc(message)
21+
Exception: Message:
22+
Element {div#ARMY_OF_ROBOTS} was not present after 1 second!

requirements.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
pip>=20.2.2
22
packaging>=20.4
33
setuptools>=44.1.1;python_version<"3.5"
4-
setuptools>=50.0.0;python_version>="3.5"
4+
setuptools>=50.0.3;python_version>="3.5"
55
setuptools-scm>=4.1.2
66
wheel>=0.35.1
77
six==1.15.0
@@ -44,7 +44,7 @@ pyopenssl==19.1.0
4444
pygments==2.5.2;python_version<"3.5"
4545
pygments==2.6.1;python_version>="3.5"
4646
traitlets==4.3.3;python_version<"3.7"
47-
traitlets==5.0.0;python_version>="3.7"
47+
traitlets==5.0.2;python_version>="3.7"
4848
prompt-toolkit==1.0.18;python_version<"3.6"
4949
prompt-toolkit==3.0.7;python_version>="3.6"
5050
ipython==5.10.0;python_version<"3.5"

seleniumbase/console_scripts/run.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -382,11 +382,14 @@ def show_grid_hub_usage():
382382
print(sc)
383383
print("")
384384
print(" Usage:")
385-
print(" seleniumbase grid-hub {start|stop}")
386-
print(" OR: sbase grid-hub {start|stop}")
385+
print(" seleniumbase grid-hub {start|stop|restart} [OPTIONS]")
386+
print(" OR: sbase grid-hub {start|stop|restart} [OPTIONS]")
387387
print(" Options:")
388388
print(" -v, --verbose (Increase verbosity of logging output.)")
389389
print(" (Default: Quiet logging / not verbose.)")
390+
print(" --timeout=TIMEOUT (Close idle browser after TIMEOUT.)")
391+
print(" (The default TIMEOUT: 230 seconds.)")
392+
print(" (Use --timeout=0 to skip timeouts.)")
390393
print(" Example:")
391394
print(" seleniumbase grid-hub start")
392395
print(" Output:")
@@ -406,8 +409,8 @@ def show_grid_node_usage():
406409
print(sc)
407410
print("")
408411
print(" Usage:")
409-
print(" seleniumbase grid-node {start|stop} [OPTIONS]")
410-
print(" OR: sbase grid-node {start|stop} [OPTIONS]")
412+
print(" seleniumbase grid-node {start|stop|restart} [OPTIONS]")
413+
print(" OR: sbase grid-node {start|stop|restart} [OPTIONS]")
411414
print(" Options:")
412415
print(" --hub=[HUB_IP] (The Grid Hub IP Address to connect to.)")
413416
print(" (Default: 127.0.0.1 if not set)")

seleniumbase/console_scripts/sb_install.py

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@
4141
urllib3.disable_warnings()
4242
DRIVER_DIR = os.path.dirname(os.path.realpath(drivers.__file__))
4343
LOCAL_PATH = "/usr/local/bin/" # On Mac and Linux systems
44-
DEFAULT_CHROMEDRIVER_VERSION = "2.44"
44+
DEFAULT_CHROMEDRIVER_VERSION = "2.44" # (Specify "latest" to get the latest)
4545
DEFAULT_GECKODRIVER_VERSION = "v0.27.0"
46-
DEFAULT_EDGEDRIVER_VERSION = "85.0.564.44"
46+
DEFAULT_EDGEDRIVER_VERSION = "85.0.564.44" # (Looks for LATEST_STABLE first)
4747
DEFAULT_OPERADRIVER_VERSION = "v.84.0.4147.89"
4848

4949

@@ -194,8 +194,6 @@ def main(override=None):
194194
print('# %s: >>> %s' % (run_this, install_sb))
195195
elif name == "geckodriver" or name == "firefoxdriver":
196196
use_version = DEFAULT_GECKODRIVER_VERSION
197-
if "win32" in sys_plat or "win64" in sys_plat or "x64" in sys_plat:
198-
use_version = "v0.24.0"
199197
found_geckodriver = False
200198
if num_args == 4 or num_args == 5:
201199
if "-p" not in sys.argv[3].lower():
@@ -244,19 +242,33 @@ def main(override=None):
244242
"version to download!\n")
245243
elif name == "edgedriver" or name == "msedgedriver":
246244
name = "edgedriver"
247-
use_version = DEFAULT_EDGEDRIVER_VERSION
245+
last = (
246+
"https://msedgewebdriverstorage.blob.core.windows.net"
247+
"/edgewebdriver/LATEST_STABLE")
248+
get_latest = False
249+
if num_args == 3:
250+
get_latest = True
251+
if num_args == 4 and "-p" in sys.argv[3].lower():
252+
get_latest = True
248253
if num_args == 4 or num_args == 5:
249254
if "-p" not in sys.argv[3].lower():
250255
use_version = sys.argv[3]
251256
if use_version.lower() == "latest":
252257
use_version = DEFAULT_EDGEDRIVER_VERSION
258+
get_latest = True
253259
else:
254260
copy_to_path = True
255261
if num_args == 5:
256262
if "-p" in sys.argv[4].lower():
257263
copy_to_path = True
258264
else:
259265
invalid_run_command()
266+
if get_latest:
267+
url_request = requests.get(last)
268+
if url_request.ok:
269+
use_version = url_request.text.split('\r')[0].split('\n')[0]
270+
else:
271+
use_version = DEFAULT_EDGEDRIVER_VERSION
260272
if "win64" in sys_plat or "x64" in sys_plat:
261273
file_name = "edgedriver_win64.zip"
262274
elif "win32" in sys_plat or "x86" in sys_plat:
@@ -268,6 +280,11 @@ def main(override=None):
268280
"only for Windows or Mac operating systems!")
269281
download_url = ("https://msedgedriver.azureedge.net/"
270282
"%s/%s" % (use_version, file_name))
283+
if not get_latest and not use_version == DEFAULT_EDGEDRIVER_VERSION:
284+
url_request = requests.get(download_url)
285+
if not url_request.ok:
286+
raise Exception(
287+
"Could not find version [%s] of EdgeDriver!" % use_version)
271288
msg = c2 + "edgedriver version for download" + cr
272289
p_version = c3 + use_version + cr
273290
print("\n*** %s = %s" % (msg, p_version))

seleniumbase/core/browser_launcher.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,8 @@ def _set_chrome_options(
242242
chrome_options.add_argument("--dom-automation")
243243
chrome_options.add_argument("--disable-hang-monitor")
244244
chrome_options.add_argument("--disable-prompt-on-repost")
245+
if servername != "localhost":
246+
use_auto_ext = True # Use Automation Extension with the Selenium Grid
245247
if not use_auto_ext: # (It's ON by default. Disable it when not wanted.)
246248
chrome_options.add_experimental_option("useAutomationExtension", False)
247249
if (settings.DISABLE_CSP_ON_CHROME or disable_csp) and not headless:

seleniumbase/utilities/selenium_grid/ReadMe.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,18 @@ seleniumbase download server
1818
<h4><img src="https://seleniumbase.io/img/sb_icon.png" title="SeleniumBase" width="30" /> Grid Hub server controls:</h4>
1919

2020
```bash
21-
seleniumbase grid-hub {start|stop} [OPTIONS]
21+
seleniumbase grid-hub {start|stop|restart} [OPTIONS]
2222
```
2323
<b>Options:</b>
2424
<ul>
2525
<li> -v / --verbose (Increases verbosity of logging output.)</li>
26+
<li> --timeout=TIMEOUT (Close idle browser after TIMEOUT sec.)</li>
2627
</ul>
2728

2829
<h4><img src="https://seleniumbase.io/img/sb_icon.png" title="SeleniumBase" width="30" /> Grid node server controls:</h4>
2930

3031
```bash
31-
seleniumbase grid-node {start|stop} --hub=[HUB_IP] [OPTIONS]
32+
seleniumbase grid-node {start|stop|restart} --hub=[HUB_IP] [OPTIONS]
3233
```
3334
<b>Options:</b>
3435
<ul>

seleniumbase/utilities/selenium_grid/grid-hub

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
#!/usr/bin/env bash
22

33
#
4-
# Usage: grid-hub {start|stop|restart}
4+
# Usage: grid-hub {start|stop} [TIMEOUT]
55
#
66

77
source $(dirname $0)/font_color
88

9-
EXPECTED_ARGS=1
9+
EXPECTED_ARGS=2
1010
E_BADARGS=65
1111

1212
DO_showUsage() {
13-
echo "Usage: $(basename $0) {start|stop|restart}"
13+
echo "Usage: $(basename $0) {start|stop} [TIMEOUT]"
1414
exit $E_BADARGS
1515
}
1616

@@ -34,7 +34,7 @@ if [ "$GRID_HUB_VERBOSE_LOGS" == "True" ]; then
3434
fi
3535

3636
WEBDRIVER_SERVER_JAR=${DIR}/selenium-server-standalone.jar
37-
WEBDRIVER_HUB_PARAMS="-role hub -timeout 230 -browserTimeout 170 -port 4444"
37+
WEBDRIVER_HUB_PARAMS="-role hub -timeout $2 -browserTimeout 170 -port 4444"
3838
WEBDRIVER_HUB_PIDFILE="/tmp/webdriver_hub.pid"
3939

4040
if [ ! -f $WEBDRIVER_SERVER_JAR ]; then

seleniumbase/utilities/selenium_grid/grid-node

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env bash
22

33
#
4-
# Usage: grid-node {start|stop|restart}
4+
# Usage: grid-node {start|stop}
55
#
66

77
source $(dirname $0)/font_color
@@ -10,7 +10,7 @@ EXPECTED_ARGS=1
1010
E_BADARGS=65
1111

1212
DO_showUsage() {
13-
echo "Usage: $(basename $0) {start|stop|restart}"
13+
echo "Usage: $(basename $0) {start|stop}"
1414
exit $E_BADARGS
1515
}
1616

seleniumbase/utilities/selenium_grid/grid_hub.py

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,16 @@
1616
os.environ["PATH"] = DRIVER_DIR + os.pathsep + os.environ["PATH"]
1717

1818

19-
def invalid_run_command():
19+
def invalid_run_command(msg=None):
2020
exp = (" ** grid-hub **\n\n")
2121
exp += " Usage:\n"
22-
exp += " seleniumbase grid-hub {start|stop|restart}\n"
22+
exp += " seleniumbase grid-hub {start|stop|restart} [OPTIONS]\n"
2323
exp += " Options:\n"
2424
exp += " -v, --verbose (Increase verbosity of logging output.)\n"
2525
exp += " (Default: Quiet logging / not verbose.)\n"
26+
exp += " --timeout=TIMEOUT (Close idle browser after TIMEOUT.)\n"
27+
exp += " (The default TIMEOUT: 230 seconds.)\n"
28+
exp += " (Use --timeout=0 to skip timeouts.)\n"
2629
exp += " Example:\n"
2730
exp += " seleniumbase grid-hub start\n"
2831
exp += " Output:\n"
@@ -31,10 +34,13 @@ def invalid_run_command():
3134
exp += " to speed up test runs and reduce the total time\n"
3235
exp += " of test suite execution.\n"
3336
exp += " You can start, restart, or stop the Grid Hub Server.\n"
37+
if msg:
38+
exp += msg
3439
raise Exception('INVALID RUN COMMAND!\n\n%s' % exp)
3540

3641

3742
def main():
43+
timeout = 230 # The default number of seconds that a test can be idle
3844
dir_path = os.path.dirname(os.path.realpath(__file__))
3945
num_args = len(sys.argv)
4046
if sys.argv[0].split('/')[-1] == "seleniumbase" or (
@@ -55,6 +61,12 @@ def main():
5561
for option in options:
5662
if option == '-v' or option == '--verbose':
5763
verbose = "True"
64+
elif option.startswith("--timeout=") and len(option) > 10:
65+
timeout = option.split("--timeout=")[1]
66+
if not timeout.isdigit():
67+
msg = '\n"timeout" must be a non-negative integer!\n'
68+
print(msg)
69+
invalid_run_command(msg)
5870
else:
5971
invalid_run_command()
6072

@@ -70,18 +82,22 @@ def main():
7082

7183
if "linux" in sys.platform or "darwin" in sys.platform:
7284
if grid_hub_command == "start":
73-
subprocess.check_call(dir_path + "/grid-hub start", shell=True)
85+
subprocess.check_call(
86+
dir_path + "/grid-hub start %s" % timeout, shell=True)
7487
elif grid_hub_command == "restart":
75-
subprocess.check_call(dir_path + "/grid-hub restart", shell=True)
88+
subprocess.check_call(dir_path + "/grid-hub stop .", shell=True)
89+
subprocess.check_call(
90+
dir_path + "/grid-hub start %s" % timeout, shell=True)
7691
elif grid_hub_command == "stop":
77-
subprocess.check_call(dir_path + "/grid-hub stop", shell=True)
92+
subprocess.check_call(dir_path + "/grid-hub stop .", shell=True)
7893
else:
7994
invalid_run_command()
8095
else:
8196
if grid_hub_command == "start" or grid_hub_command == "restart":
8297
shell_command = (
8398
"""java -jar %s/selenium-server-standalone.jar -role hub """
84-
"""-timeout 230 -browserTimeout 170 -port 4444""" % dir_path)
99+
"""-timeout %s -browserTimeout 170 -port 4444"""
100+
"" % (dir_path, timeout))
85101
print("\nStarting Selenium-WebDriver Grid Hub...\n")
86102
print(shell_command)
87103
print("")

seleniumbase/utilities/selenium_grid/grid_node.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,8 @@ def main():
9999
if grid_hub_command == "start":
100100
subprocess.check_call(dir_path + "/grid-node start", shell=True)
101101
elif grid_hub_command == "restart":
102-
subprocess.check_call(dir_path + "/grid-node restart", shell=True)
102+
subprocess.check_call(dir_path + "/grid-node stop", shell=True)
103+
subprocess.check_call(dir_path + "/grid-node start", shell=True)
103104
elif grid_hub_command == "stop":
104105
subprocess.check_call(dir_path + "/grid-node stop", shell=True)
105106
else:

0 commit comments

Comments
 (0)