How to parallelise your Playwright tests in your CI pipeline
If you want to be productive as a software engineer and be able to ship software, you need a reproducible feedback loop that tells you when things are broken. To achieve this we use automated tests. If our tests take a long time to run our productivity will start to slow down as well.
Today my test suite took 45 minutes to run in GitHub Actions. The tedium of waiting had got too great so I decided to do something about it. Eventually I managed to get my test time down to around 11 minutes. The main culprit for my slow test suite was my Playwright e2e tests, and the main lever for fixing them was the use of sharding. You just need to pass a --shard=x/y option to the command line where x is the shard number and y is the total number of shards. My GitHub Actions pipeline now looks something like:
jobs:
e2e:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
shard: [1/4, 2/4, 3/4, 4/4]
steps:
# ...checkout, install deps and browsers...
- run: npx playwright test --shard=${{ matrix.shard }}On reflection I should have done this ages ago! This fix was really cheap to implement, and has massively improved my developer experience. I (or my AI agents) can now ship faster with confidence - which feels great!