Testing the messy real world
Stitch the workshop's patterns into one end-to-end purchase against the local /checkout.
Every lesson up to this one has isolated a single technique — a locator, a web-first assertion, a network handler, a page event. The local checkout at /checkout is where you put them all together against a flow a real user would walk through: log in, add a product, fill the form, hit Place order, land on a receipt.
There's no new API in this lesson. This is the final flow!
Finalize everything and drive things home!
Six steps, in order:
- Log in.
- Add a product to the cart.
- Navigate to
/checkout. - Fill the form.
- Place an order.
- Land on
/checkout/confirmation.
The checkout isn't picky and snowboards are cheap. Any 16-digit card (e.g.
4242 4242 4242 4242, expiry 12/26, CVC 123) will work. Use promo code
WORKSHOP10 for 10% off, payment card or invoice (invoice skips the card
fields), shipping standard or express. Just try to finalize the checkout!
Catch the order number off the wire
The order number is generated server-side and comes back in the JSON response from POST /api/checkout/:
{
"ok": true,
"orderNumber": "WS-LXFG2K1Z",
"redirectTo": "/checkout/confirmation"
}
Check if the order number is rendered correctly and the we end up on a proper confirmation page!
Build the final end-to-end purchase
Drive a complete order and assert the order number off the API response
The capstone test. One spec file, one happy path, every pattern from the workshop.
- Use the storage state from your login setup project so the test starts authenticated.
- Visit
/, add one product to the cart. - Navigate to
/checkoutand fill the form (any valid email, the test card data,standardshipping,cardpayment). - Read the
/checkoutrequest and dicover the order number. - Read
orderNumberfrom the response body and assert it starts withWS-. - Wait for
/checkout/confirmationto load, and check for correctness.
Stretch goals:
- Create variations for this checkout test (applied voucher, different shipment, etc).