E2E with Playwright

Testing labIntermediate

It opens a real browser, runs the user journey and checks the result on desktop and mobile.

Steps

  1. Install Playwright: npm init playwright@latest.

  2. Write the test with role locators.

  3. Run npx playwright test.

  4. Check the report when it fails.

Example · javascript
import { test, expect } from '@playwright/test'

test('add a book', async ({ page }) => {
  await page.goto('/')
  await page.getByRole('textbox', { name: 'Book title' }).fill('My book')
  await page.getByRole('button', { name: 'Add' }).click()
  await expect(page.getByText('My book')).toBeVisible()
})
Prompt
Write a Playwright test for the journey: [..] on desktop and at a width of 390 pixels.

Sources

  1. Playwright documentation