๐Ÿ”ท Core

bx-playwright-assertions

Use this skill when asserting on web pages with bx-playwright: web-first retrying assertions, the inline style (assertSee, assertTitle, assertPathIs, assertVisible, assertCount, assertValue), the expect() style (toHaveText, toBeVisible, toHaveURL, not()), soft assertions with page.soft(), regex matching, assertion timeouts, and the Playwright.AssertionFailed, Playwright.Timeout and other typed errors.

$ npx skills add ortus-boxlang/skills/boxlang-modules/bx-playwright/bx-playwright-assertions
$ coldbox ai skills install ortus-boxlang/skills/boxlang-modules/bx-playwright/bx-playwright-assertions
๐Ÿ”— https://skills.boxlang.io/skills/raw/ortus-boxlang/skills/boxlang-modules~bx-playwright~bx-playwright-assertions

bx-playwright: Assertions and Errors

BoxLang is the AI-native software productivity platform for building, modernizing and running applications, with developers and AI agents working together.

Assertions retry until they pass or timeouts.assertion (5000 ms) expires. Never sleep before them.

Inline Style (chainable)

page.assertTitle( "Dashboard" )
	.assertTitleContains( "Dash" )
	.assertSee( "Welcome" )
	.assertDontSee( "Error" )
	.assertPathIs( "/dashboard" )        // ignores host, query and hash
	.assertUrlContains( "user=" )
	.assertVisible( "@menu" )
	.assertMissing( "@spinner" )         // hidden or absent
	.assertText( "#total", "$99" )
	.assertValue( "Email", "[email protected]" )
	.assertChecked( "Remember me" )
	.assertCount( ".todos li", 3 )
	.assertAttribute( "a.docs", "href", "/docs" )

Also assertUrlIs, assertNotChecked, assertEnabled, assertDisabled. On a locator or component, assertSee/assertDontSee are scoped to it.

Expect Style

page.expect( "h1" ).toHaveText( "Welcome" )
page.expect().toHaveTitle( "Home" ).toHaveURL( page.regex( "/home$" ) )
page.expect( "@error" ).not().toBeVisible()
page.locator( ".row" ).expect().toHaveCount( 3 )
playwright().expect( someLocator ).toContainText( "x" )

Matchers: toBeVisible, toBeHidden, toBeEnabled, toBeDisabled, toBeChecked, toBeEditable, toBeEmpty, toBeFocused, toBeAttached, toBeInViewport, toHaveText, toContainText, toHaveValue, toHaveCount, toHaveAttribute( name, value ), toHaveClass, toContainClass, toHaveId, toHaveCSS( name, value ), toHaveAccessibleName, toHaveRole, toMatchAriaSnapshot( yaml ), page: toHaveTitle, toHaveURL; API responses: toBeOK. not() negates only the next matcher. Text and URL matchers accept page.regex( pattern, "i" ).

Soft Assertions

page.soft( ( p ) => {
	p.assertTitle( "Store" ).assertSee( "Buy" )
	p.expect( "h1" ).toHaveText( "Store" )
} )   // throws once: "N soft assertion(s) failed: 1) ... 2) ..."

Timeouts

pw.newPage( { timeouts : { assertion : 10000, action : 15000 } } )

Typed Errors

TypeMeaning
Playwright.AssertionFailedAssertion did not pass in time (message has expected, received and the call log)
Playwright.TimeoutAn action waited too long for its element
Playwright.ActionFailedPlaywright refused an action
Playwright.InvalidOptionBad option, value, method, device or selector; detail lists valid values
Playwright.InvalidProfileUnknown profile or extends loop
Playwright.NotInstalledDriver, Node.js, browser or bx-ai missing (bxplaywright install)
try {
	page.click( "Checkout" )
} catch ( "Playwright.Timeout" e ) {
	println( e.message & " Fix: " & e.detail )
}