Skip to main content
Version: 1.18

PageAssertions

The PageAssertions class provides assertion methods that can be used to make assertions about the Page state in the tests. A new instance of PageAssertions is created by calling playwrightAssertions.expect(page):

import { test, expect } from '@playwright/test';

test('navigates to login', async ({ page }) => {
// ...
await page.click('#login');
await expect(page).toHaveURL(/.*\/login/);
});

pageAssertions.not()

Makes the assertion check for the opposite condition. For example, this code tests that the page URL doesn't contain "error":

await expect(page).not.toHaveURL('error');

pageAssertions.toHaveTitle(titleOrRegExp)

Ensures the page has the given title.

await expect(page).toHaveTitle(/.*checkout/);

pageAssertions.toHaveURL(urlOrRegExp)

Ensures the page is navigated to the given URL.

await expect(page).toHaveURL(/.*checkout/);