Define the right test pyramid

Aim for more unit and integration tests than UI tests. UI automation should focus on revenue or mission critical flows, not every screen.

Design for testability

  • Use stable accessibility IDs or test tags for selectors.
  • Keep business logic out of UI layers.
  • Mock network responses for predictable scenarios.

Use the page object pattern

Encapsulate UI actions and selectors into reusable objects. This reduces the cost of UI changes and keeps tests readable.

Reduce flakiness

  • Avoid fixed sleeps; use idling resources or synchronized waits.
  • Run tests on a clean state and reset data between runs.
  • Quarantine unstable tests before they block releases.
A smaller, stable UI suite beats a massive suite that fails randomly.

Run tests continuously

Integrate UI tests into CI with device cloud coverage and clear reporting. Use parallel execution for speed and track flaky tests as a quality metric.