Use fixtures for reliable setup
Use fixtures for reliable setup — Test an AI-built site with Playwright. Use the built-in isolated page; Create tests/fixtures.ts; Keep fixtures focused. Practical assignment: Lab evidence.
Demo edition. The materials are undergoing editorial review.
Topics covered
- Use the built-in isolated page
- Create tests/fixtures.ts
- Keep fixtures focused
Use the built-in isolated page
The page fixture belongs to a test context. Prefer it over a global page shared by tests, which can leak navigation, cookies and local storage between cases.
The target is a synthetic local site you own, using a separate browser context created by the test runner. It contains no real accounts, purchases or messages. Write assertions for visible behavior rather than for how an assistant happened to implement the page. A passing test covers only its stated cases; it does not prove complete accessibility, security or every device combination. Keep manual review for areas the suite does not exercise.
Create tests/fixtures.ts
A custom fixture opens the synthetic workshop and exposes the page. Setup runs before use; later tests import this test object rather than the unextended default.
Fixture setup failures are reported before the test body runs, which narrows diagnosis to startup or page readiness. Keep teardown inside the fixture when it allocates its own resource. Here the built-in page already owns its cleanup, so the custom fixture should not close a page owned by another test.
Save examples under the shown test paths and keep application startup separate from test execution. Use the configured baseURL instead of repeating environment-specific addresses. Let web-first assertions wait for observable results; fixed sleeps make failures slower without proving readiness. When a test fails, preserve the trace and reproduce its exact input before editing selectors. A missing accessible label is often an application defect, not a reason for a brittle CSS selector.
import {test as base,expect,type Page} from '@playwright/test';
export const test=base.extend<{workshop:Page}>({workshop:async({page},use)=>{await page.goto('/');await expect(page.getByRole('heading',{name:'Workshop demo',exact:true})).toBeVisible();await use(page);}});
export {expect};
Keep fixtures focused
The fixture verifies page readiness only. Do not hide form submission or unrelated assertions in setup; otherwise a setup failure obscures which behavior was being tested.
Keep tests independent and use only fictional inputs such as learner@example.test. Do not reuse a personal logged-in browser profile or copy production credentials into artifacts. Screenshots and traces can retain page text, requests and entered values, so inspect them before sharing. Treat a retry pass as evidence of possible flakiness, not permission to ignore the first failure. Record command, browser project and actual result when reporting coverage.
Practical assignment
Lab evidence
Continue to learning