Setting Up E2E Tests with GitLab CI and Playwright Made Easy
Discover how to configure GitLab CI and Playwright to run E2E tests automatically for merge requests, streamlining quality control and enhancing your development workflow.
I recently had the opportunity to explore GitLab CI and was pleasantly surprised by its simplicity, compared to GitHub Actions. While working with Playwright, I wanted to automate E2E tests to run every time a merge request is opened. This setup helps maintain code quality and streamline the development process.
Here's a step-by-step guide to configure GitLab CI and Playwright for E2E testing:
- Modify the Playwright configuration file: Edit the
playwright.config.js
file as shown below. Include thereporter
property only if you want to display unit test reports in the GitLab UI.
The reuseExistingServer
flag ensures that the local development server is reused instead of starting a new one, unless the CI environment variable is set (i.e., when running tests in GitLab CI).
- Update your
gitlab-ci.yml
file: Add the following step to set up E2E tests in GitLab CI:
This step defines an E2E test stage, which uses the Playwright Docker image and runs the tests using the yarn e2e:headless
command.
- Add the "e2e:headless" script to
package.json
:
With this configuration, GitLab CI will run E2E tests using Playwright automatically for every merge request, ensuring seamless quality control and improving your development workflow.
Published on April 25, 2023 • 2 min read