Testing the messy real world
Combine everything you learned into one end-to-end purchase using the local /checkout.
Every lesson so far focused on a single technique. You've learned about locators, web-first assertions, network handlers, and page events. Now you'll put them all together in the local checkout at /checkout, a flow a real user would walk through: log in, add a product, fill out the form, hit Place order, and land on a receipt.
There's no new API in this lesson. This is the final flow!
Put it all together and bring it home!
There are six steps:
- Log in.
- Add a product to the cart.
- Navigate to
/checkout. - Fill out 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 complete the checkout!
Catch the order number from the network response
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 that the order number is rendered correctly and that you end up on the confirmation page!
Build the final end-to-end purchase
Complete an order and assert it's correct
The final test is one spec file with one happy path that uses 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 out the form (any valid email, the test card data,standardshipping,cardpayment). - Read the
/checkoutrequest and discover the order number. - Read
orderNumberfrom the response body and assert it starts withWS-. - Wait for
/checkout/confirmationto load and check that the page shows the right order.
Stretch goals:
- Create variations for this checkout test (an applied promo code, a different shipping method, etc.).