Refactor bootstrapping process and browser.waitForAngular
to make them interruptible
#4052
Labels
Projects
browser.waitForAngular
to make them interruptible
#4052
In the bootstrapping process (everything after navigation in
browser.get
) andbrowser.waitForAngular
we send a few separate commands toselenium-webdriver
. Browser initiated navigation (e.g. clicking a link) may cause the first few commands to be executed on one page, and the remaining commands to be executed on a different page. This could end up with us trying to bootstrap or synchronize with entirely the wrong page.What's more, in #3857 we want to start running bootstrap checks periodically. With the control flow disabled, this could easily lead of race conditions.
Luckily, this is easy enough to solve. We can stick some metadata on the
window
object at the start of bootstrapping/waitForAngular
, and if that metadata goes away, we know navigation occurred. If navigation occurs, we silently give up on the remainder of the bootstrapping/waitForAngular
.Proposed Implementation
We should write a helper function
safeExecuteScriptFactory
:With the following additions to
clientsidescripts.js
:Then, in at the start of bootstrapping in
browser.get
(code link in v5.1) we do:And then we do essentially the same thing in
waitForAngular
as well. This way, if some kind of navigation happens, we just stop.Edge Case:
browser.executeAsyncScript_
We can't use
safeExecuteScriptWithDescription
in place ofbrowser.executeAsyncScript_
becausesafeExecuteScriptWithDescription
doesn't take asynchronous scripts. However, as per #4053, we probably want to get rid ofbrowser.executeAsyncScript_
anyway.Edge Case: Blocking Proxy
Blocking Proxy has its own GitHub issue (angular/blocking-proxy#32) about sending clear error messages when navigation interrupts stabilization. We will simply catch this error to detect interruptions.
We could have a race condition in
waitForAngular
where navigation could occur in between plugin stability checks and blocking proxy checks. However,waitForAngular
is only called at the start of commands likeel.click()
, and so well written tests shouldn't run into this problem.Edge Case: Plugins
The plugin functions
onPageLoad
,onPageStable
,onPageLoad
andonPageStable
also need to be interruptible. This is mostly going to be up to the plugin authors, but we can help them out by providing them withsafeExecuteScriptWithDescription
.The text was updated successfully, but these errors were encountered: