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.

Open the shop

Accounts

EmailPasswordWhat it has
alex@example.comPassword1A saved address and past orders
locked@example.comPassword1A locked account

Promo codes

CodeEffect
SAVE1010% off
WELCOME20$20 off orders of $200 or more
FREESHIPFree standard delivery
SUMMER25Expired

Test cards

Use any future expiry date, such as 12/30, and any 3-digit CVC.

Card numberResult
4111 1111 1111 1111Success (Visa)
4242 4242 4242 4242Success (Visa)
5555 5555 5555 4444Success (Mastercard)
4000 0000 0000 0002Declined
4000 0000 0000 9995Insufficient funds
4000 0000 0000 0069Expired card
4000 0000 0000 3220Bank asks to confirm (3-D Secure)
4000 0000 0000 0119Provider times out after 6 seconds