Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Some links on this page are affiliate links: if you buy through them we may earn a commission, at no extra cost to you.

Install Playwright’s test package and the browser binaries it needs, then run npx playwright test from your project directory. By default, the test runner executes the configured suite headlessly and in parallel. Use a file path, title filter, or --project option to narrow the run; use UI mode or the Inspector to investigate failures.

Set up Playwright before the first run

Playwright Test includes a test runner, assertions, isolated browser contexts, parallel execution, and reporting tools. It supports Windows, Linux, and macOS, and can run tests locally or in continuous integration (CI). The generated configuration file centralizes options such as browser projects, timeouts, retries, and reporters. See the official introduction for the installation flow.

Create a new test project

In a terminal, move to the directory where you want the project and run:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
npm init playwright@latest

Follow the prompts to choose JavaScript or TypeScript and whether to add a sample test or CI workflow. Then install the browser binaries for the Playwright version in the project:

npx playwright install

The installer and generated configuration may vary with the package version and the choices you make. Keep the generated config: it is where you can see and adjust the projects and runner defaults used by the commands below.

Install Playwright in an existing project

Add @playwright/test using your project’s package manager, then install the browsers:

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

Playwright browser binaries are version-specific: each Playwright version needs the corresponding browser versions. After upgrading the package, run npx playwright install again so the required binaries are present. The browser installation guide covers supported browsers and installation options.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Run the complete test suite

From the project root, run:

npx playwright test

This is the standard command for the configured suite. Tests run in parallel and headlessly by default, so a browser window does not appear; results are printed in the terminal. The default scope is determined by Playwright’s test discovery and your configuration, so check the config if a test file is not being picked up. More details are in the running and debugging tests guide.

A minimal test file can look like this:

import { test, expect } from '@playwright/test';

test('has title', async ({ page }) => {
  await page.goto('https://example.com');
  await expect(page).toHaveTitle(/Example Domain/);
});

Place the file where the project’s test discovery configuration expects it. The example navigates to a page and checks a user-visible property with a web-first assertion. For more reliable interactions, the writing tests guide recommends locator-based actions, such as role- or label-based locators, and assertions that wait for the expected condition. Each test receives an isolated BrowserContext.

Run only the tests you need

Use a file path or filter to reduce the scope while developing or diagnosing a failure. These forms are documented in the running tests guide and CLI reference.

Goal Command What it selects
Run one file npx playwright test tests/example.spec.ts The specified test file.
Run multiple directories npx playwright test tests/todo-page/ tests/landing-page/ Tests discovered in either directory.
Filter by filename keyword npx playwright test landing login Files matching the supplied filename patterns.
Filter by test title or regular expression npx playwright test -g "add a todo item" Tests whose titles match the pattern.
Run tests that failed on the previous run npx playwright test --last-failed The last-failed tests recorded by the runner.
Run tests at a line location npx playwright test my-spec.ts:42 The test associated with the file and line location.

Filters narrow what is run; they do not change the assertions or make a failure disappear. If a filter selects nothing, confirm the file path, test title, line number, and configured test directory.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Select a browser or device project

Playwright projects let you run the same test suite against different configured environments. By default, the runner uses all projects in the configuration. Add one or more --project options to restrict a run:

npx playwright test --project=chromium
npx playwright test --project=firefox --project=webkit

Chromium, Firefox, and WebKit projects are common choices. Playwright also documents branded Chrome and Edge channels and emulated mobile devices; availability depends on the project configuration and installed browser or channel. Consult the browser documentation when setting up a project.

Keeping assertions in the test and browser selection in projects helps make a suite portable: the same user-visible checks can run across engines or profiles, making browser-specific differences easier to spot. Running more projects means more test executions and therefore more runtime; choose the coverage that fits the purpose of the run rather than treating every local edit as a full cross-browser CI run.

Choose headless, headed, or interactive debugging

Open a visible browser window

To see the browser while running the suite, use:

npx playwright test --headed

Headed mode is useful when the visible sequence helps explain what the test is doing. It does not by itself provide the interactive timeline and inspection controls of UI mode.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Explore the run in UI mode

Start the interactive runner with:

npx playwright test --ui

UI Mode lets you step through tests and inspect what happened before, during, and after each step. It is useful when you need to locate where an assertion, navigation, or interaction diverged from expectations.

Pause at a specific test with the Inspector

Use a file and line location with --debug to open Playwright Inspector:

npx playwright test example.spec.ts:10 --debug

The Inspector provides debug logs and tools to explore locators. Choose the location that reaches the relevant test, then inspect the page and the actions around the failure. The official debugging guide describes these options.

Read the HTML report

After a run, open the report with:

npx playwright show-report

The HTML Reporter lets you filter and search results by browser, pass or failure status, skipped tests, flaky tests, errors, and individual steps. To choose a port, use the CLI option, for example:

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
npx playwright show-report --port 9323

The report is particularly useful when terminal output tells you that something failed but does not show the full sequence you need to diagnose it. Review the failing test and its steps; a retry or a green later run is not proof that the underlying cause has been fixed.

Run Playwright reliably in CI

CI runners may need operating-system packages in addition to browser binaries. To install dependencies for all supported browsers, use:

npx playwright install-deps

Or install Chromium and its dependencies together:

npx playwright install --with-deps chromium

The browser guide documents both approaches. It also describes headless-shell-only installations, which can reduce downloads in CI when a full browser channel is not needed.

The CLI exposes controls for workers, retries, sharding, reporters, failure limits, and output directories. For example:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  • npx playwright test --workers=1 runs with one worker, useful when serial execution is required by the environment or test design.
  • npx playwright test --retries=2 retries failed tests according to the configured CLI policy.
  • npx playwright test --shard=3/5 runs the third shard out of five, for distributing a suite across jobs.

These are execution controls, not fixes for flaky tests. Inspect the HTML report, compare the failed and retried steps, and address unstable assumptions or shared state in the test or application. See the CLI reference for additional options and exact behavior.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Troubleshoot common run problems

The command cannot find Playwright

Confirm you are in the project directory and that @playwright/test is installed in that project. Use the project’s package manager to install it, then run the command through npx so the local package is used.

A browser executable or library is missing

Install browser binaries for the installed Playwright version with npx playwright install. On a Linux CI image missing operating-system libraries, run npx playwright install-deps or install a specific browser with npx playwright install --with-deps chromium. If you upgraded Playwright, repeat the browser installation because browser versions are tied to the Playwright version.

The suite runs, but a test is not selected

Check that the file is within the configured test directory and that its name follows the project’s discovery pattern. For command-line filters, verify paths relative to the current directory, title spelling, and line number. If the full suite finds the test but a filtered command does not, simplify the filter and add it back incrementally.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

A test passes locally but fails in CI

Compare the project and browser used in each environment, ensure CI installed the matching browser binaries and system dependencies, and inspect the report’s failing steps. A different environment can reveal timing, state, or browser-specific assumptions; increasing retries alone may conceal symptoms without correcting the cause.

A run is slow or consumes too many resources

For a focused local check, select one file, title, or project rather than running every test in every project. In constrained environments, --workers=1 reduces concurrent execution. In CI, sharding can distribute a larger suite across jobs; balance that against the extra setup and coordination. Keep browser coverage intentional, since each configured project adds executions.

A retried test passes

Treat the result as evidence of a potentially flaky test, not a diagnosis. Use the HTML report to compare the first failure with the retry, including the steps and errors. Retries can help CI complete while surfacing intermittent failures, but they do not guarantee the test is reliable.

Or skip the browser setup

If your goal is a website screenshot rather than browser-driven test assertions, ScreenshotNeo can return an image or PDF from one GET request. It is a screenshot API and MCP server from Yorker Media; it does not replace Playwright Test for writing or executing a test suite.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

For example, using cURL:

curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp

See the ScreenshotNeo API documentation for the request parameters. In plain terms, its capture can accept cookie or consent banners and remove more than 60 known consent platforms, newsletter popups, and chat widgets before the shot; those steps can be turned off. Bot checks or CAPTCHAs, blank pages, timeouts, failed loads, and cache hits are not billed, and the response identifies the page verdict and billing status in headers. Its MCP server provides take_screenshot, get_page_info, and capture_pdf tools for AI agents using Claude, Cursor, or other MCP clients. The free plan includes 1,000 screenshots per month with no card; paid plans start at $5 for 3,000 shots.

Sign up for ScreenshotNeo’s free plan to try 1,000 screenshots a month with no card.

Frequently Asked Questions

Can I run Playwright tests without opening a browser window?

Yes. The default npx playwright test run is headless; use --headed when you want a visible browser.

How do I run a single Playwright test by its title?

Use npx playwright test -g "title text" to filter by title.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Does ScreenshotNeo run Playwright tests?

No. ScreenshotNeo captures web pages as images or PDFs; it is not a Playwright test runner.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.