How to Speed Up E2E Tests in CI Without Losing Confidence
Slow end-to-end pipelines delay feedback and encourage developers to batch changes or skip checks. But making a pipeline faster by removing meaningful coverage or hiding failures is a false economy. The goal is to reduce idle time and unnecessary work while preserving a reliable signal.
Measure where the time goes
Before changing CI, split total pipeline time into queue time, environment setup, dependency installation, test execution, artifact upload, and post-processing. Track median and high-percentile duration, not just the fastest run. A pipeline that is quick on an idle runner but slow under normal load is not predictable.
1. Remove unnecessary serial work
Identify jobs that do not depend on each other and run them concurrently. Keep dependency boundaries explicit so parallel jobs do not race to modify the same environment or test data. Start with independent lint, unit, and static checks where the repository and infrastructure support it.
2. Use parallel workers and sharding deliberately
Playwright supports parallel test execution and sharding across multiple CI jobs. More workers do not always mean a faster suite. Shared databases, rate limits, CPU, memory, and browser startup can become bottlenecks. Increase concurrency gradually and compare duration, failure rate, and infrastructure cost.
Sharding is most effective when test distribution is reasonably balanced. If one shard contains the longest scenarios, the whole pipeline waits for that shard. Use historical durations or a balanced test distribution where your tooling supports it.
3. Stabilize the environment
Pin runtime and browser dependencies, use reproducible CI images, and avoid downloading the same large dependency set unnecessarily. Cache package-manager data where appropriate, but do not cache mutable application state or browser profiles in ways that create cross-run contamination. A cache should improve setup time without changing test semantics.
4. Choose the right test at the right stage
Run fast, high-signal checks on every pull request. Run broader cross-browser or expensive end-to-end coverage at an appropriate stage, such as merge or scheduled validation, based on product risk. Test selection based on changed areas can help, but only if dependency mapping is trustworthy and a broader safety net remains.
5. Use API setup instead of repetitive UI setup
Where the test objective is a specific UI behaviour, create preconditions through an API or fixture when safe. This reduces time spent navigating through unrelated flows. Keep a smaller number of end-to-end tests that validate the full critical journey.
6. Preserve diagnostics
Upload traces, screenshots, videos where useful, and test reports for failures. Make artifact retention long enough to investigate intermittent failures. Removing diagnostics may shave seconds off a pipeline but can add hours to debugging.
7. Treat retries as a signal
Retries can provide evidence about intermittent failures, but report first-attempt failures and retry outcomes separately. A rising retry rate is a quality signal even when the final job is green. Avoid using retries as a substitute for fixing timing, isolation, or environment problems.
A practical optimization sequence
- Capture baseline duration, queue time, failure rate, and retry rate.
- Fix unstable tests and shared data before increasing parallelism.
- Remove redundant setup and add safe dependency caching.
- Parallelize independent jobs and tune workers in measured steps.
- Introduce sharding and balanced test distribution.
- Review the results after a representative period, including CI cost and escaped defects.
What not to optimize away
Do not remove critical user journeys just to hit a duration target. Do not turn off assertions, silently skip unstable tests, or allow a retry to overwrite the first failure. Pipeline speed is useful only when the result remains trustworthy.
For implementation details, see the Playwright CI guide and test sharding documentation.
If CI time keeps growing despite local optimizations, a focused review of your automation and CI pipeline can identify the bottlenecks and prioritize improvements.
QA AUTOMATION HEALTH CHECK
Know what to improve first.
Get an independent review of test reliability, automation architecture, and CI with prioritized findings and a practical 30-day plan.
Explore the review →