πŸ’‘ If you like this website, please share it with your friends and network! πŸš€
Back to All Questions
Question 32 of 100
Framework
Beginner

What test runner and assertion library does Playwright support?

The Answer

Playwright has its own built-in test runner (`@playwright/test`) with integrated Web-First assertions via `expect`. It also works with Jest and Mocha, but the native runner is strongly recommended.

Deep Dive Explanation

The native runner's `expect` library is fundamentally different from Jest's expect β€” it is 'web-first', meaning assertions automatically retry until they pass. Jest's expect is synchronous and does not retry, making it unsuitable for async UI assertions.

example.spec.ts
// Native @playwright/test (recommended)
import { test, expect } from '@playwright/test';

test('native runner', async ({ page }) => {
  await page.goto('https://playwright.dev');
  await expect(page).toHaveTitle(/Playwright/);
  await expect(page.getByRole('heading', { level: 1 })).toBeVisible();
});

// With custom expect matchers
expect.extend({
  async toHaveNoConsoleErrors(page) {
    // custom assertion logic
  }
});