18
18
Launches SeleniumBase Commander | GUI for pytest.
19
19
"""
20
20
import colorama
21
+ import os
21
22
import subprocess
22
23
import sys
23
24
@@ -78,6 +79,14 @@ def do_pytest_run(
78
79
save_screenshots ,
79
80
additional_options ,
80
81
):
82
+ cleaned_tests = []
83
+ for test in tests :
84
+ if test .startswith ("(FILE) " ):
85
+ clean_test = test .split ("(FILE) " )[1 ].split (" => " )[0 ]
86
+ cleaned_tests .append (clean_test )
87
+ else :
88
+ cleaned_tests .append (test )
89
+ tests = cleaned_tests
81
90
total_tests = len (tests )
82
91
total_selected_tests = 0
83
92
for selected_test in selected_tests :
@@ -111,13 +120,25 @@ def do_pytest_run(
111
120
full_run_command += " --rs"
112
121
elif "(--rs --crumbs)" in rs_string :
113
122
full_run_command += " --rs --crumbs"
123
+ elif "(--rcs)" in rs_string :
124
+ full_run_command += " --rcs"
125
+ elif "(--rcs --crumbs)" in rs_string :
126
+ full_run_command += " --rcs --crumbs"
114
127
115
128
if "(-n=2)" in thread_string :
116
129
full_run_command += " -n=2"
117
130
elif "(-n=3)" in thread_string :
118
131
full_run_command += " -n=3"
119
132
elif "(-n=4)" in thread_string :
120
133
full_run_command += " -n=4"
134
+ elif "(-n=5)" in thread_string :
135
+ full_run_command += " -n=5"
136
+ elif "(-n=6)" in thread_string :
137
+ full_run_command += " -n=6"
138
+ elif "(-n=7)" in thread_string :
139
+ full_run_command += " -n=7"
140
+ elif "(-n=8)" in thread_string :
141
+ full_run_command += " -n=8"
121
142
122
143
if demo_mode :
123
144
full_run_command += " --demo"
@@ -159,7 +180,7 @@ def do_pytest_run(
159
180
send_window_to_front (root )
160
181
161
182
162
- def create_tkinter_gui (tests , command_string ):
183
+ def create_tkinter_gui (tests , command_string , files , solo_tests ):
163
184
root = tk .Tk ()
164
185
root .title ("SeleniumBase Commander | GUI for pytest" )
165
186
root .minsize (820 , 658 )
@@ -179,8 +200,10 @@ def create_tkinter_gui(tests, command_string):
179
200
180
201
options_list = [
181
202
"New Session Per Test (Default)" ,
182
- "Reuse Session for all tests in thread (--rs)" ,
183
- "Reuse Session / clear cookies (--rs --crumbs)" ,
203
+ "Reuse Session for ALL tests in thread (--rs)" ,
204
+ "Reuse Session and also clear cookies (--rs --crumbs)" ,
205
+ "Reuse Session for tests with same CLASS (--rcs)" ,
206
+ "Reuse Session for class and clear cookies (--rcs --crumbs)" ,
184
207
]
185
208
rsx = tk .StringVar (root )
186
209
rsx .set (options_list [2 ])
@@ -193,6 +216,15 @@ def create_tkinter_gui(tests, command_string):
193
216
"Number of Threads: 3 (-n=3)" ,
194
217
"Number of Threads: 4 (-n=4)" ,
195
218
]
219
+ try :
220
+ if int (os .cpu_count ()) >= 8 :
221
+ options_list .append ("Number of Threads: 5 (-n=5)" )
222
+ options_list .append ("Number of Threads: 6 (-n=6)" )
223
+ options_list .append ("Number of Threads: 7 (-n=7)" )
224
+ options_list .append ("Number of Threads: 8 (-n=8)" )
225
+ except Exception :
226
+ pass
227
+
196
228
ntx = tk .StringVar (root )
197
229
ntx .set (options_list [0 ])
198
230
question_menu = tk .OptionMenu (root , ntx , * options_list )
@@ -244,13 +276,17 @@ def create_tkinter_gui(tests, command_string):
244
276
chk .pack ()
245
277
246
278
tk .Label (root , text = "" ).pack ()
279
+ plural = "s"
280
+ if len (files ) == 1 :
281
+ plural = ""
247
282
run_display = (
248
- "Select from %s tests: "
249
- "(If NO TESTS are selected, then ALL TESTS will run )"
250
- % len (tests )
283
+ "Select from %s rows (%s file%s with %s tests) : "
284
+ "(All tests will run if none are selected )"
285
+ % ( len (tests ), len ( files ), plural , len ( solo_tests ) )
251
286
)
252
- if len (tests ) == 1 :
253
- run_display = "Only ONE TEST was found: (Will run automatically)"
287
+ if len (solo_tests ) == 1 :
288
+ run_display = "Only ONE TEST was found and will be run:"
289
+ tests = solo_tests
254
290
tk .Label (root , text = run_display , fg = "blue" ).pack ()
255
291
text_area = ScrolledText (
256
292
root , width = 100 , height = 12 , wrap = "word" , state = tk .DISABLED
@@ -403,8 +439,25 @@ def main():
403
439
error_msg = c5 + "ERROR: " + error_msg + cr
404
440
print (error_msg )
405
441
return
406
-
407
- create_tkinter_gui (tests , command_string )
442
+ groups = []
443
+ for row in tests :
444
+ if row .count ("::" ) >= 1 :
445
+ g_name = "(FILE) %s" % row .split ("::" )[0 ]
446
+ groups .append (g_name )
447
+ files = []
448
+ used_files = []
449
+ for row in groups :
450
+ if row not in used_files :
451
+ used_files .append (row )
452
+ plural = "s"
453
+ if groups .count (row ) == 1 :
454
+ plural = ""
455
+ f_row = "%s => (%s Test%s)" % (row , groups .count (row ), plural )
456
+ files .append (f_row )
457
+ solo_tests = tests
458
+ tests = [* files , * tests ]
459
+
460
+ create_tkinter_gui (tests , command_string , files , solo_tests )
408
461
409
462
410
463
if __name__ == "__main__" :
0 commit comments