# Installation and Project Setup

Course: [Playwright](https://www.devtutorials.ai/learn/playwright) · Section: Playwright Foundations
Source: https://www.devtutorials.ai/learn/playwright/foundations/installation-and-project-setup

> System requirements, creating a project with npm init playwright@latest and its prompts, adding Playwright to an existing project, installing browsers (one at a time, with system dependencies, and where they are stored), the project files, the VS Code extension, and keeping Playwright up to date.

## Installation and Project Setup

- Before you write a test, you need a Playwright **project**.
- A project is a folder with Playwright, its browsers and a settings file.
- One command sets it all up. Then you answer four short questions.
- In this lesson, you will practise every setup command in a practice terminal.

**Simple lesson:** one command creates a ready-to-use Playwright project.

### A Real-World Example

- Priya wants to test her to-do app on her own laptop.
- She opens a terminal in an empty folder called `my-app`.
- She types `npm init playwright@latest` and presses Enter.
- She presses Enter four times to accept the default answers.
- A minute later, she has a config file, a starter test and three browsers.

Try it yourself. Click the command below, or type it. Then press Enter at each question to take the default.

- **What happened:** the command installed Playwright, wrote the files and downloaded the browsers.
- The last command ran the starter test in three browsers.

### What You Will Learn

1. What your computer needs before you start.
2. How to create a project and answer the setup questions.
3. How to add Playwright to a project you already have.
4. How to install browsers, and where they are stored.
5. What each file in a new project does.
6. How to set up VS Code.
7. How to check your version and update Playwright.

## System Requirements

- Playwright for JavaScript and TypeScript runs on **Node.js**.
- **Node.js** = the program that runs JavaScript outside the browser.
- Playwright needs a recent Node.js: the latest **22.x**, **24.x** or **26.x**.
- Check your version with `node -v`. If it is older, install the LTS version from nodejs.org.

| System | Supported versions |
|---|---|
| Windows | Windows 11 and later, Windows Server 2019 and later, or WSL |
| macOS | macOS 14 (Sonoma) and later |
| Linux | Debian 12 or 13, Ubuntu 22.04, 24.04 or 26.04 (x86-64 or arm64) |

These versions change as new systems come out. Before a big setup, check the **System requirements** part of the Installation page in the Playwright docs.

**Simple lesson:** a recent Node.js on Windows, macOS or Linux is all you need.

## Installing Playwright

### Creating a Project with npm init playwright@latest

- `npm init playwright@latest` runs Playwright's setup tool.
- `@latest` means "use the newest version".
- The tool asks four questions. On Linux, it asks a fifth one about system packages.

<figure className="plw-fig">
<svg viewBox="0 0 640 200" role="img" aria-labelledby="fig-plw-init" style={{ width: "100%", maxWidth: 640, height: "auto" }}>
  <title id="fig-plw-init">Animation: npm init playwright runs four steps in order: install the package, write the config, write a starter test, download browsers</title>
  <rect x="10" y="78" width="120" height="44" rx="10" style={{ fill: "var(--plw-term-bg)" }} />
  <text x="70" y="105" textAnchor="middle" style={{ fill: "#7ee787", fontFamily: "var(--mono)", fontSize: 11 }}>npm init playwright</text>
  <g style={{ fontFamily: "var(--sans)", fontSize: 12, fontWeight: 700 }}>
    <g opacity="0.25"><animate attributeName="opacity" values="0.25;0.25;1;1;0.25" keyTimes="0;0.1;0.15;0.95;1" dur="8s" repeatCount="indefinite" /><rect x="160" y="20" width="200" height="34" rx="8" style={{ fill: "var(--plw-blue-soft)", stroke: "var(--plw-blue)" }} /><text x="260" y="42" textAnchor="middle" style={{ fill: "var(--plw-blue)" }}>1. Install @playwright/test</text></g>
    <g opacity="0.25"><animate attributeName="opacity" values="0.25;0.25;1;1;0.25" keyTimes="0;0.3;0.35;0.95;1" dur="8s" repeatCount="indefinite" /><rect x="160" y="62" width="200" height="34" rx="8" style={{ fill: "var(--plw-green-soft)", stroke: "var(--plw-green)" }} /><text x="260" y="84" textAnchor="middle" style={{ fill: "var(--plw-green)" }}>2. Write playwright.config</text></g>
    <g opacity="0.25"><animate attributeName="opacity" values="0.25;0.25;1;1;0.25" keyTimes="0;0.5;0.55;0.95;1" dur="8s" repeatCount="indefinite" /><rect x="160" y="104" width="200" height="34" rx="8" style={{ fill: "var(--plw-purple-soft)", stroke: "var(--plw-purple)" }} /><text x="260" y="126" textAnchor="middle" style={{ fill: "var(--plw-purple)" }}>3. Write a starter test</text></g>
    <g opacity="0.25"><animate attributeName="opacity" values="0.25;0.25;1;1;0.25" keyTimes="0;0.7;0.75;0.95;1" dur="8s" repeatCount="indefinite" /><rect x="160" y="146" width="200" height="34" rx="8" style={{ fill: "var(--plw-orange-soft)", stroke: "var(--plw-orange)" }} /><text x="260" y="168" textAnchor="middle" style={{ fill: "var(--plw-orange)" }}>4. Download browsers</text></g>
  </g>
  <path d="M130 100 C145 100 145 37 158 37" style={{ stroke: "var(--plw-slate)", strokeWidth: 1.5, fill: "none" }} />
  <rect x="400" y="40" width="225" height="120" rx="12" style={{ fill: "var(--plw-win)", stroke: "var(--plw-slate)" }} />
  <text x="512" y="62" textAnchor="middle" style={{ fill: "var(--ink)", fontFamily: "var(--sans)", fontSize: 13, fontWeight: 700 }}>my-app/</text>
  <g style={{ fontFamily: "var(--mono)", fontSize: 11, fill: "var(--ink)" }}>
    <text x="420" y="84" opacity="0">package.json<animate attributeName="opacity" values="0;0;1;1;0" keyTimes="0;0.15;0.2;0.95;1" dur="8s" repeatCount="indefinite" /></text>
    <text x="420" y="102" opacity="0">playwright.config.ts<animate attributeName="opacity" values="0;0;1;1;0" keyTimes="0;0.35;0.4;0.95;1" dur="8s" repeatCount="indefinite" /></text>
    <text x="420" y="120" opacity="0">tests/example.spec.ts<animate attributeName="opacity" values="0;0;1;1;0" keyTimes="0;0.55;0.6;0.95;1" dur="8s" repeatCount="indefinite" /></text>
    <text x="420" y="138" opacity="0">+ Chromium, Firefox, WebKit<animate attributeName="opacity" values="0;0;1;1;0" keyTimes="0;0.75;0.8;0.95;1" dur="8s" repeatCount="indefinite" /></text>
  </g>
</svg>
<figcaption>One command, four steps. The folder fills up as each step finishes.</figcaption>
</figure>

### The Setup Prompts

| Question | Default | What it means |
|---|---|---|
| TypeScript or JavaScript? | TypeScript | The language of your config and test files |
| Where to put your end-to-end tests? | `tests` | The folder for test files (`e2e` if `tests` already exists) |
| Add a GitHub Actions workflow? | No | Writes a file that runs your tests on GitHub on every push |
| Install Playwright browsers? | Yes | Downloads Chromium, Firefox and WebKit now |

- Pick **TypeScript** if you are not sure. Your editor can then warn you about mistakes as you type.
- You can say no to browsers and install them later with `npx playwright install`.

### Adding Playwright to an Existing Project

- Run the same command inside a project that already has a `package.json`.
- Playwright adds itself to your `devDependencies` and writes its files next to your code.
- It never overwrites tests you already have.

### Manual Installation

- You can also install the package and the browsers yourself, in two steps:

```bash
npm install --save-dev @playwright/test
npx playwright install
```

- Then you write `playwright.config.ts` and your first test by hand.
- `--save-dev` (or `-D`) lists the package under `devDependencies`. Users of your app never download it.

**Simple lesson:** `npm init playwright@latest` sets up everything. Manual install takes two commands.

## Installing Browsers

- Playwright runs its **own** builds of each browser engine.
- Each Playwright version is tested with exact browser versions, so you download the matching ones.
- `npx playwright install` downloads Chromium, Firefox and WebKit.

### Installing a Single Browser

- Name the browser to install only that one. This saves disk space and time on CI.

```bash
npx playwright install chromium
npx playwright install firefox webkit
```

- You can also install branded browsers: `npx playwright install chrome` or `npx playwright install msedge`.

### Installing System Dependencies with --with-deps

- On Linux, browsers need some system libraries, such as fonts and graphics packages.
- `--with-deps` installs those libraries too. It needs admin rights (sudo).
- Windows and macOS do not need it. CI servers usually run Linux, so CI setups use it:

```bash
npx playwright install --with-deps chromium
```

### Where Browser Binaries Are Stored

- Browsers go into a shared cache folder, not into your project. Every project on your computer reuses them.

| System | Folder |
|---|---|
| Windows | `%USERPROFILE%\AppData\Local\ms-playwright` |
| macOS | `~/Library/Caches/ms-playwright` |
| Linux | `~/.cache/ms-playwright` |

- The `PLAYWRIGHT_BROWSERS_PATH` environment variable moves this folder somewhere else.
- Change the **System** menu in the terminal below. Then install a browser and look at the path.

If a test fails with **Executable doesn't exist**, the browsers are missing. This happens after you install or update Playwright. Run `npx playwright install` and try again.

**Simple lesson:** `npx playwright install` downloads the browsers. Add a name for one browser, and `--with-deps` on Linux.

## Project Structure

- A new project has a few files and folders. Click each one.

- The two files you edit most are `playwright.config.ts` and the files in `tests/`.
- `test-results/` and `playwright-report/` appear after your first run.

**Simple lesson:** the config says how to run tests. The `tests` folder holds them.

## Editor Setup

- Playwright works in any editor. **VS Code** has the best support.
- Install the extension **Playwright Test for VS Code**, made by Microsoft:

1. Open VS Code and click the **Extensions** icon on the left.
2. Search for **Playwright Test for VS Code**.
3. Click **Install**.
4. Open the **Testing** panel (the flask icon). Your tests appear there.

- With it, you can run one test with a click, debug with breakpoints and pick locators on the page.
- **Debugging and Tracing** shows every feature.

**Simple lesson:** install the Playwright extension in VS Code to run and debug tests with a click.

## Maintaining Playwright

### Checking the Installed Version

- `npx playwright --version` prints the version your project uses.

### Updating Playwright and Browsers

- Update in two steps. The second step matters: new Playwright versions need new browsers.

```bash
npm install -D @playwright/test@latest
npx playwright install
```

- Run `npm outdated` first to see if a newer version exists.

### Reading the Release Notes and the Release Cycle

- A new Playwright version comes out about **once a month**. Small fix versions come in between.
- Each version brings new browser builds and sometimes new features or changes.
- Read the **Release notes** page in the Playwright docs before you update. It lists anything that might break your tests.
- Update often. Small, regular updates are easier than one big jump.

Commit `package-lock.json`. It locks the exact Playwright version, so your team and CI test with the same version you do.

**Simple lesson:** update the package, then the browsers. Read the release notes first.

## Try It in Your Project

- These steps take the lesson from the lab to your own app.
- Run `npm init playwright@latest` in a copy of your project, or a new folder next to it.
- Commit the generated `playwright.config.ts`, the `tests` folder and the workflow file, but not `playwright-report` or `test-results`.
- Install the VS Code extension and run the example test from the green ▶ button.

**Simple lesson:** use one idea from this lesson on your own app this week.

## TL;DR

- You need a recent Node.js (22, 24 or 26) on Windows, macOS or Linux.
- `npm init playwright@latest` creates a full project after four questions.
- `npx playwright install` downloads browsers. Add a name for one, and `--with-deps` on Linux.
- Browsers live in a shared cache folder, not in your project.
- The config file and the `tests` folder are what you edit.
- Update with `npm install -D @playwright/test@latest`, then `npx playwright install`.

## Common mistakes

| Mistake | What happens | Fix |
|---|---|---|
| Updating the package but not the browsers | Tests fail with "Executable doesn't exist" | Run `npx playwright install` after every update |
| Installing with plain `npm install @playwright/test` | It lands in `dependencies`, so it ships with your app | Use `-D` (`--save-dev`) |
| Using `--with-deps` on Windows | Nothing extra happens. It is only for Linux | Use it on Linux machines and CI |
| Committing `test-results/` and `playwright-report/` | Your repository fills up with run files | Keep them in `.gitignore` |
| Using an old Node.js | Install fails or Playwright refuses to start | Install the current LTS Node.js |

## Check Yourself

## Exercises

## What to Remember

- Check Node.js with `node -v` before you start.
- `npm init playwright@latest` creates the project. Press Enter to take the defaults.
- `npx playwright install` gets the browsers. Use `--with-deps` on Linux.
- Edit the config and the `tests` folder. Leave the rest to the tools.
- Update the package, then the browsers.

Next: **Your First Playwright Test**
