Getting Started with Playwright: Installation, Setup, and Running Tests

Last updated on: February 25, 2025

Notesly Team

School Student

Share :

1. Introduction

Overview of Playwright and its Benefits

  1. What is Playwright?
  2. A modern, open-source end-to-end testing framework developed by Microsoft. Supports Chromium, Firefox, WebKit, and Electron for cross-browser testing.
  3. Key Benefits:
  4. Single API for all browsers.
  5. Auto-waiting for elements, network interception, and mobile emulation.
  6. Built-in test runner, parallel execution, and CI/CD integration.
  7. Supports TypeScript, JavaScript, Python, and .NET.

2. System Requirements

Hardware, Software, and Dependencies

  1. Hardware:
  2. Minimum: 4GB RAM, 2-core CPU.
  3. Recommended: 8GB RAM, 4-core CPU (for parallel testing).
  4. Software:
  5. Node.js v14+ (required for JavaScript/TypeScript).
  6. Python 3.7+ (for Python support).
  7. .NET SDK (for .NET support).
  8. Supported OS: Windows 10+, macOS 10.14+, Linux (Ubuntu 18.04+).

3. Installing Playwright

Step-by-Step Installation

  1. Install Node.js:
  2. Download from nodejs.org.
  3. Initialize a Project:
mkdir playwright-demo && cd playwright-demo
npm init -y
  1. Install Playwright:
npm init playwright@latest
  1. Follow prompts to configure (e.g., TypeScript vs. JavaScript).
  2. Verify Installation:
npx playwright --version

4. What’s Installed?

Breakdown of Components

  1. Browsers: Chromium, Firefox, WebKit (installed in ~/cache/ms-playwright).
  2. Tools:
  3. playwright: Core library.
  4. playwright/test: Test runner.
  5. playwright-cli: Command-line tools.
  6. Dependencies:
  7. browser binaries, test runner, and device descriptors for mobile testing.

5. Running the Example Test

Executing the Default Test

  1. Run Tests:
npx playwright test

  1. Terminal Output:
  2. Passed/failed tests.
  3. Links to HTML reports.
  4. Screenshots on failure.

6. HTML Test Reports

Generating and Understanding Reports

  1. Generate Report:
npx playwright show-report

  1. Navigate Results:
  2. Test Suites: Grouped by files.
  3. Status: Passed/Failed/Skipped.
  4. Traces: Screenshots, network logs, and execution timelines.

7. Running the Example Test in UI Mode

Interactive Debugging

  1. Launch UI Mode:
npx playwright test --ui
  1. Features:
  2. Live browser preview.
  3. Edit tests while running.
  4. Inspect elements and console logs.

8. Updating Playwright

Safely Updating Versions

  1. Update Packages:
npm update playwright
  1. Reinstall Browsers:
npx playwright install
  1. Check Version:
npx playwright --version

Recap and Next Steps

  1. Playwright simplifies cross-browser testing with a unified API.
  2. Explore advanced features like custom reporters, CI/CD integration, and API testing.
  3. Next Steps: Write custom tests, integrate with GitHub Actions, or explore Playwright’s mocking capabilities.

Important Commands Cheat Sheet

Action
Install Playwrightnpm init playwright@latest
Run Testsnpx playwright test
Generate HTML Reportnpx playwright show-report
UI Modenpx playwright test --ui
Update Playwrightnpm update playwright
Install Browsersnpx playwright install
Check Versionnpx playwright --version