Skip to content

Commit 0dddaab

Browse files
committed
Add option to skip JS waits, which are used in multiple methods
1 parent 235d9bd commit 0dddaab

File tree

5 files changed

+39
-8
lines changed

5 files changed

+39
-8
lines changed

seleniumbase/behave/behave_sb.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -502,6 +502,10 @@ def get_configured_sb(context):
502502
if low_key in ["disable-beforeunload", "disable_beforeunload"]:
503503
sb._disable_beforeunload = True
504504
continue
505+
# Handle: -D sjw / skip-js-waits / skip_js_waits
506+
if low_key in ["sjw", "skip-js-waits", "skip_js_waits"]:
507+
settings.SKIP_JS_WAITS = True
508+
continue
505509
# Handle: -D visual-baseline / visual_baseline
506510
if low_key in ["visual-baseline", "visual_baseline"]:
507511
sb.visual_baseline = True

seleniumbase/config/settings.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -60,19 +60,17 @@
6060
SWITCH_TO_NEW_TABS_ON_CLICK = True
6161

6262
"""
63-
This adds wait_for_ready_state_complete() after various browser actions.
64-
Setting this to True may improve reliability at the cost of speed.
63+
These methods add global waits, such as self.wait_for_ready_state_complete(),
64+
which waits for document.readyState to be "complete" after browser actions.
6565
"""
66-
# Called after self.open(url) or self.open_url(url), NOT self.driver.open(url)
66+
# Called after self.open(URL), NOT driver.get(URL)
6767
WAIT_FOR_RSC_ON_PAGE_LOADS = True
6868
# Called after self.click(selector), NOT element.click()
6969
WAIT_FOR_RSC_ON_CLICKS = False
70-
71-
"""
72-
This adds wait_for_angularjs() after various browser actions.
73-
(Requires WAIT_FOR_RSC_ON_PAGE_LOADS and WAIT_FOR_RSC_ON_CLICKS to also be on.)
74-
"""
70+
# Wait for AngularJS calls to complete after various browser actions.
7571
WAIT_FOR_ANGULARJS = True
72+
# Skip all calls to wait_for_ready_state_complete() and wait_for_angularjs().
73+
SKIP_JS_WAITS = False
7674

7775
# Default time to wait after each browser action performed during Demo Mode.
7876
# Use Demo Mode when you want others to see what your automation is doing.

seleniumbase/fixtures/js_utils.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ def wait_for_ready_state_complete(driver, timeout=settings.LARGE_TIMEOUT):
2323
because readyState == "interactive" may be good enough.
2424
(Previously, tests would fail immediately if exceeding the timeout.)
2525
"""
26+
if hasattr(settings, "SKIP_JS_WAITS") and settings.SKIP_JS_WAITS:
27+
return
2628
if sb_config.time_limit and not sb_config.recorder_mode:
2729
from seleniumbase.fixtures import shared_utils
2830

@@ -54,6 +56,8 @@ def execute_async_script(driver, script, timeout=settings.EXTREME_TIMEOUT):
5456

5557

5658
def wait_for_angularjs(driver, timeout=settings.LARGE_TIMEOUT, **kwargs):
59+
if hasattr(settings, "SKIP_JS_WAITS") and settings.SKIP_JS_WAITS:
60+
return
5761
if not settings.WAIT_FOR_ANGULARJS:
5862
return
5963

seleniumbase/plugins/pytest_plugin.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ def pytest_addoption(parser):
6565
--start-page=URL (The starting URL for the web browser when tests begin.)
6666
--archive-logs (Archive existing log files instead of deleting them.)
6767
--archive-downloads (Archive old downloads instead of deleting them.)
68+
--skip-js-waits (Skip waiting for readyState to be complete or Angular.)
6869
--time-limit=SECONDS (Safely fail any test that exceeds the time limit.)
6970
--slow (Slow down the automation. Faster than using Demo Mode.)
7071
--demo (Slow down and visually see test actions as they occur.)
@@ -327,6 +328,17 @@ def pytest_addoption(parser):
327328
default=False,
328329
help="Archive old downloads instead of deleting them.",
329330
)
331+
parser.addoption(
332+
"--sjw",
333+
"--skip_js_waits",
334+
"--skip-js-waits",
335+
action="store_true",
336+
dest="skip_js_waits",
337+
default=False,
338+
help="""Skip all calls to wait_for_ready_state_complete()
339+
and wait_for_angularjs(), which are part of many
340+
SeleniumBase methods for improving reliability.""",
341+
)
330342
parser.addoption(
331343
"--with-db_reporting",
332344
"--with-db-reporting",
@@ -1265,6 +1277,8 @@ def pytest_configure(config):
12651277
sb_config.archive_logs = config.getoption("archive_logs")
12661278
if config.getoption("archive_downloads"):
12671279
settings.ARCHIVE_EXISTING_DOWNLOADS = True
1280+
if config.getoption("skip_js_waits"):
1281+
settings.SKIP_JS_WAITS = True
12681282
sb_config._time_limit = config.getoption("time_limit")
12691283
sb_config.time_limit = config.getoption("time_limit")
12701284
sb_config.slow_mode = config.getoption("slow_mode")

seleniumbase/plugins/selenium_plugin.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,17 @@ def options(self, parser, env):
136136
help="""The Chrome User Data Directory to use. (Chrome Profile)
137137
If the directory doesn't exist, it'll be created.""",
138138
)
139+
parser.add_option(
140+
"--sjw",
141+
"--skip_js_waits",
142+
"--skip-js-waits",
143+
action="store_true",
144+
dest="skip_js_waits",
145+
default=False,
146+
help="""Skip all calls to wait_for_ready_state_complete()
147+
and wait_for_angularjs(), which are part of many
148+
SeleniumBase methods for improving reliability.""",
149+
)
139150
parser.add_option(
140151
"--protocol",
141152
action="store",

0 commit comments

Comments
 (0)