Skip to content

Commit a7df7f7

Browse files
committed
Add option to change "timeout" for idle Selenium Grid tests
1 parent 7c931aa commit a7df7f7

File tree

5 files changed

+33
-15
lines changed

5 files changed

+33
-15
lines changed

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)