Install Playwright Packages, Browsers & CI Setup
In this article
This guide walks you through manually installing Playwright packages, downloading its browser binaries, and configuring it for continuous integration (CI) environments. You'll learn the exact commands and configuration steps needed to get Playwright running locally and in a CI pipeline, without relying on automatic setup scripts.
What You'll Need
- Node.js (version 18 or later) and npm installed on your machine.
- A code editor or terminal access.
- For CI: a GitHub, GitLab, or other CI platform account with a project you can modify.
- Basic familiarity with command-line tools and YAML configuration files.
Step-by-Step
- Initialize your project (if not already done). Open a terminal in your project directory and run
npm init -yto create apackage.jsonfile. This is where Playwright dependencies will be recorded. - Install the Playwright library. Run
npm install @playwright/test(for the test runner) ornpm install playwright(for the library only). The@playwright/testpackage includes the test runner and is recommended for most projects. - Install browser binaries manually. Normally, Playwright downloads browsers during installation. To do it manually, run
npx playwright installto download all supported browsers (Chromium, Firefox, WebKit). To install a specific browser, usenpx playwright install chromium(orfirefox,webkit). - Install system dependencies (Linux only). If you're on Linux, you may need additional system packages for browsers to run. Run
npx playwright install-depsto install them automatically (requires sudo). Alternatively, consult the Playwright documentation for a manual list. - Verify installation. Create a simple test file (e.g.,
test.spec.js) with a basic test that opens a page and checks a title. Runnpx playwright testto confirm everything works. If you're not using the test runner, you can run a Node script that launches a browser and navigates to a URL. - Configure CI environment variables (optional but recommended). Set
PLAYWRIGHT_BROWSERS_PATH=0to force Playwright to install browsers into the default cache location, which is often required in CI. Alternatively, set it to a custom path if you need to control where browsers are stored. - Create a CI pipeline configuration. For GitHub Actions, create a
.github/workflows/playwright.ymlfile. For GitLab CI, create a.gitlab-ci.ymlfile. The configuration should include steps to: checkout the code, set up Node.js, install dependencies (npm ci), install Playwright browsers (npx playwright install --with-deps), and run tests (npx playwright test). - Cache Playwright browsers in CI (to speed up runs). In your CI configuration, add a caching step for the Playwright browser cache. For GitHub Actions, use the
actions/cacheaction with a path like~/.cache/ms-playwright. This avoids re-downloading browsers on every run. - Run your CI pipeline. Commit your changes and push to your repository. The CI pipeline should trigger. Monitor the logs to ensure browsers install correctly and tests pass.
Common Mistakes
- Forgetting to install browsers. Installing the npm package alone does not download browsers. You must run
npx playwright install. - Using
npm installinstead ofnpm ciin CI.npm ciis faster and more reliable for CI environments because it installs exact versions from the lockfile. - Not setting
PLAYWRIGHT_BROWSERS_PATHin CI. Some CI environments have restricted permissions, and without this variable, browsers may not install correctly. - Ignoring system dependencies on Linux. If you skip
install-deps, browsers may crash with missing library errors. - Running tests from the wrong directory. Ensure your CI configuration runs tests from the project root where
playwright.config.jsis located.
Tips
- Use a specific Playwright version. Pin your Playwright version in
package.jsonto avoid unexpected changes when browsers are updated. - Run
npx playwright install --with-depsin CI. This installs both browsers and system dependencies in one command, simplifying your pipeline. - Set a timeout for browser installation in CI. If your CI has a default timeout, increase it to accommodate browser downloads (they can take several minutes).
- Use the Playwright Docker image for CI. If your CI supports Docker, using
mcr.microsoft.com/playwrightas the base image pre-installs browsers and dependencies, saving time. - Keep your test configuration separate. Use
playwright.config.jsto define test directories, browsers, and retries, so your CI file stays clean.
Troubleshooting
- Browser fails to launch with missing libraries. Run
npx playwright install-depson your local machine or in CI. If you're on a custom Linux distribution, manually install the required packages from the Playwright docs. - Tests fail due to timeout when launching browser. This often happens when browsers are not fully downloaded. Delete the cache folder (
~/.cache/ms-playwright) and re-runnpx playwright install. - CI says “browser executable doesn’t exist”. Ensure you ran
npx playwright installin the CI step before running tests. Also verify thePLAYWRIGHT_BROWSERS_PATHis set correctly if you customized it. - Permission errors when installing browsers in CI. Set
PLAYWRIGHT_BROWSERS_PATH=0to use the default cache, or specify a writable directory like/tmp/playwright. - npm install fails with EACCES. This is a file permission issue. Avoid using
sudowith npm; instead, fix the directory ownership or use a node version manager.
Frequently Asked Questions
Do I need to install browsers for every project?
Yes, each project that uses Playwright needs its own browser installation, unless you set a shared PLAYWRIGHT_BROWSERS_PATH to a common location.
What is the difference between playwright and @playwright/test?
The playwright package provides the core automation library. @playwright/test includes the library plus a test runner with assertions, fixtures, and parallel execution.
Can I install only Chromium to save disk space?
Yes, use npx playwright install chromium. You can also configure which browsers to use in your test configuration.
How do I update Playwright to a new version?
Run npm install @playwright/test@latest to update the package, then run npx playwright install to download any new browser versions.
Why does my CI pipeline take so long on the first run?
Because it downloads browsers and dependencies. Caching the Playwright browser cache and using npm ci will speed up subsequent runs.
Can I use Playwright without a test runner?
Yes, you can write plain Node.js scripts using the playwright library. However, the test runner provides better reporting and debugging tools.