From 97d6b3a8ca2667645bbe5e85011ba59dbb22cd90 Mon Sep 17 00:00:00 2001 From: Michael Mintz Date: Thu, 2 May 2024 13:03:47 -0400 Subject: [PATCH] Add command-line shortcuts for SB() and Driver() --- seleniumbase/plugins/driver_manager.py | 13 +++++++++++++ seleniumbase/plugins/sb_manager.py | 18 ++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/seleniumbase/plugins/driver_manager.py b/seleniumbase/plugins/driver_manager.py index 1b4f4149..90e532d4 100644 --- a/seleniumbase/plugins/driver_manager.py +++ b/seleniumbase/plugins/driver_manager.py @@ -328,6 +328,12 @@ def Driver( ): recorder_mode = True recorder_ext = True + if headed is None: + # Override the default headless mode on Linux if set. + if "--gui" in sys_argv or "--headed" in sys_argv: + headed = True + else: + headed = False if ( shared_utils.is_linux() and not headed @@ -434,6 +440,13 @@ def Driver( disable_js = False if pls is not None and page_load_strategy is None: page_load_strategy = pls + if not page_load_strategy and "--pls=" in arg_join: + if "--pls=none" in sys_argv or '--pls="none"' in sys_argv: + page_load_strategy = "none" + elif "--pls=eager" in sys_argv or '--pls="eager"' in sys_argv: + page_load_strategy = "eager" + elif "--pls=normal" in sys_argv or '--pls="normal"' in sys_argv: + page_load_strategy = "normal" if page_load_strategy is not None: if page_load_strategy.lower() not in ["normal", "eager", "none"]: raise Exception( diff --git a/seleniumbase/plugins/sb_manager.py b/seleniumbase/plugins/sb_manager.py index 4a17601f..2fd8d913 100644 --- a/seleniumbase/plugins/sb_manager.py +++ b/seleniumbase/plugins/sb_manager.py @@ -378,9 +378,20 @@ def SB( record_sleep = True else: record_sleep = False + if xvfb is None: + if "--xvfb" in sys_argv: + xvfb = True + else: + xvfb = False if not shared_utils.is_linux(): # The Xvfb virtual display server is for Linux OS Only! xvfb = False + if headed is None: + # Override the default headless mode on Linux if set. + if "--gui" in sys_argv or "--headed" in sys_argv: + headed = True + else: + headed = False if ( shared_utils.is_linux() and not headed @@ -532,6 +543,13 @@ def SB( _disable_beforeunload = True if pls is not None and page_load_strategy is None: page_load_strategy = pls + if not page_load_strategy and "--pls=" in arg_join: + if "--pls=none" in sys_argv or '--pls="none"' in sys_argv: + page_load_strategy = "none" + elif "--pls=eager" in sys_argv or '--pls="eager"' in sys_argv: + page_load_strategy = "eager" + elif "--pls=normal" in sys_argv or '--pls="normal"' in sys_argv: + page_load_strategy = "normal" if page_load_strategy is not None: if page_load_strategy.lower() not in ["normal", "eager", "none"]: raise Exception(