Start from the test pyramid
An end-to-end testing strategy works when end-to-end tests are the smallest layer of the suite, not the only one. They drive a real browser against a running system, so they are the slowest tests to run and the most expensive to maintain. We give each layer one job.
When a bug can be caught lower in the pyramid, we catch it there. A validation rule with ten cases belongs in ten unit tests, with one end-to-end test proving that the form is wired to it.
- Unit tests check business rules and pure logic. They are fast and should carry most of the edge cases.
- Integration tests check a module together with its real database, queue or file storage.
- Contract tests check that an API and its consumers still agree on requests and responses, without starting both sides together.
- End-to-end tests check that a user can complete a flow in the deployed product.
Which user flows deserve an end-to-end test?
The ones where a failure costs money or trust, and where several parts of the system have to work together. For most products the list is short.
We write the list with the product owner, as sentences a user would recognize. If the product ships in Hebrew and English, as many Israeli products do, we run the main flow in both languages: right-to-left layouts break in ways an English-only suite never sees.
- Sign-up, login and password reset.
- The purchase path: cart, checkout and payment confirmation.
- The one or two actions the product exists for, such as creating a booking or sending an invoice.
- Permissions: a user of one account cannot open the data of another.
Playwright testing: the features that matter
We use Playwright for most web projects. It runs the same tests in Chromium, Firefox and WebKit, and four of its features remove most of the usual maintenance pain.
- Auto-waiting. Before clicking or typing, Playwright waits for the element to be visible, stable and enabled. Its web-first assertions retry until they pass or time out, so fixed sleeps are not needed.
- Locators by role. getByRole and getByLabel find elements the way a user or a screen reader does. Tests survive a markup refactor, and a missing accessible name shows up as a failing test.
- Traces. A trace records each action with DOM snapshots, network requests and console output. We record it on the first retry and open it in the trace viewer instead of guessing from a screenshot.
- Parallel runs. Test files run in parallel worker processes, each test gets a fresh browser context, and sharding splits the suite across several CI machines.
Test data and isolation
Most unstable suites have a data problem, not a tooling problem. Every test should create the data it needs and never depend on what another test left behind.
The tests run against an environment that can be rebuilt from scratch: a database created by migrations and seeded by code.
- Create users, orders and other records through the API or a seed script, not by clicking through the interface.
- Give each record a unique identifier so that parallel tests do not collide.
- Log in once per role, save the session with Playwright's storageState and reuse it.
- Use the sandbox or test mode of payment and messaging providers, or intercept those calls with page.route when no sandbox exists.
Run the suite on every pull request
A suite that runs once a night finds the bug after it has been merged, when nobody remembers which change caused it. We run end-to-end tests on every pull request, against a preview deployment or a build started inside the CI job, and a red run blocks the merge.
Speed decides whether this habit survives. Parallel workers and sharding keep the run short, the HTML report and the traces are stored as CI artifacts, and slower checks such as the full cross-browser run and visual comparisons move to a scheduled run. If people start merging without waiting for the result, the suite is too slow, and that is the first thing to fix.
Treat flaky tests as bugs
A test that fails one run in twenty teaches the team to press retry, and then real failures get retried too. Playwright can retry failed tests in CI, and its report marks a test that passed only on retry as flaky. We keep that report visible and treat every entry as a defect with an owner.
The usual causes are few: a fixed timeout in place of an assertion, data shared between tests, a dependency on test order, animations, or the clock and time zone of the CI machine. When a fix cannot be made the same day, we mark the test with test.fixme, open a ticket and set a date. A quarantine without a deadline is a deleted test.
Mobile device tests
For mobile web, Playwright emulates devices: viewport, user agent and touch input, using its built-in device descriptors. It is still emulation: WebKit in Playwright is the engine behind Safari, not Safari on an iPhone, so we check the critical flows on real devices before a release.
Native apps need their own tools: XCUITest on iOS, Espresso on Android, or Appium and Maestro when one suite has to cover both platforms. The strategy does not change: few flows, isolated data and a run on every pull request.