1818 Launches SeleniumBase Commander | GUI for pytest.
1919"""
2020import colorama
21+ import os
2122import subprocess
2223import sys
2324
@@ -78,6 +79,14 @@ def do_pytest_run(
7879 save_screenshots ,
7980 additional_options ,
8081):
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
8190 total_tests = len (tests )
8291 total_selected_tests = 0
8392 for selected_test in selected_tests :
@@ -111,13 +120,25 @@ def do_pytest_run(
111120 full_run_command += " --rs"
112121 elif "(--rs --crumbs)" in rs_string :
113122 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"
114127
115128 if "(-n=2)" in thread_string :
116129 full_run_command += " -n=2"
117130 elif "(-n=3)" in thread_string :
118131 full_run_command += " -n=3"
119132 elif "(-n=4)" in thread_string :
120133 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"
121142
122143 if demo_mode :
123144 full_run_command += " --demo"
@@ -159,7 +180,7 @@ def do_pytest_run(
159180 send_window_to_front (root )
160181
161182
162- def create_tkinter_gui (tests , command_string ):
183+ def create_tkinter_gui (tests , command_string , files , solo_tests ):
163184 root = tk .Tk ()
164185 root .title ("SeleniumBase Commander | GUI for pytest" )
165186 root .minsize (820 , 658 )
@@ -179,8 +200,10 @@ def create_tkinter_gui(tests, command_string):
179200
180201 options_list = [
181202 "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)" ,
184207 ]
185208 rsx = tk .StringVar (root )
186209 rsx .set (options_list [2 ])
@@ -193,6 +216,15 @@ def create_tkinter_gui(tests, command_string):
193216 "Number of Threads: 3 (-n=3)" ,
194217 "Number of Threads: 4 (-n=4)" ,
195218 ]
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+
196228 ntx = tk .StringVar (root )
197229 ntx .set (options_list [0 ])
198230 question_menu = tk .OptionMenu (root , ntx , * options_list )
@@ -244,13 +276,17 @@ def create_tkinter_gui(tests, command_string):
244276 chk .pack ()
245277
246278 tk .Label (root , text = "" ).pack ()
279+ plural = "s"
280+ if len (files ) == 1 :
281+ plural = ""
247282 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 ) )
251286 )
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
254290 tk .Label (root , text = run_display , fg = "blue" ).pack ()
255291 text_area = ScrolledText (
256292 root , width = 100 , height = 12 , wrap = "word" , state = tk .DISABLED
@@ -403,8 +439,25 @@ def main():
403439 error_msg = c5 + "ERROR: " + error_msg + cr
404440 print (error_msg )
405441 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 )
408461
409462
410463if __name__ == "__main__" :
0 commit comments