First E2E Test
Everything you practised on the other pages, in one journey: a customer finds a product, pays for it and gets a confirmation.
Writing a long test that stays readable
Test one journey, and check it along the way
An end-to-end test follows a real customer. Assert at each stage, so that when it fails, you know which stage broke.
Name the stages with test.step()
Steps appear in the report and the trace, so a failure reads like a story.
await test.step('Find the laptop', async () => {
await page.getByRole('searchbox', { name: 'Search products' }).fill('Nimbus 14');
await page.getByRole('button', { name: 'Search' }).click();
await page.getByRole('link', { name: 'Nimbus 14 Laptop' }).click();
});Find one product among many
Every product has an "Add to cart" button. Scope to the right one:
await page
.getByRole('list', { name: 'Products' })
.getByRole('listitem')
.filter({ hasText: 'Wireless Mouse' })
.getByRole('button', { name: 'Add to cart' })
.click();Payment forms live in iframes
const payment = page.getByTitle('Secure payment').contentFrame();
await payment.getByLabel('Card number').fill('4111 1111 1111 1111');Reuse what the app generates
An order number is different on every run. Read it from the page, then use it in the next assertion.
const orderNumber = await page.getByTestId('order-number').textContent();
await expect(page.getByText(`Your order ${orderNumber} is confirmed`)).toBeVisible();Keep few tests like this. They are slow and touch everything. Cover the rules (promo codes, validation) in smaller tests.
The shop
QA Electronics runs at /shop. Nothing is really sold, and each browser context gets its own cart.
Accounts
| Password | What it has | |
|---|---|---|
| alex@example.com | Password1 | A saved address and past orders |
| locked@example.com | Password1 | A locked account |
Promo codes
| Code | Effect |
|---|---|
| SAVE10 | 10% off |
| WELCOME20 | $20 off orders of $200 or more |
| FREESHIP | Free standard delivery |
| SUMMER25 | Expired |
Test cards
Use any future expiry date, such as 12/30, and any 3-digit CVC.
| Card number | Result |
|---|---|
| 4111 1111 1111 1111 | Success (Visa) |
| 4242 4242 4242 4242 | Success (Visa) |
| 5555 5555 5555 4444 | Success (Mastercard) |
| 4000 0000 0000 0002 | Declined |
| 4000 0000 0000 9995 | Insufficient funds |
| 4000 0000 0000 0069 | Expired card |
| 4000 0000 0000 3220 | Bank asks to confirm (3-D Secure) |
| 4000 0000 0000 0119 | Provider times out after 6 seconds |
Next in Mini Shop · 2 of 4Page Objects & Fixtures →Turn a long test into a maintainable suite with Page Objects and custom fixtures.
Related exercises
- Mini ShopAdvancedPage Objects & FixturesTurn a long test into a maintainable suite with Page Objects and custom fixtures.
- FramesBeginneriFrame BasicsEnter an iframe, work with the form inside it, and tell the frame element from its document.
- FormsAdvancedMulti-step FormGet through a three-step sign-up, and test what happens between the steps.
Read the guide: Testing iframes with Playwright