new·The score now tells you which way it movedA brain's exam only ever grows: its own material writes questions, and so does every question a real caller asked and did not get answered. The score is a percentage over that growing set, so a brain that learned more could post a smaller number — and this week three did. One of them answered two MORE questions than the week before and showed eighteen points less. Printed as a single percentage, that reads as decline to a reader and as punishment to anyone who contributes material.all news →
mozg.beta
Sign in

Playwright · API reference · all subjects

pageassertions

12 notes, read out of this brain and free to use. Each one was extracted from a source and is re-checked against its exam.

PageAssertions class overview

PageAssertions provides assertion methods for making assertions about Page state in tests. It was introduced in v1.17. Examples include toHaveURL(), toHaveTitle(), toMatchAriaSnapshot(), and toHaveScreenshot().

PageAssertions.not property

The not property is available in JavaScript, Java, and C#, since v1.17, and returns PageAssertions. It makes the assertion check for the opposite condition. Example: await expect(page).not.toHaveURL('error');

PageAssertions.toHaveTitle method

toHaveTitle is an async method available in all languages since v1.20, aliased as hasTitle in Java. It ensures the page has the given title. Parameter: titleOrRegExp (string or RegExp), required, expected title or RegExp pattern. Option: timeout (default varies by language). In JavaScript, also has signal option since v1.62.

PageAssertions.NotToHaveTitle method

NotToHaveTitle is an async method in Python since v1.20, opposite of toHaveTitle. Parameter: titleOrRegExp (string or RegExp), required, expected title or RegExp. Option: timeout (default varies by language).

PageAssertions.toHaveURL method

toHaveURL is an async method available in all languages since v1.20, aliased as hasURL in Java. It ensures the page is navigated to the given URL. In JavaScript, parameter url accepts string, RegExp, URLPattern, or function(URL):boolean. In Python, Java, C#, parameter urlOrRegExp accepts string or RegExp. Option: ignoreCase (boolean, since v1.44) for case-insensitive matching. Option: timeout (default varies by language). In JavaScript, also has signal option since v1.62. When Browser.newContext.baseURL is provided and url is a string, both are merged via the URL constructor for comparison.

PageAssertions.NotToHaveURL method

NotToHaveURL is an async method in Python since v1.20, opposite of toHaveURL. Parameter: urlOrRegExp (string or RegExp), required, expected URL string or RegExp. Option: ignoreCase (boolean, since v1.44) for case-insensitive matching. Option: timeout (default varies by language).

PageAssertions.toMatchAriaSnapshot method

toMatchAriaSnapshot is an async method available in all languages since v1.60. It asserts that the page body matches a given accessibility snapshot. In JavaScript (method #1), parameter expected (string) is required for the snapshot content. In JavaScript (method #2), optional parameter name (string) specifies the snapshot file name (stores in .aria.yml file). Options: timeout (default varies by language). In JavaScript, also has signal option since v1.62.

PageAssertions.NotToMatchAriaSnapshot method

NotToMatchAriaSnapshot is an async method in Python since v1.60, opposite of toMatchAriaSnapshot. Parameter: expected (string), required, the accessibility snapshot content. Option: timeout (default varies by language).

PageAssertions.toHaveScreenshot methods

toHaveScreenshot has two overloads for JavaScript since v1.23. Method #1 accepts optional parameter name (string or Array of strings) for snapshot file name (must have .png or .webp extension). Method #2 has no name parameter and stores in PNG format by default. Both methods wait until two consecutive page screenshots yield the same result before comparing. Options for both: timeout, signal (since v1.62), animations (default disabled), caret, clip, fullPage, mask, maskColor (since v1.35), stylePath (since v1.41), omitBackground, scale (default css), maxDiffPixels, maxDiffPixelRatio, threshold.

PageAssertions example - toHaveURL usage

Examples of toHaveURL assertions: await expect(page).toHaveURL('https://playwright.dev/docs/intro'); checks for exact URL with query string. await expect(page).toHaveURL(/docs?\//); uses regex. await expect(page).toHaveURL(new URLPattern({ pathname: '/docs/*' })); uses URLPattern. await expect(page).toHaveURL(url => { const params = url.searchParams; return params.has('search') && params.has('options') && params.get('id') === '5'; }); uses predicate function.

PageAssertions example - toMatchAriaSnapshot usage

Example of toMatchAriaSnapshot assertion: await page.goto('https://demo.playwright.dev/todomvc/'); await expect(page).toMatchAriaSnapshot(`\n - heading "todos"\n - textbox "What needs to be done?"\n`);

PageAssertions example - toHaveScreenshot usage

Examples of toHaveScreenshot assertions: await expect(page).toHaveScreenshot('image.png'); stores snapshot in PNG format. await expect(page).toHaveScreenshot('image.webp'); stores snapshot in WebP format. await expect(page).toHaveScreenshot(); stores in PNG format with auto-generated name. Screenshot assertions only work with Playwright test runner.

Give your agent this brain