Prompt
We are building a modern web stack and need end-to-end tests that won't be painful to maintain
Latest observation
If you want end-to-end tests that are actually maintainable in a modern web stack, the biggest win is designing the app and the tests together.
What makes E2E tests painful
Most E2E suites become brittle because they:
- target implementation details like CSS classes or DOM structure
- depend on arbitrary sleeps/timeouts
- test too many UI permutations in one flow
- use unstable test data or shared environments
- duplicate lots of setup logic
- don’t have clear ownership between product, QA, and engineering
What to do instead
1. Use stable selectors
Prefer selectors intended for testing:
data-testid- accessible roles/labels
- semantic HTML
Best order:
getByRolegetByLabelTextdata-testid- avoid raw class names / deep CSS selectors
Example:
await page.getByRole('button', { name: 'Save' }).click();
2. Test user behavior, not implementation
Write tests around:
- login
- create/edit/delete a record
- checkout
- permissions
- critical navigation
- error states
Avoid asserting:
- exact component layout
- every field in every form
- internal state changes
- styling details unless they’re business-critical
3. Keep flows short and focused
One test should usually prove one thing.
Good:
- “user can sign in”
- “user can create an invoice”
- “admin can invite a teammate”
Not ideal:
- one giant “happy path” that covers half the product
4. Make test data deterministic
Use:
- seeded fixtures
- API setup/teardown
- isolated test accounts
- dedicated test database or ephemeral environments
Avoid:
- relying on pre-existing shared records
- using production-like environments for all tests
- random data without cleanup
5. Prefer API setup over UI setup
If the test is about an order page, create the order via API or seed data, then use the UI to verify the user journey.
This keeps tests:
- faster
- less flaky
- easier to reason about
6. Use a page-object or helper layer carefully
A thin abstraction is helpful for repetitive actions, but don’t hide too much.
Good:
await loginPage.login('user@example.com', 'password');
await dashboardPage.openProject('Acme');
Too much abstraction can make failures hard to debug.
7. Wait on conditions, not time
Avoid sleep(2000).
Use:
- auto-waiting from the framework
- explicit waits for URL changes
- waiting for specific elements or network responses
8. Run the right test pyramid
Use E2E for:
- a few critical journeys
- cross-service integration
- business-critical regressions
Use:
- unit tests for logic
- integration tests for API/data contracts
- component tests for UI states
Don’t make E2E do all the work.
Recommended stack choices
For modern web apps, these are common and maintainable:
- Playwright for E2E
- Testing Library principles for selectors and user-centric testing
- TypeScript for test reliability
- CI parallelization with isolated test workers
- ephemeral preview environments if available
Practical conventions
Establish team-wide rules like:
- every critical page has stable test hooks
- tests must not use fixed sleeps
- each test owns its data
- flaky tests are fixed or quarantined quickly
- no test should require manual state before running
A good baseline strategy
Start with:
- 5–15 critical end-to-end tests
- one test per major user journey
- API-based setup
- accessible selectors
- isolated test environment
- CI on every merge
Then expand only when a real production bug or high-risk feature justifies it.
If you want, I can also give you:
- a Playwright project structure for maintainable E2E, or
- a sample test pattern with fixtures, page objects, and API setup.