Repository navigation
Capture a cucumber scenario's last page before the user's After hooks run - #635
vishnuv688 wants to merge 3 commits into
Conversation
… run Cucumber runs the user's After hooks before the service's afterScenario, so the end-of-scenario capture ran after a hook had ended or reloaded the session. The example's reloadSession left the last action and every assertion after it showing a blank about:blank page, and a failing scenario had no picture of its failure. The capture now runs in afterStep at the scenario's last step, or at a failed one, while the scenario's session is still alive. A test whose session a hook replaced takes no end-of-test capture from the new session. Closes #631
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
[Medium impact] The PR appears safe to merge; all previous capture issues are addressed. SummaryThe PR captures Cucumber's final page before the user's
Reviews (3) · Last reviewed commit: "Check the final capture against the sess..." · Reviewed by Greptile |
| if (this.#testSessionId && sessionId !== this.#testSessionId) { | ||
| log.info( | ||
| 'The session was replaced after the test ran, so its last page is not captured again' | ||
| ) | ||
| return |
There was a problem hiding this comment.
Blank capture returns at teardown
When the last Mocha test reloads its session in afterEach, afterTest skips capture without filling #finalizedSlot. But after() still calls #finalizePerScenario() directly. It captures the replacement session's blank page at the test's last action timestamp, so session and spec traces can still show the wrong final page. Apply the session check to worker-end capture too, while preserving standalone capture.
There was a problem hiding this comment.
Fixed in 217da69: the session check moved into #finalizePerScenario itself, so the worker-end pass in after() gets it too. A session with no action, the standalone path, has nothing to compare and is still captured. Test: "takes no capture at worker end from a session the last test reloaded" in trace-action-capture.test.ts.
| const sessionId = this.#browser?.sessionId | ||
| if (this.#testSessionId && sessionId !== this.#testSessionId) { |
There was a problem hiding this comment.
The check also skips valid captures when a Mocha or Jasmine test reloads and then continues. A test can call reloadSession(), open a page, and click submit. onReload restores capture, but neither it nor later commands update #testSessionId. afterTest then skips the submit result and writes the test's artifacts with an older frame. Track which session owns the last action rather than treating every session change as teardown.
There was a problem hiding this comment.
Fixed in 217da69: the service now records the session each action ran on (in #afterCommand, for commands that map to a row, so reloadSession itself does not count), and skips a final capture only when the browser's session is no longer the last action's. A test that reloads, opens a page and submits is captured on its new session. Test: "captures the last action of a test that reloaded its session and carried on".
Comparing with the session a test started on skipped a valid capture when a test reloaded and carried on, and the worker-end pass in after() still captured a blank page when the last test's afterEach reloaded. The service now records the session each action ran on, and every end-of-test capture, at test end and at worker end, is skipped only when the browser's session is no longer that one.
| if (this.#isActionCommand(command)) { | ||
| this.#lastActionSessionId = this.#browser.sessionId | ||
| } |
There was a problem hiding this comment.
Final picture uses wrong session
A test can click on session A, call reloadSession(), then call getTitle() on session B. The read updates #lastActionSessionId to B, so the session check passes. But #finalizePerScenario skips reads when choosing the last page-changing command and captures B's blank page at A's click timestamp. The trace then shows the wrong result for that click.
Track the session alongside the command selected for the final capture, rather than updating one shared field for every mapped command.
There was a problem hiding this comment.
Fixed in 20f75ad: the service now keeps the session of the last page-changing action beside the last action's, and #finalCaptureTarget returns the action the final capture is of together with the session that action ran on, which is what the check compares. Clicking on A, reloading, then reading on B no longer lets the click be captured on B. Test: "takes no capture of a click on a session a later read ran after a reload".
The final capture is of the test's last page-changing action, but the session it was checked against was the last action's of any kind, so a read on a reloaded session let a click from the session before be captured on the new blank page. The service now keeps the session of the last page-changing action beside the last action's, and checks the one belonging to the action the capture is of.
What & why
In a WebdriverIO cucumber run, the page a scenario ended on was captured after the user's
Afterhooks had run. Cucumber runsAfterhooks in reverse order of definition, and WebdriverIO's cucumber framework registers itsafterScenariohook before it loads the step files, so the user's hook runs first. The cucumber example'sAfter(() => browser.reloadSession())therefore gave the service a new session, and the last action and every assertion after it showed a blackabout:blankcapture. A failing scenario had no picture of its failure.afterStepruns the end-of-scenario capture when the step is the scenario's last, or when it failed (cucumber skips the rest), while the scenario's session is still alive. The existing finalized-slot check makesafterScenario's capture a no-op after it.afterScenario,afterTest, and the worker-end pass inafter()) is skipped when the browser's session is no longer the last action's, so a new session's blank page never stands in for the test's last state. A mochaafterEachthat reloads is covered, and a test that reloads mid-way and carries on is captured on its new session.Closes #631
Type of change
Packages touched
shared(types and contracts)core(framework-agnostic capture/reporting)elements(published element/snapshot API:@wdio/elements)service(WebdriverIO adapter)nightwatch-devtools(Nightwatch adapter)selenium-devtools(Selenium adapter)selenium-devtools-py(Selenium Python adapter)backend(server)app(UI)script(page-injected runtime)trace(Trace mode)Capability matrix
packages/conformance/src/features.tsupdated, and tables regenerated withpnpm docs:capabilities, if this adds or changes user-facing behaviourNot applicable: per-action captures are listed already; this fixes which page a scenario's last capture shows.
Notes for reviewers
AfterStephook, so it already captures before the user'sAfterhooks; Nightwatch orders its pre-quit capture first. Only the WebdriverIO service needed the change.DEVTOOLS_MODE=trace DEVTOOLS_SPECS=all pnpm demo:wdioagainst the-internet.herokuapp.com, Chrome 158: at the failed assertion oflogin-fail.feature, the trace's snapshot is the login page with the "Your username is invalid!" banner in its tree, and its screenshot shows the red banner over the login form. Before, both wereabout:blankand a black frame. Debugging the same trace through the trace query tools returned that screenshot.Afterhook'sreloadSessiontriggers no second capture; a failed step capturing; a step before the last not capturing;afterTestafter a session replacement capturing nothing; a test that reloads and carries on capturing its last action;after()at worker end capturing nothing from a session the last test reloaded.pnpm test(347 files, 4730 tests),pnpm typecheckand lint (0 errors; the four warnings inpackages/service/src/index.tsare its size and long functions, already listed as debt) pass.Screenshots / recordings
Not applicable: no UI change.
🤖 Generated with Claude Code