DEV Community

Cover image for How to Install Playwright: The Ultimate End-to-End Testing Guide
Pratham Rathod
Pratham Rathod

Posted on

How to Install Playwright: The Ultimate End-to-End Testing Guide

How to Install Playwright: The Ultimate End-to-End Testing Guide

Learn how to install Playwright and set up your first end-to-end testing environment for modern web applications. This comprehensive guide walks you through the installation process using npm, yarn, or pnpm, ensuring a seamless setup for TypeScript or JavaScript projects. Discover how to configure browser binaries for Chromium, WebKit, and Firefox, and leverage the powerful VS Code extension for efficient test development. We cover everything from initializing your project with the playwright.config.ts file to executing your first example test. Explore advanced features like the HTML Test Reporter for detailed debugging, UI Mode for live time-travel debugging, and GitHub Actions integration for continuous integration pipelines. Whether you are working on Windows, Linux, or macOS, this tutorial provides the essential steps to get your automation suite running quickly. We also detail system requirements, including Node.js compatibility and OS support, to ensure your environment is fully optimized for testing success. By following these steps, you will master parallel execution, headless browser testing, and native mobile emulation. Start your journey into reliable, high-performance web testing with Playwright today and streamline your QA workflow with the industry’s most robust automation framework. Elevate your development standards now with our expert installation guide.

Introduction

Playwright Test is an end-to-end testing framework for modern web applications. It provides a unified solution for testing across Chromium, WebKit, and Firefox with support for parallelization, native mobile emulation, and CI/CD integration.


System Requirements

  • Node.js: 22.x, 24.x, or 26.x.
  • OS:
    • Windows 11+ or Windows Server 2019+ (or WSL).
    • macOS 14 (Sonoma) or later.
    • Debian 12/13, Ubuntu 22.04/24.04/26.04 (x86-64 or arm64).

Installation

Run the following command to initialize a new project or add Playwright to an existing project:

npm init playwright@latest
Enter fullscreen mode Exit fullscreen mode

Configuration Prompts

During installation, you will be prompted to configure the following:

  • Language: TypeScript (default) or JavaScript.
  • Test Folder: Name of the directory (default: tests or e2e).
  • GitHub Actions: Recommended for CI integration.
  • Browser Install: Automatically download required binaries (recommended).

Project Structure

Playwright creates the following scaffold:

File/Folder Purpose
playwright.config.ts Global configuration (browsers, timeouts, reporters).
tests/ Directory containing your test specifications.
package.json Project dependencies and scripts.

Running Tests

Execute tests using the Playwright CLI. By default, tests run in parallel in headless mode across all configured browsers.

Execution Commands

Task Command
Run all tests npx playwright test
Run specific file npx playwright test tests/example.spec.ts
Run in headed mode npx playwright test --headed
Run specific browser npx playwright test --project=chromium
Open UI Mode npx playwright test --ui

HTML Reports

After execution, generate and view the detailed HTML report:

npx playwright show-report
Enter fullscreen mode Exit fullscreen mode

Maintenance

Updating Playwright

To update the framework and ensure browser binaries are synchronized:

# Update dependency
npm install -D @playwright/test@latest

# Update browser binaries
npx playwright install --with-deps
Enter fullscreen mode Exit fullscreen mode

Version Check

Verify your current installation:

npx playwright --version
Enter fullscreen mode Exit fullscreen mode

Key Features

  • UI Mode: Use npx playwright test --ui for watch mode, live step-by-step debugging, and time-travel inspection.
  • Configuration: Edit playwright.config.ts to adjust retries, global timeouts, and environment-specific settings.
  • Cross-Browser: Supports Chromium, Firefox, and WebKit out of the box.

Top comments (1)

Collapse
 
codingwithjiro profile image
Elmar Chavez

I haven't had the experience in integrating playwright yet in my projects. Thanks for this informative article.