Add option to skip JS waits, which are used in multiple methods

This commit is contained in:
Michael Mintz 2022-08-26 21:56:39 -04:00
parent 235d9bd4fe
commit 0dddaabcec
5 changed files with 39 additions and 8 deletions

View File

@ -502,6 +502,10 @@ def get_configured_sb(context):
if low_key in ["disable-beforeunload", "disable_beforeunload"]:
sb._disable_beforeunload = True
continue
# Handle: -D sjw / skip-js-waits / skip_js_waits
if low_key in ["sjw", "skip-js-waits", "skip_js_waits"]:
settings.SKIP_JS_WAITS = True
continue
# Handle: -D visual-baseline / visual_baseline
if low_key in ["visual-baseline", "visual_baseline"]:
sb.visual_baseline = True

View File

@ -60,19 +60,17 @@ If False, the browser will stay on the current tab where the click happened.
SWITCH_TO_NEW_TABS_ON_CLICK = True
"""
This adds wait_for_ready_state_complete() after various browser actions.
Setting this to True may improve reliability at the cost of speed.
These methods add global waits, such as self.wait_for_ready_state_complete(),
which waits for document.readyState to be "complete" after browser actions.
"""
# Called after self.open(url) or self.open_url(url), NOT self.driver.open(url)
# Called after self.open(URL), NOT driver.get(URL)
WAIT_FOR_RSC_ON_PAGE_LOADS = True
# Called after self.click(selector), NOT element.click()
WAIT_FOR_RSC_ON_CLICKS = False
"""
This adds wait_for_angularjs() after various browser actions.
(Requires WAIT_FOR_RSC_ON_PAGE_LOADS and WAIT_FOR_RSC_ON_CLICKS to also be on.)
"""
# Wait for AngularJS calls to complete after various browser actions.
WAIT_FOR_ANGULARJS = True
# Skip all calls to wait_for_ready_state_complete() and wait_for_angularjs().
SKIP_JS_WAITS = False
# Default time to wait after each browser action performed during Demo Mode.
# Use Demo Mode when you want others to see what your automation is doing.

View File

@ -23,6 +23,8 @@ def wait_for_ready_state_complete(driver, timeout=settings.LARGE_TIMEOUT):
because readyState == "interactive" may be good enough.
(Previously, tests would fail immediately if exceeding the timeout.)
"""
if hasattr(settings, "SKIP_JS_WAITS") and settings.SKIP_JS_WAITS:
return
if sb_config.time_limit and not sb_config.recorder_mode:
from seleniumbase.fixtures import shared_utils
@ -54,6 +56,8 @@ def execute_async_script(driver, script, timeout=settings.EXTREME_TIMEOUT):
def wait_for_angularjs(driver, timeout=settings.LARGE_TIMEOUT, **kwargs):
if hasattr(settings, "SKIP_JS_WAITS") and settings.SKIP_JS_WAITS:
return
if not settings.WAIT_FOR_ANGULARJS:
return

View File

@ -65,6 +65,7 @@ def pytest_addoption(parser):
--start-page=URL (The starting URL for the web browser when tests begin.)
--archive-logs (Archive existing log files instead of deleting them.)
--archive-downloads (Archive old downloads instead of deleting them.)
--skip-js-waits (Skip waiting for readyState to be complete or Angular.)
--time-limit=SECONDS (Safely fail any test that exceeds the time limit.)
--slow (Slow down the automation. Faster than using Demo Mode.)
--demo (Slow down and visually see test actions as they occur.)
@ -327,6 +328,17 @@ def pytest_addoption(parser):
default=False,
help="Archive old downloads instead of deleting them.",
)
parser.addoption(
"--sjw",
"--skip_js_waits",
"--skip-js-waits",
action="store_true",
dest="skip_js_waits",
default=False,
help="""Skip all calls to wait_for_ready_state_complete()
and wait_for_angularjs(), which are part of many
SeleniumBase methods for improving reliability.""",
)
parser.addoption(
"--with-db_reporting",
"--with-db-reporting",
@ -1265,6 +1277,8 @@ def pytest_configure(config):
sb_config.archive_logs = config.getoption("archive_logs")
if config.getoption("archive_downloads"):
settings.ARCHIVE_EXISTING_DOWNLOADS = True
if config.getoption("skip_js_waits"):
settings.SKIP_JS_WAITS = True
sb_config._time_limit = config.getoption("time_limit")
sb_config.time_limit = config.getoption("time_limit")
sb_config.slow_mode = config.getoption("slow_mode")

View File

@ -136,6 +136,17 @@ class SeleniumBrowser(Plugin):
help="""The Chrome User Data Directory to use. (Chrome Profile)
If the directory doesn't exist, it'll be created.""",
)
parser.add_option(
"--sjw",
"--skip_js_waits",
"--skip-js-waits",
action="store_true",
dest="skip_js_waits",
default=False,
help="""Skip all calls to wait_for_ready_state_complete()
and wait_for_angularjs(), which are part of many
SeleniumBase methods for improving reliability.""",
)
parser.add_option(
"--protocol",
action="store",