16
16
os .environ ["PATH" ] = DRIVER_DIR + os .pathsep + os .environ ["PATH" ]
17
17
18
18
19
- def invalid_run_command ():
19
+ def invalid_run_command (msg = None ):
20
20
exp = (" ** grid-hub **\n \n " )
21
21
exp += " Usage:\n "
22
- exp += " seleniumbase grid-hub {start|stop|restart}\n "
22
+ exp += " seleniumbase grid-hub {start|stop|restart} [OPTIONS] \n "
23
23
exp += " Options:\n "
24
24
exp += " -v, --verbose (Increase verbosity of logging output.)\n "
25
25
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 "
26
29
exp += " Example:\n "
27
30
exp += " seleniumbase grid-hub start\n "
28
31
exp += " Output:\n "
@@ -31,10 +34,13 @@ def invalid_run_command():
31
34
exp += " to speed up test runs and reduce the total time\n "
32
35
exp += " of test suite execution.\n "
33
36
exp += " You can start, restart, or stop the Grid Hub Server.\n "
37
+ if msg :
38
+ exp += msg
34
39
raise Exception ('INVALID RUN COMMAND!\n \n %s' % exp )
35
40
36
41
37
42
def main ():
43
+ timeout = 230 # The default number of seconds that a test can be idle
38
44
dir_path = os .path .dirname (os .path .realpath (__file__ ))
39
45
num_args = len (sys .argv )
40
46
if sys .argv [0 ].split ('/' )[- 1 ] == "seleniumbase" or (
@@ -55,6 +61,12 @@ def main():
55
61
for option in options :
56
62
if option == '-v' or option == '--verbose' :
57
63
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 )
58
70
else :
59
71
invalid_run_command ()
60
72
@@ -70,18 +82,22 @@ def main():
70
82
71
83
if "linux" in sys .platform or "darwin" in sys .platform :
72
84
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 )
74
87
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 )
76
91
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 )
78
93
else :
79
94
invalid_run_command ()
80
95
else :
81
96
if grid_hub_command == "start" or grid_hub_command == "restart" :
82
97
shell_command = (
83
98
"""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 ))
85
101
print ("\n Starting Selenium-WebDriver Grid Hub...\n " )
86
102
print (shell_command )
87
103
print ("" )
0 commit comments