Skip to content

Show how long a Nightwatch assertion waited - #636

Open
vishnuv688 wants to merge 4 commits into
mainfrom
fix/627-nightwatch-assert-timing
Open

vishnuv688 wants to merge 4 commits into
mainfrom
fix/627-nightwatch-assert-timing

Conversation

@vishnuv688

Copy link
Copy Markdown
Member

What & why

Under Nightwatch's BDD interface, a native assertion's row recorded the moment it was queued as both its start and its end, so a trace showed it lasting about 1 ms however long it waited. In the committed fixture nightwatch-bdd-2026-11-10-ee505b9c.zip, a failing assert.textContains that polled for 5 s ran from 2205 to 2206 ms, and its test's span closed before the failure happened.

  • The row is re-timed from Nightwatch's results bag when it carries a command window. The BDD interface never does, so the row now ends when the assertion's promise settled (the recorder already observed it), or, when that was not observed, after the wait the failure message names (Nightwatch ends it with "(5236ms)").
  • The row keeps its queued start. Rows are ordered by start, then issue sequence, so the order is unchanged; the exporter already raises a start to the previous row's end.

Closes #627

Type of change

  • Bugfix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Polish (an improvement to an existing feature)
  • Breaking change (existing behavior changes for users)
  • Documentation
  • Internal (build, CI, dependencies, tooling)

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.ts updated, and tables regenerated with pnpm docs:capabilities, if this adds or changes user-facing behaviour

Not applicable: assertion rows are listed already; this fixes their duration.

Notes for reviewers

  • Verified in a real browser. pnpm demo:nightwatch (trace mode, the-internet.herokuapp.com, Chrome 158): the failing assert.textContains("#flash", ...) now lasts 5240 ms against the 5236 ms its error message names, and the next test's first action starts 55 ms after it ends. Before, the same row lasted 1 ms.
  • Tests: the test that pinned the queued end ("keeps ... its enqueue timestamp when both sources exist") now expects the settle time with the start unchanged; a new one covers the failure-message fallback.
  • Checks run: pnpm test (347 files, 4727 tests), pnpm typecheck and lint (0 errors) pass.

Screenshots / recordings

Not applicable: no UI change.

🤖 Generated with Claude Code

Under the BDD interface Nightwatch reports no per-assertion command
window, so a native assertion's row kept the moment it was queued as
both its start and its end, and a failing textContains that polled for
5 s showed as 1 ms with its test's span closing before the failure. The
row now ends when the assertion's promise settled, or after the wait its
failure message names, and keeps its queued start, which with its issue
sequence keeps the rows in order.

Closes #627
@vishnuv688 vishnuv688 self-assigned this Nov 30, 2026
@vercel

vercel Bot commented Nov 30, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
devtools Ready Ready Preview Nov 30, 2026 10:20am UTC

Request Review

@greptile-apps

greptile-apps Bot commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

Confidence Score: 5/5 · The PR appears safe to merge, with no new findings or outstanding previous findings.RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge, with no new findings or outstanding previous findings.

Summary

Assertion rows now use the observed settlement time when Nightwatch supplies no command window. Failed assertions without an observed settlement use the wait named in their message, accounting for earlier assertions.

  • Nightwatch assertion rows now show how long each wait lasted.

Reviews (4) · Last reviewed commit: "Note that a queued native assert's live ..." · Reviewed by Greptile

Comment on lines +156 to +157
startTime: call.timestamp,
endTime: call.timestamp + Number(elapsed[1])

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Queued waits still disappear

elapsedTiming adds the assertion's wait to its enqueue time, not its execution start. For synchronous assertions without an observed settlement, earlier queued work can therefore hide the wait again. If an earlier assertion takes 5 seconds and this assertion then waits 5 seconds, both calculated ends land around enqueue + 5 seconds. The exporter raises the second start to the first end, leaving the second row about 1 ms long.

Account for earlier queued work when placing this fallback window, and add a test with consecutive queued assertions.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 9cdc7a0: captureNativeAssertions now tracks where the assertion queue has got to, and the message fallback starts each wait at the later of the assertion's enqueue time and the previous assertion's end, since Nightwatch runs queued assertions one after another. Test: "places consecutive queued failures one after another, each with its own wait" (two assertions queued together waiting 5000 and 4000 ms land at 0-5000 and 5000-9000).

Nightwatch runs queued assertions one after another, but the fallback
that times an assertion from its failure message started the wait when
the assertion was queued. Two assertions queued together, each waiting
5 s, got the same window and the exporter pressed the second back to
1 ms. The fallback now starts each wait once the assertion before it has
ended.
Comment on lines +158 to +159
const startTime = Math.max(call.timestamp, after)
return { startTime, endTime: startTime + Number(elapsed[1]) }

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Queued actions appear out of order

Moving the fallback's startTime forward can put an assertion after commands queued later. Queue two failing verify.textContains calls followed by a click, without observed settlements or command windows: the second assertion starts at the first assertion's end, but the click keeps its enqueue start.

Both trace outputs sort by startTime before sequence, so the click appears before the second assertion. This can also shrink the assertion's displayed wait again. Keep the enqueue time as the ordering key when placing the fallback window.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in cfda385: the fallback keeps the row's startTime at enqueue, the ordering key beside sequence, and only its end follows the queue (the later of enqueue and the previous assertion's end, plus the wait). The exporter raises a row's start to the previous row's end (trace-action-events.ts), so two assertions queued together at 200 ms waiting 5000 and 4000 ms show as 200 to 5200 and 5200 to 9200, and a click queued after them at 201 ms sorts and shows after both.

Moving the fallback's start to the previous assertion's end let a
command queued after it sort before it, since rows are ordered by start
before issue sequence. The start stays at enqueue, the ordering key, and
only the end follows the assertion queue; the exporter raises the start
to the previous row's end, so each assertion still shows its own wait.
Comment on lines +160 to +161
startTime: call.timestamp,
endTime: waitedFrom + Number(elapsed[1])

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Later waits look longer

Keeping startTime at enqueue fixes trace ordering, but makes the live action list count earlier waits again. With two queued failures waiting 5000 ms and 4000 ms, the second row now carries a 9000 ms span. The live view's entryDuration subtracts startTime directly, so it displays 9 seconds instead of 4 seconds. Only the trace exporter raises the start to the previous end.

Keep the enqueue ordering key without making the live duration include earlier assertions.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, and it is a trade-off rather than a bug this PR can remove: one startTime is both the row's ordering key (it must be the enqueue time, or a command queued after back-to-back asserts sorts ahead of them, your previous comment) and the start of its live duration. The trace exporter raises a start to the previous row's end, so traces show each wait on its own; the live list subtracts the start directly. The observed-settlement path, which existed before this PR for cucumber and is the common case here, has the same shape (enqueue start, settle end). Only back-to-back un-awaited asserts are affected. Kept as is and recorded in 9c240d6 in packages/nightwatch-devtools/CLAUDE.md known debt; the fix is a display start separate from the ordering key across shared, the app and the exporter, which belongs in its own change.

The row keeps its enqueue start as the ordering key, so the live action
list, which subtracts the start directly, counts the wait of the assert
queued before it; the trace exporter does not. A separate display start
would fix it across shared, the app and the exporter.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Nightwatch: native assertion rows record about 1 ms however long they waited

1 participant