You click a button to turn on a lamp. The button works, but the lamp stays off. A test that stops after the click misses this bug.
Reading example. Reading Desk is a fictional app. You can read this example here. The exercise below uses a different app.
import { test, expect } from '@playwright/test';
test('turning on the lamp changes its status', async ({ page }) => {
await page.goto('/');
const button = page.getByRole('button', { name: 'Turn on lamp' });
await button.click();
await expect(page.getByRole('status')).toHaveText('Lamp on');
});
importbrings intestto name the test andexpectto check a result.- The test name says what should happen. Playwright gives the test a browser tab called
page. page.goto('/')opens the app. The wordawaittells the test to wait.getByRolefinds an element by its purpose. Here it finds the button named “Turn on lamp”.click()presses that button.- The status element tells the reader whether the lamp is on. The last line checks its text. If it still says “Lamp off”, the test fails.
Your exercise. In Nimbus, submit the login form with both fields empty. Check that Email shows an error. Check that Password shows an error too.
These lessons assume you can write a simple loop. If you cannot, start with the JavaScript guide to loops. Come back when you can read each value in a list.
You can try the shop exercise for free. The subtotal forgets the quantity.
Continue with the free Playwright lesson Choose data that exposes a bug.
Remember this. After an action, check what the user should see.