test: Wait for a page load in Browser.open() #19583
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Commit 8284618 dropped all explicit "wait for page load" calls (fka.
expect_load()
) in favor of allowing page loads during wait commands. This is better in almost all cases, but it created a race condition on the login page in tests which logged out and back in. In particular, this can happen:Test calls
Browser.logout()
.That destroys a lot of execution contexts from the session, and creates a new one for the login page. It waits until the
#login
field becomes visible.Test starts a new session by calling
Browser.open()
usually viaBrowser.login_and_go()
. This results in aPage.navigate()
CDP call. Sometimes this takes a while.Browser.try_login()
fills in the login form. In most cases, thewait: ph_is_present("#login")
command runs into the page load from 3., sees the destroyed/new execution context, and resumes on the new frame.However, if cockpit/ws or the browser take a while to load the login page, it could happen that it gets all the way to e.g. filling in the user or even password form before the page load from 3. happens. That page load resets the form.
try_login()
clicks on "Login" button, which fails because no user or password is given.Fix this by always waiting for a page load in
Browser.open()
after aPage.navigate()
. But we don't need the unnecessary complex and brittle polling machinery of the oldexpectLoad()
before commit 8284618. We can use theloadEventFired
CDP signal, which happens after the page and all of its frames finished loading, and execution contexts are set up. Introduce a new littlewaitPageLoad()
helper which re-uses the existingpageLoadHandler
promise.This fixes this common flake pair, which both fail in > 30% of runs.
See #19578 for the debugging note details and a stress test with amplification.