Skip to content

Use waiting matchers for h1 content expectations#317

Merged
theseanything merged 1 commit into
mainfrom
use-waiting-h1-matchers
Jul 24, 2026
Merged

Use waiting matchers for h1 content expectations#317
theseanything merged 1 commit into
mainfrom
use-waiting-h1-matchers

Conversation

@theseanything

Copy link
Copy Markdown
Contributor

What

Replaces all expect(page.find("h1")).to have_content "X" assertions with expect(page).to have_css "h1", text: "X". A purely mechanical pattern swap — no headings or call sites change.

Why

The find-then-assert form races against navigation. page.find("h1") runs first and in the pipeline this intermittently either:

  • fails with ElementNotFound: Unable to find visible css "h1" because the document is momentarily blank mid-navigation, or
  • grabs the outgoing page's h1, which then goes stale before or during the have_content check, raising StaleElementReferenceError

expect(page).to have_css "h1", text: "X" re-runs the whole query (element and text together) on every retry, so it recovers from both a late-rendering page and a stale node.

Follows on from #315, which gave these matchers a long enough retry window.

expect(page.find("h1")).to have_content finds an h1 first and
then checks its text. If the find runs while the browser is
mid-navigation it either fails with ElementNotFound on a blank
document, or grabs the outgoing page's h1 which then goes stale.
expect(page).to have_css re-runs the whole query on every retry,
so it recovers from both.

@lfdebrux lfdebrux left a comment

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.

I'm not sure it will make a difference to the errors we were seeing (or how we would tell now the default wait time has been increased), probably won't hurt though.

@theseanything
theseanything added this pull request to the merge queue Jul 24, 2026
Merged via the queue into main with commit 46eb9e8 Jul 24, 2026
3 checks passed
@theseanything
theseanything deleted the use-waiting-h1-matchers branch July 24, 2026 11:56
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.

2 participants