Skip to content

Commit cb1564d

Browse files
authored
Merge pull request #2180 from seleniumbase/refactor-gui-apps-and-uc-mode
Refactor GUI apps and UC Mode
2 parents cd66f4a + 81be9a9 commit cb1564d

File tree

6 files changed

+80
-54
lines changed

6 files changed

+80
-54
lines changed

seleniumbase/__version__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
# seleniumbase package
2-
__version__ = "4.20.0"
2+
__version__ = "4.20.1"

seleniumbase/console_scripts/sb_behave_gui.py

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def set_colors(use_colors):
3939
cr = ""
4040
if use_colors:
4141
if (
42-
"win32" in sys.platform
42+
shared_utils.is_windows()
4343
and hasattr(colorama, "just_fix_windows_console")
4444
):
4545
colorama.just_fix_windows_console()
@@ -84,7 +84,7 @@ def do_behave_run(
8484
if selected_tests[selected_test].get():
8585
total_selected_tests += 1
8686

87-
full_run_command = "%s -m behave" % sys.executable
87+
full_run_command = '"%s" -m behave' % sys.executable
8888
if total_selected_tests == 0 or total_tests == total_selected_tests:
8989
if command_string:
9090
full_run_command += " "
@@ -183,7 +183,10 @@ def do_behave_run(
183183
def create_tkinter_gui(tests, command_string, t_count, f_count, s_tests):
184184
root = tk.Tk()
185185
root.title("SeleniumBase Behave Commander | GUI for Behave")
186-
root.minsize(820, 656)
186+
if shared_utils.is_windows():
187+
root.minsize(820, 640)
188+
else:
189+
root.minsize(820, 656)
187190
tk.Label(root, text="").pack()
188191

189192
options_list = [
@@ -270,26 +273,26 @@ def create_tkinter_gui(tests, command_string, t_count, f_count, s_tests):
270273
row += " " * 200
271274
ara[count] = tk.IntVar()
272275
cb = None
273-
if not shared_utils.is_windows():
276+
if shared_utils.is_windows():
274277
cb = tk.Checkbutton(
275278
text_area,
276279
text=(row),
277-
bg="teal",
278-
fg="yellow",
280+
bg="white",
281+
fg="black",
279282
anchor="w",
280283
pady=0,
284+
borderwidth=1,
285+
highlightthickness=1,
281286
variable=ara[count],
282287
)
283288
else:
284289
cb = tk.Checkbutton(
285290
text_area,
286291
text=(row),
287-
bg="teal",
288-
fg="yellow",
292+
bg="white",
293+
fg="black",
289294
anchor="w",
290295
pady=0,
291-
borderwidth=0,
292-
highlightthickness=0,
293296
variable=ara[count],
294297
)
295298
text_area.window_create("end", window=cb)
@@ -331,7 +334,6 @@ def create_tkinter_gui(tests, command_string, t_count, f_count, s_tests):
331334
root,
332335
text="Run Selected Tests",
333336
fg="green",
334-
bg="gray",
335337
command=lambda: do_behave_run(
336338
root,
337339
tests,
@@ -396,7 +398,7 @@ def main():
396398
command_string = command_string.replace("--quiet", "")
397399
command_string = command_string.replace("-q", "")
398400
proc = subprocess.Popen(
399-
"%s -m behave -d %s --show-source"
401+
'"%s" -m behave -d %s --show-source'
400402
% (sys.executable, command_string),
401403
stdout=subprocess.PIPE,
402404
shell=True,

seleniumbase/console_scripts/sb_caseplans.py

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def set_colors(use_colors):
4343
cr = ""
4444
if use_colors:
4545
if (
46-
"win32" in sys.platform
46+
shared_utils.is_windows()
4747
and hasattr(colorama, "just_fix_windows_console")
4848
):
4949
colorama.just_fix_windows_console()
@@ -380,7 +380,10 @@ def view_summary_of_existing_case_plans(root, tests):
380380
def create_tkinter_gui(tests, command_string):
381381
root = tk.Tk()
382382
root.title("SeleniumBase Case Plans Generator")
383-
root.minsize(820, 652)
383+
if shared_utils.is_windows():
384+
root.minsize(820, 618)
385+
else:
386+
root.minsize(820, 652)
384387
tk.Label(root, text="").pack()
385388
run_display = (
386389
"Select from %s tests found: "
@@ -407,26 +410,26 @@ def create_tkinter_gui(tests, command_string):
407410
row += " " * 200
408411
ara[count] = tk.IntVar()
409412
cb = None
410-
if not shared_utils.is_windows():
413+
if shared_utils.is_windows():
411414
cb = tk.Checkbutton(
412415
text_area,
413416
text=(row),
414-
bg="green",
415-
fg="yellow",
417+
bg="white",
418+
fg="black",
416419
anchor="w",
417420
pady=0,
421+
borderwidth=1,
422+
highlightthickness=1,
418423
variable=ara[count],
419424
)
420425
else:
421426
cb = tk.Checkbutton(
422427
text_area,
423428
text=(row),
424-
bg="green",
425-
fg="yellow",
429+
bg="white",
430+
fg="black",
426431
anchor="w",
427432
pady=0,
428-
borderwidth=0,
429-
highlightthickness=0,
430433
variable=ara[count],
431434
)
432435
parts = row.strip().split("/")
@@ -501,7 +504,7 @@ def create_tkinter_gui(tests, command_string):
501504

502505
def main():
503506
use_colors = True
504-
if "linux" in sys.platform:
507+
if shared_utils.is_linux():
505508
use_colors = False
506509
c0, c1, c2, c3, c4, c5, cr = set_colors(use_colors)
507510
command_args = sys.argv[2:]
@@ -527,7 +530,7 @@ def main():
527530
print(message)
528531

529532
proc = subprocess.Popen(
530-
'%s -m pytest --collect-only -q --rootdir="./" %s'
533+
'"%s" -m pytest --collect-only -q --rootdir="./" %s'
531534
% (sys.executable, command_string),
532535
stdout=subprocess.PIPE,
533536
shell=True,
@@ -539,7 +542,11 @@ def main():
539542
print(error_msg)
540543
return
541544
tests = []
542-
for row in output.decode("utf-8").split("\n"):
545+
if shared_utils.is_windows():
546+
output = output.decode("latin1")
547+
else:
548+
output = output.decode("utf-8")
549+
for row in output.replace("\r", "").split("\n"):
543550
if ("::") in row:
544551
tests.append(row)
545552
if not tests:

seleniumbase/console_scripts/sb_commander.py

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def set_colors(use_colors):
4343
cr = ""
4444
if use_colors:
4545
if (
46-
"win32" in sys.platform
46+
shared_utils.is_windows()
4747
and hasattr(colorama, "just_fix_windows_console")
4848
):
4949
colorama.just_fix_windows_console()
@@ -96,7 +96,7 @@ def do_pytest_run(
9696
if selected_tests[selected_test].get():
9797
total_selected_tests += 1
9898

99-
full_run_command = "%s -m pytest" % sys.executable
99+
full_run_command = '"%s" -m pytest' % sys.executable
100100
if total_selected_tests == 0 or total_tests == total_selected_tests:
101101
if command_string:
102102
full_run_command += " "
@@ -186,7 +186,10 @@ def do_pytest_run(
186186
def create_tkinter_gui(tests, command_string, files, solo_tests):
187187
root = tk.Tk()
188188
root.title("SeleniumBase Commander | GUI for pytest")
189-
root.minsize(820, 658)
189+
if shared_utils.is_windows():
190+
root.minsize(820, 696)
191+
else:
192+
root.minsize(820, 702)
190193
tk.Label(root, text="").pack()
191194

192195
options_list = [
@@ -305,26 +308,26 @@ def create_tkinter_gui(tests, command_string, files, solo_tests):
305308
row += " " * 200
306309
ara[count] = tk.IntVar()
307310
cb = None
308-
if not shared_utils.is_windows():
311+
if shared_utils.is_windows():
309312
cb = tk.Checkbutton(
310313
text_area,
311314
text=(row),
312-
bg="green",
313-
fg="yellow",
315+
bg="white",
316+
fg="black",
314317
anchor="w",
315318
pady=0,
319+
borderwidth=1,
320+
highlightthickness=1,
316321
variable=ara[count],
317322
)
318323
else:
319324
cb = tk.Checkbutton(
320325
text_area,
321326
text=(row),
322-
bg="green",
323-
fg="yellow",
327+
bg="white",
328+
fg="black",
324329
anchor="w",
325330
pady=0,
326-
borderwidth=0,
327-
highlightthickness=0,
328331
variable=ara[count],
329332
)
330333
text_area.window_create("end", window=cb)
@@ -368,7 +371,6 @@ def create_tkinter_gui(tests, command_string, files, solo_tests):
368371
root,
369372
text="Run Selected Tests",
370373
fg="green",
371-
bg="gray",
372374
command=lambda: do_pytest_run(
373375
root,
374376
tests,
@@ -430,7 +432,7 @@ def main():
430432
print(message)
431433

432434
proc = subprocess.Popen(
433-
'%s -m pytest --collect-only -q --rootdir="./" %s'
435+
'"%s" -m pytest --collect-only -q --rootdir="./" %s'
434436
% (sys.executable, command_string),
435437
stdout=subprocess.PIPE,
436438
shell=True,
@@ -442,7 +444,11 @@ def main():
442444
print(error_msg)
443445
return
444446
tests = []
445-
for row in output.decode("utf-8").split("\n"):
447+
if shared_utils.is_windows():
448+
output = output.decode("latin1")
449+
else:
450+
output = output.decode("utf-8")
451+
for row in output.replace("\r", "").split("\n"):
446452
if ("::") in row:
447453
tests.append(row)
448454
if not tests:

seleniumbase/core/browser_launcher.py

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -347,13 +347,12 @@ def uc_special_open_if_cf(
347347
except Exception:
348348
pass
349349
if special:
350+
time.sleep(0.05)
350351
with driver:
351-
time.sleep(0.18)
352352
driver.execute_script('window.open("%s","_blank");' % url)
353353
driver.close()
354-
driver.switch_to.window(driver.window_handles[-1])
355-
time.sleep(0.02)
356354
if mobile_emulator:
355+
driver.switch_to.window(driver.window_handles[-1])
357356
uc_metrics = {}
358357
if (
359358
type(device_width) is int
@@ -382,7 +381,8 @@ def uc_special_open_if_cf(
382381
)
383382
except Exception:
384383
pass
385-
time.sleep(0.03)
384+
if not mobile_emulator:
385+
driver.switch_to.window(driver.window_handles[-1])
386386
else:
387387
driver.default_get(url) # The original one
388388
else:
@@ -392,23 +392,21 @@ def uc_special_open_if_cf(
392392

393393
def uc_open(driver, url):
394394
if (url.startswith("http:") or url.startswith("https:")):
395+
time.sleep(0.05)
395396
with driver:
396-
time.sleep(0.18)
397397
driver.default_get(url)
398-
time.sleep(0.02)
399398
else:
400399
driver.default_get(url) # The original one
401400
return None
402401

403402

404403
def uc_open_with_tab(driver, url):
405404
if (url.startswith("http:") or url.startswith("https:")):
405+
time.sleep(0.05)
406406
with driver:
407-
time.sleep(0.18)
408407
driver.execute_script('window.open("%s","_blank");' % url)
409408
driver.close()
410-
driver.switch_to.window(driver.window_handles[-1])
411-
time.sleep(0.02)
409+
driver.switch_to.window(driver.window_handles[-1])
412410
else:
413411
driver.default_get(url) # The original one
414412
return None
@@ -2822,25 +2820,29 @@ def get_local_driver(
28222820
)
28232821
if headless2:
28242822
try:
2825-
if use_version == "latest" or int(use_version) >= 109:
2823+
if (
2824+
use_version == "latest"
2825+
or int(str(use_version).split(".")[0]) >= 109
2826+
):
28262827
chrome_options.add_argument("--headless=new")
28272828
else:
28282829
chrome_options.add_argument("--headless=chrome")
28292830
except Exception:
28302831
chrome_options.add_argument("--headless=new")
28312832
elif headless and undetectable:
28322833
try:
2833-
if int(use_version) >= 109:
2834+
int_use_version = int(str(use_version).split(".")[0])
2835+
if int_use_version >= 109:
28342836
chrome_options.add_argument("--headless=new")
28352837
elif (
2836-
int(use_version) >= 96
2837-
and int(use_version) <= 108
2838+
int_use_version >= 96
2839+
and int_use_version <= 108
28382840
):
28392841
chrome_options.add_argument("--headless=chrome")
28402842
else:
28412843
pass # Will need Xvfb on Linux
28422844
except Exception:
2843-
pass
2845+
pass # Will need Xvfb on Linux
28442846
elif headless:
28452847
if "--headless" not in chrome_options.arguments:
28462848
chrome_options.add_argument("--headless")
@@ -3117,6 +3119,13 @@ def get_local_driver(
31173119
and int(use_version) >= 72
31183120
):
31193121
uc_chrome_version = int(use_version)
3122+
elif (
3123+
str(use_version).split(".")[0].isnumeric()
3124+
and int(str(use_version).split(".")[0]) >= 72
3125+
):
3126+
uc_chrome_version = (
3127+
int(str(use_version).split(".")[0])
3128+
)
31203129
cdp_events = uc_cdp_events
31213130
cert = "unable to get local issuer certificate"
31223131
mac_certificate_error = False
@@ -3209,7 +3218,9 @@ def get_local_driver(
32093218
and use_version
32103219
and (
32113220
int(ch_driver_version)
3212-
< int(use_version)
3221+
< int(str(
3222+
use_version).split(".")[0]
3223+
)
32133224
)
32143225
)
32153226
):

seleniumbase/undetected/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ def __init__(
217217
options.binary_location = (
218218
browser_executable_path or find_chrome_executable()
219219
)
220-
self._delay = 2
220+
self._delay = 2.05
221221
self.user_data_dir = user_data_dir
222222
self.keep_user_data_dir = keep_user_data_dir
223223
if suppress_welcome:

0 commit comments

Comments
 (0)