Skip to content

Report strict mode violations in assertion failures - #226

Merged
smnandre merged 3 commits into
playwright-php:mainfrom
smnandre:fix/assertion-strict-mode-message
Nov 17, 2026
Merged

smnandre merged 3 commits into
playwright-php:mainfrom
smnandre:fix/assertion-strict-mode-message

Conversation

@smnandre

Copy link
Copy Markdown
Member

An assertion on a locator that resolves to several elements waits for its whole timeout, then fails with a generic message such as Expected locator to be visible. Playwright raises a strict mode violation on each check, and the assertion discards it and retries.

The assertion now fails on the first strict mode violation. Its message keeps the usual first line, or the custom message, followed by Playwright's error, which lists the matched elements. The original exception is available through getPrevious(). This applies to negated assertions too, and matches Playwright JS, where waiting does not help a locator that is too broad.

AssertionException gains an optional $previous constructor argument; existing callers are not affected. Other errors raised while polling are still retried and left out of the message, as before.

Fixes #187

@codecov

codecov Bot commented Nov 15, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@smnandre
smnandre merged commit 5261656 into playwright-php:main Nov 17, 2026
10 checks passed
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.

Cannot getByText() an h1 tag

1 participant