Playwright Get Started
Get Started with Playwright
To get started, you create a Node.js project with Playwright and its browsers installed.
This takes one command, and a few minutes for the download.
Requirements
Playwright runs on Node.js.
Playwright 1.65 needs Node.js version 20 or newer.
Check your Node.js version in a terminal:
Example
node --version
If you do not have Node.js, download it from nodejs.org, or read our Node.js Get Started chapter.
Playwright works on Windows, macOS and Linux.
Create a New Project
Create an empty folder for your project, open a terminal in it, and run:
Example
npm init playwright@latest
The command asks you a few questions:
- TypeScript or JavaScript? Choose JavaScript to follow this tutorial
- Where to put your end-to-end tests? Keep the default,
tests - Add a GitHub Actions workflow? Choose yes if you want your tests to run on GitHub
- Install Playwright browsers? Choose yes
Then it installs Playwright, downloads the browsers, and creates these files:
| File | Description |
|---|---|
| package.json | The Node.js project file, with @playwright/test as a dev dependency (a package you need only while you develop and test, not when the website runs) |
| playwright.config.js | The Playwright configuration: where the tests are, which browsers to use, and more |
| tests/example.spec.js | A short example test |
| .github/workflows/playwright.yml | The GitHub Actions workflow (only if you chose it) |
You can delete the example test when you have read it.
Add Playwright to an Existing Project
If you already have a Node.js project, install the Playwright test runner as a dev dependency:
Example
npm install -D @playwright/test
Then download the browsers that Playwright uses:
Example
npx playwright install
The browsers are saved in a shared folder on your computer, not in your project.
Create a playwright.config.js file yourself, like the one in the Test in Chromium Only section below.
The Config File
The generated playwright.config.js has comments that explain every setting.
The most important settings are:
| Setting | Description |
|---|---|
| testDir | The folder with your test files |
| fullyParallel | Run the tests at the same time |
| retries | How many times to try a failed test again |
| reporter | How the results are shown, for example as an HTML report |
| use | Options for every test, for example when to record a trace (a recording of the test run) |
| projects | The browsers to test in: Chromium, Firefox and WebKit |
You will learn more in the Config File chapter.
Test in Chromium Only
By default, every test runs three times: once in Chromium, once in Firefox and once in WebKit.
To keep the outputs short, this tutorial tests in Chromium only.
Replace the content of your playwright.config.js with this:
Example
playwright.config.js
// @ts-check
import { defineConfig, devices } from '@playwright/test';
export default defineConfig({
testDir: './tests',
fullyParallel: true,
reporter: 'html',
use: {
trace: 'on-first-retry',
},
projects: [
{ name: 'chromium', use: { ...devices['Desktop Chrome'] } },
],
});
The projects list now has one browser: Chromium, with the settings of a desktop Chrome browser.
You will learn how to add the other browsers in the Browsers and Projects chapter.
Check the Version
Check which version of Playwright your project uses:
Example
npx playwright --version
Output:
Version 1.65.1
This tutorial uses Playwright 1.65.
Tip: If you use Visual Studio Code, install the Playwright Test for VS Code extension from Microsoft.
It lets you run and debug tests from the editor.