Skip to content

Commit 698fb0c

Browse files
committed
Update the "SB" context manager and "Driver" manager
1 parent 62b5231 commit 698fb0c

File tree

2 files changed

+67
-16
lines changed

2 files changed

+67
-16
lines changed

seleniumbase/plugins/driver_manager.py

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,14 +68,18 @@ def Driver(
6868
extension_zip=None, # Load a Chrome Extension .zip|.crx, comma-separated.)
6969
extension_dir=None, # Load a Chrome Extension directory, comma-separated.)
7070
page_load_strategy=None, # Set Chrome PLS to "normal", "eager", or "none".
71+
use_wire=None, # Use selenium-wire's webdriver over selenium webdriver.
7172
external_pdf=None, # Set Chrome "plugins.always_open_pdf_externally":True.
7273
is_mobile=None, # Use the mobile device emulator while running tests.
74+
mobile=None, # Shortcut / Duplicate of "is_mobile".
7375
d_width=None, # Set device width
7476
d_height=None, # Set device height
7577
d_p_r=None, # Set device pixel ratio
76-
uc=None, # Shortcut / Duplicate of "undetectable" to avoid confusion.
77-
undetected=None, # Duplicate of "undetectable" to avoid confusion.
78-
uc_sub=None, # Duplicate of "uc_subprocess" to avoid confusion.
78+
uc=None, # Shortcut / Duplicate of "undetectable".
79+
undetected=None, # Shortcut / Duplicate of "undetectable".
80+
uc_sub=None, # Shortcut / Duplicate of "uc_subprocess".
81+
wire=None, # Shortcut / Duplicate of "use_wire".
82+
pls=None, # Shortcut / Duplicate of "page_load_strategy".
7983
):
8084
import sys
8185
from seleniumbase.fixtures import constants
@@ -202,6 +206,8 @@ def Driver(
202206
devtools = True
203207
else:
204208
devtools = False
209+
if mobile is not None and is_mobile is None:
210+
is_mobile = mobile
205211
if is_mobile is None:
206212
if "--mobile" in sys_argv:
207213
is_mobile = True
@@ -277,6 +283,9 @@ def Driver(
277283
uc_subprocess = True
278284
else:
279285
uc_subprocess = False
286+
if undetectable and is_mobile:
287+
is_mobile = False
288+
user_agent = None
280289
if use_auto_ext is None:
281290
if "--use-auto-ext" in sys_argv:
282291
use_auto_ext = True
@@ -287,6 +296,8 @@ def Driver(
287296
disable_js = True
288297
else:
289298
disable_js = False
299+
if pls is not None and page_load_strategy is None:
300+
page_load_strategy = pls
290301
if page_load_strategy is not None:
291302
if page_load_strategy.lower() not in ["normal", "eager", "none"]:
292303
raise Exception(
@@ -309,6 +320,15 @@ def Driver(
309320
do_not_track = True
310321
else:
311322
do_not_track = False
323+
if use_wire is None and wire is None:
324+
if "--wire" in sys_argv:
325+
use_wire = True
326+
else:
327+
use_wire = False
328+
elif use_wire or wire:
329+
use_wire = True
330+
else:
331+
use_wire = False
312332
if external_pdf is None:
313333
if "--external-pdf" in sys_argv or "--external_pdf" in sys_argv:
314334
external_pdf = True
@@ -380,6 +400,7 @@ def Driver(
380400
extension_zip=extension_zip,
381401
extension_dir=extension_dir,
382402
page_load_strategy=page_load_strategy,
403+
use_wire=use_wire,
383404
external_pdf=external_pdf,
384405
test_id=test_id,
385406
mobile_emulator=is_mobile,

seleniumbase/plugins/sb_manager.py

Lines changed: 43 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@
2323
@contextmanager # Usage: -> ``with SB() as sb:``
2424
def SB(
2525
test=None, # Test Mode: Output, Logging, Continue on failure unless "rtf".
26-
raise_test_failure=None, # In "test" mode, raise Exception at 1st failure.
27-
rtf=None, # Short form of "raise_test_failure". (Less typing, same thing!)
26+
rtf=None, # Shortcut / Duplicate of "raise_test_failure".
27+
raise_test_failure=None, # If "test" mode, raise Exception on 1st failure.
2828
browser=None, # Choose from "chrome", "edge", "firefox", or "safari".
2929
headless=None, # The original headless mode for Chromium and Firefox.
3030
headless2=None, # Chromium's new headless mode. (Has more features)
@@ -59,11 +59,14 @@ def SB(
5959
firefox_arg=None, # "ARG=N,ARG2" (Set Firefox args, comma-separated.)
6060
firefox_pref=None, # SET (Set Firefox PREFERENCE:VALUE set, ","-separated)
6161
user_data_dir=None, # Set the Chrome user data directory to use.
62-
extension_zip=None, # Load a Chrome Extension .zip|.crx, comma-separated.)
63-
extension_dir=None, # Load a Chrome Extension directory, comma-separated.)
62+
extension_zip=None, # Load a Chrome Extension .zip|.crx, comma-separated.
63+
extension_dir=None, # Load a Chrome Extension directory, comma-separated.
6464
page_load_strategy=None, # Set Chrome PLS to "normal", "eager", or "none".
65+
skip_js_waits=None, # Skip JS Waits (readyState=="complete" and Angular).
66+
use_wire=None, # Use selenium-wire's webdriver over selenium webdriver.
6567
external_pdf=None, # Set Chrome "plugins.always_open_pdf_externally":True.
6668
is_mobile=None, # Use the mobile device emulator while running tests.
69+
mobile=None, # Shortcut / Duplicate of "is_mobile".
6770
device_metrics=None, # Set mobile metrics: "CSSWidth,CSSHeight,PixelRatio"
6871
xvfb=None, # Run tests using the Xvfb virtual display server on Linux OS.
6972
start_page=None, # The starting URL for the web browser when tests begin.
@@ -82,9 +85,12 @@ def SB(
8285
disable_ws=None, # Reverse of "enable_ws". (None and False are different)
8386
disable_beforeunload=None, # Disable the "beforeunload" event on Chromium.
8487
settings_file=None, # A file for overriding default SeleniumBase settings.
85-
uc=None, # Shortcut / Duplicate of "undetectable" to avoid confusion.
86-
undetected=None, # Duplicate of "undetectable" to avoid confusion.
87-
uc_sub=None, # Duplicate of "uc_subprocess" to avoid confusion.
88+
uc=None, # Shortcut / Duplicate of "undetectable".
89+
undetected=None, # Shortcut / Duplicate of "undetectable".
90+
uc_sub=None, # Shortcut / Duplicate of "uc_subprocess".
91+
wire=None, # Shortcut / Duplicate of "use_wire".
92+
pls=None, # Shortcut / Duplicate of "page_load_strategy".
93+
sjw=None, # Shortcut / Duplicate of "skip_js_waits".
8894
save_screenshot=None, # Save a screenshot at the end of each test.
8995
timeout_multiplier=None, # Multiplies the default timeout values.
9096
js_checking_on=None, # Check for JavaScript errors after page loads.
@@ -154,6 +160,7 @@ def SB(
154160
raise_test_failure
155161
or rtf
156162
or "--raise-test-failure" in sys_argv
163+
or "--raise_test_failure" in sys_argv
157164
or "--rtf" in sys_argv
158165
or "-x" in sys_argv # Carry-over from "pytest"
159166
or "--exitfirst" in sys_argv # Carry-over from "pytest"
@@ -286,6 +293,8 @@ def SB(
286293
devtools = True
287294
else:
288295
devtools = False
296+
if mobile is not None and is_mobile is None:
297+
is_mobile = mobile
289298
if is_mobile is None:
290299
if "--mobile" in sys_argv:
291300
is_mobile = True
@@ -416,6 +425,9 @@ def SB(
416425
uc_subprocess = True
417426
else:
418427
uc_subprocess = False
428+
if undetectable and is_mobile:
429+
is_mobile = False
430+
user_agent = None
419431
if use_auto_ext is None:
420432
if "--use-auto-ext" in sys_argv:
421433
use_auto_ext = True
@@ -432,6 +444,8 @@ def SB(
432444
_disable_beforeunload = False
433445
if disable_beforeunload:
434446
_disable_beforeunload = True
447+
if pls is not None and page_load_strategy is None:
448+
page_load_strategy = pls
435449
if page_load_strategy is not None:
436450
if page_load_strategy.lower() not in ["normal", "eager", "none"]:
437451
raise Exception(
@@ -444,12 +458,17 @@ def SB(
444458
page_load_strategy = "eager"
445459
elif "--pls=none" in sys_argv or '--pls="none"' in sys_argv:
446460
page_load_strategy = "none"
447-
if (
448-
"--sjw" in sys_argv
449-
or "--skip_js_waits" in sys_argv
450-
or "--skip-js-waits" in sys_argv
451-
):
452-
settings.SKIP_JS_WAITS = True
461+
if sjw is not None and skip_js_waits is None:
462+
skip_js_waits = sjw
463+
if skip_js_waits is None:
464+
if (
465+
"--sjw" in sys_argv
466+
or "--skip_js_waits" in sys_argv
467+
or "--skip-js-waits" in sys_argv
468+
):
469+
settings.SKIP_JS_WAITS = True
470+
elif skip_js_waits:
471+
settings.SKIP_JS_WAITS = skip_js_waits
453472
if save_screenshot is None:
454473
if "--screenshot" in sys_argv or "--save-screenshot" in sys_argv:
455474
save_screenshot = True
@@ -480,6 +499,15 @@ def SB(
480499
do_not_track = True
481500
else:
482501
do_not_track = False
502+
if use_wire is None and wire is None:
503+
if "--wire" in sys_argv:
504+
use_wire = True
505+
else:
506+
use_wire = False
507+
elif use_wire or wire:
508+
use_wire = True
509+
else:
510+
use_wire = False
483511
if external_pdf is None:
484512
if "--external-pdf" in sys_argv or "--external_pdf" in sys_argv:
485513
external_pdf = True
@@ -598,6 +626,7 @@ def SB(
598626
sb_config.message_duration = message_duration
599627
sb_config.block_images = block_images
600628
sb_config.do_not_track = do_not_track
629+
sb_config.use_wire = use_wire
601630
sb_config.external_pdf = external_pdf
602631
sb_config.remote_debug = remote_debug
603632
sb_config.settings_file = settings_file
@@ -691,6 +720,7 @@ def SB(
691720
sb.message_duration = sb_config.message_duration
692721
sb.block_images = sb_config.block_images
693722
sb.do_not_track = sb_config.do_not_track
723+
sb.use_wire = sb_config.use_wire
694724
sb.external_pdf = sb_config.external_pdf
695725
sb.remote_debug = sb_config.remote_debug
696726
sb.settings_file = sb_config.settings_file

0 commit comments

Comments
 (0)