Skip to content

feat(assertions): support custom expect message#3309

Merged
dgozman merged 1 commit into
microsoft:mainfrom
dgozman:fix-2161
May 1, 2026
Merged

feat(assertions): support custom expect message#3309
dgozman merged 1 commit into
microsoft:mainfrom
dgozman:fix-2161

Conversation

@dgozman
Copy link
Copy Markdown
Collaborator

@dgozman dgozman commented May 1, 2026

Summary

  • Adds an optional string message argument to Expect(locator) / Expect(page) / Expect(response) (both Microsoft.Playwright.Assertions and the four PlaywrightTest harnesses — NUnit / MSTest / Xunit / Xunit.v3; MSTest.v4 inherits via shared sources).
  • When the assertion fails, the message is prepended to the thrown PlaywrightException, mirroring the JS/Python expect(thing, "msg") behavior.
  • The custom message also propagates through .Not.

Fixes #2161

Adds an optional `message` argument to `Expect(...)` overloads (locator,
page, API response). When the assertion fails, the message is prepended
to the thrown PlaywrightException, providing extra context in test
reports — the same pattern as the JS/Python `expect(thing, "msg")` form.

Wired through Assertions.Expect, the four PlaywrightTest harnesses
(NUnit, MSTest, Xunit, Xunit.v3; MSTest.v4 reuses MSTest sources),
AssertionsBase / LocatorAssertions / PageAssertions / APIResponseAssertions,
and propagated through `.Not`.

Fixes microsoft#2161
@dgozman dgozman merged commit 5670c5e into microsoft:main May 1, 2026
16 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.

[Feature] Implement Custom Expect Message option

2 participants