October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsPC HealthRecommendedCrashes, freezes, slowdowns? Check your PC nowSpot repairable issues before they interrupt work.Check PCOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk8 min

How to Test Modern Web Applications with Playwright

A practical Playwright guide to installation, reliable tests, browser and device coverage, debugging, CI setup, and common failures.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Playwright Test gives you an end-to-end test runner, browser automation, assertions, fixtures, parallel execution and debugging tools in one framework. To test a modern web app reliably, install it with your project, write tests around user-visible behavior, isolate test data, define the browser and device coverage you support, and run a reproducible suite in CI. This guide walks through that workflow, including how to diagnose failures.

Install Playwright and run a first test

Playwright Test supports Chromium, Firefox and WebKit on Windows, Linux and macOS, with mobile-device emulation. It is a framework for end-to-end testing, not just a browser automation library: the runner, assertions, fixtures, isolation, parallel execution and reporting are integrated. See the official installation guide for current package-manager and runtime instructions.

As an Amazon Associate I earn from qualifying purchases.

From your project directory, use the official initializer for your package manager. For npm, the interactive setup command is:

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

Choose JavaScript or TypeScript, a test directory, and whether to add a CI workflow. The setup installs the package and can install browser binaries. If you need to install browsers separately, run:

npx playwright install

Then run the generated tests with:

npx playwright test

Use the package manager and commands that match your repository; the official guide covers supported initialization options. The installed Playwright package and browser binaries should be kept aligned, as described in Playwright’s browser documentation.

A minimal test

Playwright Test supplies the page fixture. It opens an isolated page for the test and manages its setup and teardown.

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

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

Replace the URL and expectation with an outcome that matters to your application. A title check is a useful starter, but meaningful end-to-end coverage should also exercise user actions and verify the resulting state.

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

Write reliable tests with locators and web-first assertions

Prefer locators that describe how a person identifies an interface element: its accessible role and name, its label, or visible text. For example:

await page.getByRole('button', { name: 'Save changes' }).click();
await expect(page.getByText('Changes saved')).toBeVisible();

When a test needs a deliberate automation hook rather than user-facing semantics, use a test ID the team has explicitly chosen to maintain:

await page.getByTestId('account-menu').click();

Selectors that depend on incidental DOM structure—such as a chain of nested elements or a styling class—are more likely to break when the interface is refactored, even if user behavior has not changed. Playwright calls locators the central piece of its auto-waiting and retry-ability. Before an action such as a click, it checks that the target is uniquely matched and meets relevant action conditions, including visibility, stability, receiving events and being enabled. See Playwright’s best practices and the actionability guide.

Assert the eventual state

Use web-first assertions such as toBeVisible(), toHaveText() and toHaveURL(). They wait and retry for the expected state instead of reading a value once and immediately comparing it. For example:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
await page.getByRole('button', { name: 'Sign in' }).click();
await expect(page).toHaveURL(//dashboard/);
await expect(page.getByRole('heading', { name: 'Dashboard' })).toBeVisible();

A fixed sleep is usually a poor default synchronization strategy: it can waste time when the app is fast and still fail when it is slow. Waiting for a meaningful UI state is clearer. Auto-waiting does not make every test reliable by itself; unstable test data, shared accounts, external services, race conditions and interference between parallel tests can still create flaky outcomes.

Manage setup and test data with fixtures

The built-in page fixture gives a test a page, while context represents its browser context. Playwright prepares only the fixtures a test requests and tears them down afterward; the page fixture is isolated for each test. This supports independent tests that do not inherit stray cookies, tabs or browser state from another test. Read the fixture documentation for built-in and custom fixtures.

Use custom fixtures for reusable setup

Put repeated setup behind a fixture when it makes tests clearer—for example, constructing a test helper or preparing an authenticated state. Keep fixture scope no broader than necessary, and keep data predictable. If multiple tests mutate the same account or record, they can interfere even when their browser pages are isolated.

For tests that need a signed-in user, decide whether the test should verify the sign-in flow itself or begin from an authenticated state. Keep those purposes separate where practical: one test can cover signing in, while other tests reuse prepared authentication state to focus on their own behavior. Follow Playwright’s guidance for the chosen authentication approach in the authentication documentation.

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

Choose browser and device projects deliberately

Projects let one configuration run the same suite with different browsers, devices or settings. Start with environments that represent your product’s actual support commitments, rather than assuming that success in one local browser is enough. Playwright offers Chromium, Firefox and WebKit projects, branded Google Chrome and Microsoft Edge options, and emulated mobile devices. The browser guide distinguishes browser options; the emulation guide explains device and environment emulation.

A representative configuration might look like this:

import { defineConfig, devices } from '@playwright/test';

export default defineConfig({
  testDir: './tests',
  projects: [
    { name: 'chromium', use: { ...devices['Desktop Chrome'] } },
    { name: 'firefox', use: { ...devices['Desktop Firefox'] } },
    { name: 'webkit', use: { ...devices['Desktop Safari'] } },
    { name: 'mobile-chrome', use: { ...devices['Pixel 7'] } },
  ],
});

Project names and device descriptors should match those available in the Playwright version installed in your repository. This example is a starting point, not a claim that these four configurations are right for every application. Each added project increases the amount of work a run performs, so prioritize browsers and devices based on the users and support commitments you need to cover.

Do not confuse Chromium with branded Chrome

Playwright’s open-source Chromium build is not the same browser build as branded Google Chrome. If your application depends on browser-specific behavior, decide whether a Chromium project is adequate or whether you also need to exercise Chrome or Edge. Playwright downloads browser revisions associated with its release; after updating the package, rerun the browser installation command so the expected binaries are available.

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

Projects can vary more than browsers

Projects can also apply different settings, including timeouts and device or environment options. Teams can use separate projects for scenarios such as staging versus production, or logged-in versus logged-out behavior, when doing so makes the test matrix easier to understand. Avoid multiplying projects without a clear coverage reason.

Run locally and debug failures

Tests run headless by default. For interactive investigation, use headed mode, UI mode or the Inspector. The HTML report helps filter outcomes and inspect test details. See the test-running guide, UI mode and the Playwright Inspector guide.

Useful local commands

# Run the full suite
npx playwright test

# Run a named test file
npx playwright test tests/account.spec.ts

# Run only one configured project
npx playwright test --project=chromium

# Run with a visible browser
npx playwright test --headed

# Open interactive UI mode
npx playwright test --ui

# Open the HTML report after a run
npx playwright show-report

Use UI mode or the Inspector to step through a test and explore locators while the page is open. A failure is often easier to understand when you identify the first incorrect state: the navigation that did not complete, the control that was not actionable, or the assertion that never became true.

Use traces to investigate CI failures

Playwright’s guidance recommends the Trace Viewer for CI failure investigation instead of relying on video or screenshots alone. A trace provides a timeline, DOM snapshots around actions and network-request information. Recording traces for every test can add performance and storage cost; the documentation recommends collecting a trace on retry in CI, then using local tracing when actively debugging. See the Trace Viewer guide and the best practices page.

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.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Run Playwright in CI reproducibly

A reliable CI run needs the project dependencies, matching Playwright browser binaries and required operating-system dependencies. The basic sequence is: install Node dependencies from the lockfile, install browsers and OS dependencies, then run the tests. The exact syntax depends on your package manager and CI environment; consult the current official CI guide for provider-specific examples.

# Example sequence for a Linux CI job using npm
npm ci
npx playwright install --with-deps
npx playwright test

Playwright recommends starting with one worker in CI for stability and reproducibility. Add workers only when the runner has sufficient resources and the suite’s data and services tolerate concurrent work. If the suite needs to span multiple CI jobs, sharding distributes tests across jobs; each job must be configured as part of the same run. Preserve useful artifacts such as HTML reports and traces so failures can be investigated after the job ends.

Troubleshoot common Playwright problems

  • Browser executable is missing or does not launch: the installed package may expect browser binaries that are not installed or no longer match its version. Run npx playwright install after installing or updating Playwright; on Linux CI, use the documented dependency installation flow.
  • A click times out: check whether the locator matches exactly one element and whether the element is visible, stable, enabled and able to receive events. Inspect overlays, disabled states and duplicate labels; prefer a locator tied to the intended control.
  • An assertion times out: inspect the actual UI state and determine whether the expected state is wrong, the preceding action failed, or an application dependency is slow or unavailable. Assert on the relevant eventual state rather than adding an arbitrary sleep.
  • A test passes alone but fails in the suite: look for shared mutable test data, accounts or external dependencies, and for tests that assume execution order. Isolate or reset data and avoid relying on another test’s side effects.
  • A test fails only in CI: confirm CI installed the lockfile dependencies and matching browsers, and inspect the trace for timing, network or DOM differences. Begin with conservative worker settings before scaling concurrency.
  • It passes in Chromium but fails in another project: inspect the browser-specific trace and decide whether the failure reveals a real compatibility issue or an unsupported test assumption. Keep coverage aligned with the environments the product claims to support.

Capture a screenshot without writing a browser test

If you only need a page image or PDF—not an interactive end-to-end test—ScreenshotNeo is a separate website screenshot API and MCP server for developers. It is not a replacement for Playwright’s assertions, fixtures or browser projects. A single request can capture a URL; see the ScreenshotNeo API documentation for parameters and response details.

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

ScreenshotNeo removes supported cookie/consent banners, newsletter popups and chat widgets before capture, and those steps can be turned off. Bot checks or CAPTCHAs, blank pages, timeouts, failed loads and cache hits are not billed; response headers report the page verdict and billing status. Its MCP server provides take_screenshot, get_page_info and capture_pdf tools for AI agents and MCP clients. The free plan includes 1,000 shots per month without a card; paid plans start at $5 for 3,000 shots.

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.

Sign up for 1,000 free screenshots a month, with no card required.

Frequently Asked Questions

Does Playwright Test support TypeScript?

Yes. The official initializer lets you choose JavaScript or TypeScript for a project.

Can Playwright run tests on mobile browsers?

It supports emulated mobile device configurations; emulation is not the same as testing on every physical device.

Is Playwright only useful for end-to-end tests?

This guide covers Playwright Test’s integrated end-to-end workflow; the framework also provides browser automation and debugging tools.

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

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.

Leave a Reply

Your email address will not be published. Required fields are marked *

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

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
PC Slower Than It Used to Be?Free scan - under a minute
Crashes, No Sound, or Screen Glitches?Free driver scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.