Repository navigation
fix(playwright): do not wait for a frame's calls once its document goes - #126
Merged
Merged
Conversation
Settle waited until the test timed out when a page loaded another document while one of its frames (a payment form's iframe) had a call in flight. The frame goes with the old document, and Playwright reports no end for the call: neither for an ordinary call nor for a keepalive one (navigator.sendBeacon, fetch with keepalive), which the browser goes on sending. Settle dropped only the page's own calls then, so a frame's telemetry beacon held each such test until its timeout. A frame's calls are now dropped when Playwright reports the frame detached, as a closed page's calls already are. Rows: a beacon, a keepalive fetch and an ordinary call a frame had in flight when the page loaded another document (each fails with the old settle), and a beacon the frame sends as the page hides, are not waited for; a beacon from a page that stays is still waited for; a unit row drops only the gone frame's call. Signed-off-by: slayerjain <shubhamkjain@outlook.com>
The rows' Playwright project ran only in Chromium, Playwright's default. PW_BROWSER=firefox or webkit now runs them in that browser, so the settle rows can show a frame's calls are dropped when the frame goes in all three browsers. CI's legs still run them in Chromium. Signed-off-by: slayerjain <shubhamkjain@outlook.com>
A frame whose own document is still loading when the page loads another document goes with the old one, and Playwright reports no end for the frame's document request either. Settle already drops every call of a frame that detaches, its document request included; a row now pins it: a frame from another site commits a document whose last byte the page server holds, then the page loads another document, and the test passes with no wait step. The unit row's gone frame has its document request in flight too. The settle note in the README and settle.ts now say that the browser goes on sending a frame's keepalive call only while the test's context lives: one still in flight when the test ends is cut by the context close, so its answer may not be recorded. Signed-off-by: slayerjain <shubhamkjain@outlook.com>
The unit row for a frame that is gone gave the other frame only a beacon, so it did not pin that settle keeps counting another frame's document request while it loads. Give that frame a document request too, and expect it still named after the first frame goes. Signed-off-by: slayerjain <shubhamkjain@outlook.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
What was wrong
Before a test's browser context closes,
@keploy/playwrightwaits until none of the test's calls is in flight (settle). It counts calls by Playwright's own request events, and drops a call once the browser cancels it: when its page loads another document, its page closes, or the test closes its context.When a page loads another document, the frames of the old document (a payment form's iframe) go with it. Playwright reports no end for the calls those frames still had in flight: neither for an ordinary call nor for a keepalive one (
navigator.sendBeacon,fetchwithkeepalive: true), which the browser goes on sending, nor for a frame's own document request while that document is still loading. Settle dropped only the page's own calls at that moment, so it went on counting the frame's call and held the test until Playwright's test timeout.Seen in enterprise-ui's Playwright suite under
keploy mock record: as the app loads another page, Stripe.js's controller frame posts two telemetry beacons tohttps://r.stripe.com/b(resource typeping) 20 ms before the frame goes with the old document. Every call settle still counted at the end of each hung test was such a beacon, and those tests waited two minutes, until their timeout.What changes
src/settle.ts: when Playwright reports a frame detached, the calls of that frame still counted are dropped, its own document request included, as a closed page's calls already are. Playwright reports each frame that goes, a frame inside it too.net::ERR_ABORTED), beacons included, so for a frame the page removes nothing changes.Tests
test/rows.test.mjswithtest/fixtures/settle.spec.ts(real Chromium runs against the fake agent and a page server that holds/beacon,/slowand the last byte of/slowdocuntil the row lets them go):fetchand an ordinaryfetcha frame from another site had in flight when the page loaded another document: each test passes with no wait step, and the page server received the call; with the oldsettle.tseach of the three times out;pagehidehandler as the page loads another document: not waited for;/slowdoc, its last byte held) is still loading when the page loads another document: the test passes with no wait step; with the oldsettle.ts, or with the frame's document request kept counted, it fails: settle still countsGET .../slowdoc, whose last byte never comes;POST .../beacon.test/unit.test.mjs: with calls in two frames of a page, each frame's own document request among them, the first frame going drops only its calls, its document request too (the other frame's call and its own document request are still named), and settle keeps waiting; the second going wakes it.test/fixtures/playwright.config.ts:PW_BROWSER=firefoxorwebkitruns the rows in that browser; CI's legs (Node 20, 22 and 24) run them in Chromium, the browser the workflow installs.