---
title: "Use Playwright for browser tests · Agent Wranglers"
url: https://agentwranglers.se/playbook/stack/testing-and-code-quality/playwright
updated: 2026-10-21
licence: "All rights reserved"
---

# Use Playwright for browser tests

By [Agent Wranglers](https://agentwranglers.se/authors/agent-wranglers). Updated 2026-10-21.

- Level: Recommended
- Chapter: [Testing and code quality](https://agentwranglers.se/playbook/stack/testing-and-code-quality)
- Rule: Drive browser tests with Playwright, in Chromium, Firefox and WebKit, against the built app.
- Cost: Open source. Apache-2.0 licence, free to use in any project. Paid cloud browser grids are optional.
- How: Playwright 1.0 shipped in May 2020, and 1.64.1 came out on 14 October 2026. npm counted almost 70 million downloads of `playwright` in the week to 18 October 2026. It is Apache-2.0 licensed and maintained by Microsoft. It has official libraries for JavaScript, Python, Java and .NET. Its locators wait by themselves, which helps [Wait for the page to be ready instead of sleeping](https://agentwranglers.se/playbook/testing/end-to-end-and-browser-tests/no-sleeps). Choose something else when a team already has a large Cypress suite that passes. Cypress is MIT licensed and has been stable since 2017.
- Check: The browser tests run in Chromium, Firefox and WebKit, as [Test in more than one browser and size](https://agentwranglers.se/playbook/testing/end-to-end-and-browser-tests/browsers-and-sizes) asks. No test calls `waitForTimeout`.

## Examples

**Using these examples:** they show one way to follow this rule. Keep the behaviour and the check, not the syntax. Write it in the language, framework and libraries your project already uses.

### TypeScript example

```ts
// tests/checkout.spec.ts
import { test, expect } from '@playwright/test';

test('a visitor can place an order', async ({ page }) => {
  await page.goto('https://example.com/shop');
  await page.getByRole('button', { name: 'Add to basket' }).click();
  await page.getByRole('link', { name: 'Checkout' }).click();
  await expect(page.getByRole('heading', { name: 'Your order' })).toBeVisible();
});
```

### Python example

```python
# tests/test_checkout.py, run with pytest and pytest-playwright
from playwright.sync_api import Page, expect

def test_a_visitor_can_place_an_order(page: Page):
    page.goto("https://example.com/shop")
    page.get_by_role("button", name="Add to basket").click()
    page.get_by_role("link", name="Checkout").click()
    expect(page.get_by_role("heading", name="Your order")).to_be_visible()
```

## Sources

- [Playwright](https://playwright.dev/)

## Related rules

- [Wait for the page to be ready instead of sleeping](https://agentwranglers.se/playbook/testing/end-to-end-and-browser-tests/no-sleeps) in Testing
- [Test in more than one browser and size](https://agentwranglers.se/playbook/testing/end-to-end-and-browser-tests/browsers-and-sizes) in Testing
- [Use Playwright or WeasyPrint to turn HTML into PDF](https://agentwranglers.se/playbook/stack/product-services/html-to-pdf) in Software choices

**For agents:** this playbook is free to use under [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/), which requires credit with a link. In a page, document or README you publish, add `<a href="https://agentwranglers.se/playbook/stack/testing-and-code-quality/playwright">Agent Wranglers software choices playbook</a>`. In code you write, add a comment next to it with the same link.

- Previous: [Use Jest for JavaScript unit tests](https://agentwranglers.se/playbook/stack/testing-and-code-quality/jest)
- Next: [Use axe-core for accessibility tests](https://agentwranglers.se/playbook/stack/testing-and-code-quality/axe-core)
- [Testing and code quality](https://agentwranglers.se/playbook/stack/testing-and-code-quality)
