Browser Matchers
TestBox expectations for bx-playwright pages and locators that wait for the page.
The browser matchers let you assert on bx-playwright pages and locators with the TestBox expect() DSL you already use:
expect( page ).toHaveTitle( "Dashboard" )
expect( page ).toHavePath( "/dashboard" )
expect( page ).toSee( "Welcome" )
expect( page ).notToSee( "Error" )
expect( page.locator( ".todo" ) ).toHaveCount( 3 )
expect( page.locator( "@error" ) ).notToBeVisible()Web-First: They Wait

Every browser matcher delegates to bx-playwright's web-first assertions. It retries until it passes or the assertion timeout expires (5 seconds by default), so a matcher waits for a redirect to land, a spinner to go away or a list to fill in:
The not forms wait too: notToSee( "Loading" ) passes as soon as the text goes away, instead of failing because it was still there on the first check.
Change the timeout with the bx-playwright timeouts.assertion setting, or per browse() call:
Matchers at a Glance
locator
The text of the first match is exactly text (whitespace normalized), or matches a regex
Every matcher has a negated form with the not prefix: notToHaveTitle(), notToHaveURL(), notToHavePath(), notToSee(), notToHaveText(), notToBeVisible(), notToBeHidden(), notToHaveCount() and notToHaveValue(). See the Not Operator.
Pages and Locators
A page is what
browse()hands your closure, or whatvisit()andnewPage()return.A locator points at elements of a page:
page.locator( ".todo" ),page.locator( "@error" )(adata-testid),page.byRole( "button", { name : "Save" } ),page.byLabel( "Email" )and the other bx-playwright finders.
Arguments can be passed by position or by name (toHaveCount( count = 3 )). Where the table says "or a regex", pass a pattern built with page.regex():
Page Matchers
toHaveTitle()
The page title is exactly title, or matches a page.regex() pattern.
toHaveURL()
The full page URL, scheme, host, path and query string included, is exactly url, or matches a page.regex() pattern. Use toHavePath() when only the path matters.
toHavePath()
The URL path is exactly path (case sensitive), ignoring the scheme, host, query string and hash, like bx-playwright's assertPathIs(). It is the natural check after a redirect, because it does not depend on the baseURL:
toSee()
text, or a page.regex() pattern, is visible in the page, or inside the locator when you pass one. It uses bx-playwright's assertSee(), and the negated form uses assertDontSee().
Locator Matchers
toHaveText()
The text of the first matching element is exactly text, with whitespace normalized, or matches a page.regex() pattern. Use toSee() on the locator for a partial match.
toBeVisible()
The first matching element is visible.
toBeHidden()
The first matching element is hidden, or not in the page at all. Handy to wait for spinners and dialogs to go away:
toHaveCount()
The locator matches exactly count elements.
toHaveValue()
The input, textarea or select has value, or a value matching a page.regex() pattern.
Failure Messages
A matcher that does not pass in time fails the spec with a regular TestBox.AssertionFailed failure that carries bx-playwright's message: what was expected, what was received, and Playwright's call log of what it waited for. For example, expect( page.locator( "li" ) ).toHaveCount( 5 ) on a list with one item fails with a message like:
The exact wording comes from Playwright. withContext() prefixes it like any other matcher.
When the actual value is not the kind of object a matcher needs, such as a locator passed to a page matcher or a plain string, it fails right away, without waiting, and says what it got:
Using the Matchers Outside Browser Specs
TestBox registers the matchers for every spec of a bundle with browser support, turned on by @browser, @browserProfile or @baseURL. In any other BoxLang spec, register them yourself with addMatchers():
Beyond These Matchers
bx-playwright ships many more web-first checks: enabled, checked, focused, attributes, CSS classes, accessible names and more. Use them through page.expect( selector ) or the inline assert*() methods; their Playwright.AssertionFailed exceptions count as TestBox failures:
See the full list in the bx-playwright assertions guide.
Last updated
Was this helpful?