Reusable Hooks: Fixtures
Fixtures are used to establish an environment for each test, giving it exactly what it needs and nothing else.
Example Custom Fixture
javascript
const test = base.extend({
authenticatedPage: async ({ page }, use) => {
await page.goto('/login');
await page.fill('#user', 'admin');
await page.click('#submit');
await use(page); // Use the page in the test
},
});
Tests then simply use `authenticatedPage` instead of repeating the login steps.