← Back to library
Playwrightassertionsbeginnerv1.20+

Assert page title

Assert the document <title> using toHaveTitle() — retries automatically for pages with dynamic titles.

1test('page has the correct document title', async ({ page }) => {
2  await page.goto('/');
3
4  // toHaveTitle() retries until the <title> matches — handles async title updates
5  await expect(page).toHaveTitle('SnipQA — Playwright & Cypress Snippet Library');
6
7  // Regex — useful for titles with dynamic segments like counts or user names
8  await expect(page).toHaveTitle(/SnipQA/);
9
10  // After navigation, verify the title updated
11  await page.getByRole('link', { name: 'Pricing' }).click();
12  await expect(page).toHaveTitle(/Pricing/);
13});
#toHaveTitle#page title#document title#SEO