Checkout Edge Cases
The happy path is the easy part. Declined cards, bank confirmations, expired codes and outages are where money is lost.
Testing what goes wrong
One test per case, from a table
for (const { card, message } of [
{ card: '4000 0000 0000 0002', message: 'Your card was declined.' },
{ card: '4000 0000 0000 9995', message: 'Your card has insufficient funds.' },
]) {
test(`shows "${message}"`, async ({ page }) => { … });
}Frames inside dialogs
3-D Secure opens a window from your bank: a dialog holding an iframe. Locate the frame through the dialog.
const bank = page.getByRole('dialog', { name: 'Confirm your payment' })
.getByTitle('Bank verification').contentFrame();
await bank.getByRole('button', { name: 'Approve' }).click();A failed payment must not create an order
Assert what did not happen too: the customer is still on the checkout page, and the cart still holds the items.
Simulate an outage
You cannot make a real provider fail on demand. Replace its response, once, then let the retry through.
await page.route('**/api/shop/orders', (route) => route.fulfill({
status: 503,
json: { error: 'Payments are unavailable.' },
}), { times: 1 });Money is compared as text on the page ("$1,049.00"). In the API it is a whole number of cents, so sums never suffer from rounding errors.
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 · 4 of 4UI + API Together →Combine the API and the browser for tests that are fast, independent and thorough.
Related exercises
- Network & APIAdvancedNetwork MockingControl network responses to test states that are hard to get from a real backend.
- FramesIntermediateNested & Multiple FramesReach a frame inside a frame, choose between identical frames, and find a frame with no title.
- Mini ShopIntermediateFirst E2E TestWrite your first full end-to-end test: a guest finds a laptop, pays, and gets a confirmation.
Read the guide: Playwright network mocking and API testing