Beginner Chapter 1 · 8 min read

Introduction to Playwright

Discover what Playwright is, why it stands out from Selenium and Cypress, and run your very first cross-browser test.

What Is Playwright?

Playwright is an open-source end-to-end testing framework developed and maintained by Microsoft. It lets you write tests that drive real browsers — Chromium, Firefox, and WebKit — using a single unified API. Unlike older tools that relied on browser-specific drivers, Playwright communicates with browsers over the Chrome DevTools Protocol (CDP) or equivalent, giving it direct, low-level control with exceptional reliability.

Playwright supports JavaScript/TypeScript, Python, Java, and .NET, making it accessible to almost every development team. Its auto-waiting engine, network interception capabilities, and built-in test runner (Playwright Test) make it a compelling all-in-one solution for modern web testing.

Why Choose Playwright Over Selenium or Cypress?

Selenium has been the industry standard for over a decade, but it requires separate WebDriver binaries and often suffers from flaky tests caused by manual waits. Cypress is developer-friendly but runs only in Chromium-based browsers and cannot test multiple tabs or cross-origin pages natively. Playwright addresses all of these pain points out of the box.

Tip: Playwright's auto-waiting means you almost never need to add explicit sleep() or waitFor() calls — the framework waits for elements to be ready before acting on them.
FeaturePlaywrightSeleniumCypress
BrowsersChromium, Firefox, WebKitAll (via drivers)Chromium only
LanguagesJS, TS, Python, Java, .NETManyJS/TS only
Auto-waitYesNoYes
Network mockYesLimitedYes
Multiple tabsYesYesNo
iframesYesYesLimited

Getting Started

The code examples below show a minimal "hello world" test in each supported language. Each example navigates to https://playwright.dev, asserts that the page title contains the word "Playwright", and closes the browser. This tiny test is all you need to verify that your installation is working correctly before moving on to more complex scenarios.

hello.spec.js
// hello.spec.js — your first Playwright test
import { test, expect } from '@playwright/test';

test('Playwright home page has correct title', async ({ page }) => {
  // Navigate to the Playwright website
  await page.goto('https://playwright.dev');

  // Grab the page title
  const title = await page.title();

  // Assert it contains the word "Playwright"
  await expect(page).toHaveTitle(/Playwright/);

  console.log(`Page title: ${title}`);
});
HelloPlaywright.java
import com.microsoft.playwright.*;

public class HelloPlaywright {

  public static void main(String[] args) {
    // Launch browser, create context and page
    try (Playwright playwright = Playwright.create()) {
      Browser browser = playwright.chromium().launch();
      Page page = browser.newPage();

      // Navigate and assert title
      page.navigate("https://playwright.dev");
      String title = page.title();

      System.out.println("Title: " + title);
      assert title.contains("Playwright");

      browser.close();
    }
  }
}
test_hello.py
import re
from playwright.sync_api import Page, expect

# test_hello.py — minimal Playwright test in Python

def test_has_title(page: Page):
    # Navigate to the Playwright website
    page.goto("https://playwright.dev")

    # Assert the title matches the pattern
    expect(page).to_have_title(re.compile("Playwright"))

def test_get_started_link(page: Page):
    page.goto("https://playwright.dev")
    # Click the "Get started" link
    page.get_by_role("link", name="Get started").click()
    expect(page).to_have_url(re.compile(r".*intro"))

Playwright Beginner Introduction to Playwright

Written by PV

© 2026 All Rights Reserved