Parameterize tests
Instead of copying the same test 5 times for different inputs, run it against a data array. Two levels: test-level (forEach over cases) and project-level (different use options per project run). The forEach approach is 80% of what you need.
Test-level: forEach over a data array
The simplest pattern: loop over an array of inputs before test(). Playwright generates a separate test for each item. The test name includes the parameter so you can see exactly which case failed.
I use this when testing order status transitions — the same flow (create → update → check), different status values.
Hooks with parameterized tests
If you add beforeEach outside the loop, it runs once before the whole group. If you want hooks per iteration, put them inside test.describe() inside the loop.
Environment variables — credentials and environment switching
Never hardcode credentials in tests. Read them from environment variables. For local dev, use a .env file with dotenv. For CI, set them as repository secrets.
Project-level: different options per run
For advanced cases — testing the same feature as different user roles — you can declare a custom fixture option and override it per project. Each project runs the full suite with its own use value.