← Back to library
Playwrightfixturesadvancedv1.20+

Custom fixture for logged-in page

Create a reusable fixture that provides a pre-authenticated page to every test.

1import { test as base, expect } from '@playwright/test';
2
3type MyFixtures = { loggedInPage: Page };
4
5export const test = base.extend<MyFixtures>({
6  loggedInPage: async ({ page }, use) => {
7    await page.goto('/login');
8    await page.fill('[name="email"]', 'user@test.com');
9    await page.fill('[name="password"]', 'secret');
10    await page.click('[type="submit"]');
11    await page.waitForURL('/dashboard');
12
13    // Hand the authenticated page to the test
14    await use(page);
15  },
16});
17
18export { expect };
19
20// Usage in any test file:
21// import { test, expect } from './fixtures';
22// test('dashboard loads', async ({ loggedInPage }) => { ... });
#fixture#auth#reusable#extend