How to write a maintainable first E2E test
Quando usar: You have a staging URL and a login flow; you want one solid test before scaling.
Fluxo
-
Describe the flowWrite a Playwright test for login at staging.example.com: email, password, expect dashboard heading. Use role-based locators only.✓ Copiado→ Test using getByRole, getByLabel; no .class or xpath
-
Add auth reuse fixtureConvert the login into a reusable auth fixture so other tests skip logging in.✓ Copiado→ storageState-based fixture + globalSetup
-
Ensure non-flakinessAudit the test for waitFor* anti-patterns; switch to web-first assertions.✓ Copiado→ expect(locator).toBeVisible() rather than waitForSelector
Resultado: A robust first test plus a fixture the whole suite inherits.
Armadilhas
- Claude reaches for page.waitForTimeout — Tell skill explicitly: no arbitrary waits, use web-first assertions