Skip to content

Commit ecc253b

Browse files
committed
Add option to wait for AngularJS to load
1 parent e34928f commit ecc253b

File tree

4 files changed

+46
-0
lines changed

4 files changed

+46
-0
lines changed

seleniumbase/behave/behave_sb.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
-D binary-location=PATH (Set path of the Chromium browser binary to use.)
4343
-D driver-version=VER (Set the chromedriver or uc_driver version to use.)
4444
-D sjw (Skip JS Waits for readyState to be "complete" or Angular to load.)
45+
-D wfa (Wait for AngularJS to be done loading after specific web actions.)
4546
-D pls=PLS (Set pageLoadStrategy on Chrome: "normal", "eager", or "none".)
4647
-D headless (Run tests in headless mode. The default arg on Linux OS.)
4748
-D headless2 (Use the new headless mode, which supports extensions.)
@@ -588,6 +589,10 @@ def get_configured_sb(context):
588589
if low_key in ["sjw", "skip-js-waits", "skip_js_waits"]:
589590
settings.SKIP_JS_WAITS = True
590591
continue
592+
# Handle: -D wfa / wait-for-angularjs / wait_for_angularjs
593+
if low_key in ["wfa", "wait-for-angularjs", "wait_for_angularjs"]:
594+
settings.WAIT_FOR_ANGULARJS = True
595+
continue
591596
# Handle: -D visual-baseline / visual_baseline
592597
if low_key in ["visual-baseline", "visual_baseline"]:
593598
sb.visual_baseline = True

seleniumbase/plugins/pytest_plugin.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ def pytest_addoption(parser):
5959
--binary-location=PATH (Set path of the Chromium browser binary to use.)
6060
--driver-version=VER (Set the chromedriver or uc_driver version to use.)
6161
--sjw (Skip JS Waits for readyState to be "complete" or Angular to load.)
62+
--wfa (Wait for AngularJS to be done loading after specific web actions.)
6263
--pls=PLS (Set pageLoadStrategy on Chrome: "normal", "eager", or "none".)
6364
--headless (Run tests in headless mode. The default arg on Linux OS.)
6465
--headless2 (Use the new headless mode, which supports extensions.)
@@ -358,6 +359,17 @@ def pytest_addoption(parser):
358359
and wait_for_angularjs(), which are part of many
359360
SeleniumBase methods for improving reliability.""",
360361
)
362+
parser.addoption(
363+
"--wfa",
364+
"--wait_for_angularjs",
365+
"--wait-for-angularjs",
366+
action="store_true",
367+
dest="wait_for_angularjs",
368+
default=False,
369+
help="""Add waiting for AngularJS. (The default setting
370+
was changed to no longer wait for AngularJS to
371+
finish loading as an extra JavaScript call.)""",
372+
)
361373
parser.addoption(
362374
"--with-db_reporting",
363375
"--with-db-reporting",
@@ -1546,6 +1558,8 @@ def pytest_configure(config):
15461558
settings.ARCHIVE_EXISTING_DOWNLOADS = True
15471559
if config.getoption("skip_js_waits"):
15481560
settings.SKIP_JS_WAITS = True
1561+
if config.getoption("wait_for_angularjs"):
1562+
settings.WAIT_FOR_ANGULARJS = True
15491563
sb_config.all_scripts = config.getoption("all_scripts")
15501564
sb_config._time_limit = config.getoption("time_limit")
15511565
sb_config.time_limit = config.getoption("time_limit")

seleniumbase/plugins/sb_manager.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ def SB(
7676
binary_location=None, # Set path of the Chromium browser binary to use.
7777
driver_version=None, # Set the chromedriver or uc_driver version to use.
7878
skip_js_waits=None, # Skip JS Waits (readyState=="complete" and Angular).
79+
wait_for_angularjs=None, # Wait for AngularJS to load after some actions.
7980
use_wire=None, # Use selenium-wire's webdriver over selenium webdriver.
8081
external_pdf=None, # Set Chrome "plugins.always_open_pdf_externally":True.
8182
is_mobile=None, # Use the mobile device emulator while running tests.
@@ -109,6 +110,7 @@ def SB(
109110
wire=None, # Shortcut / Duplicate of "use_wire".
110111
pls=None, # Shortcut / Duplicate of "page_load_strategy".
111112
sjw=None, # Shortcut / Duplicate of "skip_js_waits".
113+
wfa=None, # Shortcut / Duplicate of "wait_for_angularjs".
112114
save_screenshot=None, # Save a screenshot at the end of each test.
113115
no_screenshot=None, # No screenshots saved unless tests directly ask it.
114116
page_load_strategy=None, # Set Chrome PLS to "normal", "eager", or "none".
@@ -607,6 +609,17 @@ def SB(
607609
settings.SKIP_JS_WAITS = True
608610
elif skip_js_waits:
609611
settings.SKIP_JS_WAITS = skip_js_waits
612+
if wfa is not None and wait_for_angularjs is None:
613+
wait_for_angularjs = wfa
614+
if wait_for_angularjs is None:
615+
if (
616+
"--wfa" in sys_argv
617+
or "--wait_for_angularjs" in sys_argv
618+
or "--wait-for-angularjs" in sys_argv
619+
):
620+
settings.WAIT_FOR_ANGULARJS = True
621+
elif wait_for_angularjs:
622+
settings.WAIT_FOR_ANGULARJS = wait_for_angularjs
610623
if save_screenshot is None:
611624
if (
612625
"--screenshot" in sys_argv

seleniumbase/plugins/selenium_plugin.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ class SeleniumBrowser(Plugin):
4040
--binary-location=PATH (Set path of the Chromium browser binary to use.)
4141
--driver-version=VER (Set the chromedriver or uc_driver version to use.)
4242
--sjw (Skip JS Waits for readyState to be "complete" or Angular to load.)
43+
--wfa (Wait for AngularJS to be done loading after specific web actions.)
4344
--pls=PLS (Set pageLoadStrategy on Chrome: "normal", "eager", or "none".)
4445
--headless (Run tests in headless mode. The default arg on Linux OS.)
4546
--headless2 (Use the new headless mode, which supports extensions.)
@@ -178,6 +179,17 @@ def options(self, parser, env):
178179
and wait_for_angularjs(), which are part of many
179180
SeleniumBase methods for improving reliability.""",
180181
)
182+
parser.addoption(
183+
"--wfa",
184+
"--wait_for_angularjs",
185+
"--wait-for-angularjs",
186+
action="store_true",
187+
dest="wait_for_angularjs",
188+
default=False,
189+
help="""Add waiting for AngularJS. (The default setting
190+
was changed to no longer wait for AngularJS to
191+
finish loading as an extra JavaScript call.)""",
192+
)
181193
parser.addoption(
182194
"--protocol",
183195
action="store",
@@ -1105,6 +1117,8 @@ def beforeTest(self, test):
11051117
test.test.start_page = self.options.start_page
11061118
if self.options.skip_js_waits:
11071119
settings.SKIP_JS_WAITS = True
1120+
if self.options.wait_for_angularjs:
1121+
settings.WAIT_FOR_ANGULARJS = True
11081122
test.test.protocol = self.options.protocol
11091123
test.test.servername = self.options.servername
11101124
test.test.port = self.options.port

0 commit comments

Comments
 (0)