How to automate online store testing: from cart to payment
Updated:
An automated online store test should confirm that a customer can complete a purchase and the system handles the outcome correctly. Clicking “Place order” and finding a thank-you page is not enough. Verify the price, payment, order status and relevant follow-up actions.
Start with a smaller number of important shopping journeys through the browser. Check combinations of discounts, quantities and invalid inputs through the API or application logic too. This makes it easier to identify the failing part of the process, without taking every variation through the entire checkout.
First agree on a correct purchase outcome
List the supported customer types, delivery options and payment methods. Define when an order is created, when stock is reserved and what permits dispatch. An order created after an unsuccessful payment is not necessarily a defect. It may correctly remain unpaid or await another attempt. A defect is a mismatch with agreed states, such as treating a declined payment as successful.
Expectations should come from product rules rather than the current application’s behaviour alone. If a test copies an incorrect cart total and compares it with the same total on confirmation, it checks consistency between screens but misses the calculation error.
Choose scenarios by their impact on customers. Record each scenario’s input data, expected state and risk it covers. Choosing a guest or signed-in account depends on the supported journeys, not on filling a list.
Assign risks to suitable test layers
| Risk | Suitable check | What to verify |
|---|---|---|
| A product cannot be purchased through the site | Browser test | Selection, cart and completion of the supported journey |
| Incorrect price or discount | Logic and API, representative UI journey | Independently calculated amount and rounding rules |
| A declined payment appears successful | API and gateway sandbox | Payment and order states, without unauthorised fulfilment |
| Duplicate order submission | API and selected UI scenario | Number of resulting operations according to the contract |
| Concurrent purchase of the last item | Controlled integration test | Reservation or rejection according to stock rules |
| Missing payment confirmation | Webhook integration test | Eventual correct state even without the customer returning |
An API is an interface for preparing data or checking server results without clicking through screens. This layer does not replace checking that a customer can find the right button and understand an error. Conversely, the browser need not exercise every combination of a pricing rule.
A hypothetical purchase with a verifiable price
The following example is a fictional test profile. One product costs EUR 20 per item, the cart contains two items and a coupon reduces the goods price by 10%. Delivery costs EUR 4 and the coupon does not reduce it. Prices already include tax, with no additional fee. These are neither a particular shop’s rules nor a statutory tax rate.
The independent expectation is EUR 40 for goods, a EUR 4 discount, EUR 36 after discount and EUR 40 including delivery. The test calculation can use integer cents. For other rules, define discount order, rounding and the free-delivery threshold separately.
The test prepares a product, stock and coupon with these properties. It verifies quantity, price and discount in the cart, then selects the agreed delivery and payment at checkout. Afterwards, it compares the order with its own expectation, including line items, currency and final state. On-page confirmation contributes evidence but is not its only source.
For a negative variation, change only the decisive condition, such as using an invalid coupon. Define whether the application blocks the purchase or continues without a discount. Rejection caused by a simultaneously missing product would not establish correct coupon validation.
Which purchase variations to add
After the basic journey, extend coverage through specific differences:
- Cart: quantity changes, item removal, sold-out stock and a price change between selection and submission.
- Customer: guest and signed-in account where supported, including address and required details.
- Coupons: valid, invalid and expired, a prohibited combination or a minimum-order threshold.
- Delivery: price changes under agreed conditions and an unavailable option for a particular address.
- Completion: double-clicking, refreshing the page and returning after interruption.
Do not automate every variation at once. Map it to a risk and choose a layer that can expose it. Cancellation, refunds or partial fulfilment belong in coverage when the product supports them and your test plan includes them.
Test the last item according to the stock contract. Two customers may receive one successful reservation and one rejection, but the system might support backorders too. Clicking simultaneously does not guarantee overlapping server operations. An integration test needs controlled concurrency or evidence that requests overlapped at the critical step.
Verify payment on the server and in the interface
A payment gateway adds redirects, customer verification and asynchronous events. Prepare success, rejection, interruption and delayed confirmation according to its documentation. Use its test mode and approved test data. For example, Stripe requires test API keys and prohibits testing with real card details.
A customer’s return to the success page is not a reliable sole proof of payment. They might pay and lose their connection before returning. Stripe Checkout therefore uses server-side payment status checks and webhooks for fulfilment. For delayed methods, checkout.session.completed alone does not mean payment has succeeded. These names belong to Stripe, so use the relevant contract for another gateway.
Also test successful payment without returning to the store and repeated confirmation of the same operation. The system should not fulfil an order twice or send duplicate warehouse instructions. Signatures, duplicates and ordering are covered in webhook testing.
Prepare isolated data and outputs
Each test needs its own accounts or identifiers, orders and, where required, stock items. An isolated Playwright context separates browser cookies and storage, but not shared server-side stock or accounts. Parallel jobs must therefore avoid uncontrolled changes to the same order.
Record created IDs and clean up only that run’s data. When a test fails, retain necessary evidence before performing the agreed cleanup. Restore the prerequisites before another run. Practical preparation is covered in E2E test data.
Route payments, email, SMS and carrier instructions through a verified test mode. Calling an environment “test” does not guarantee that it sends messages only to a capture service. Check configured accounts, keys and destination services before running, rather than only after an order is created.
Wait for the outcome and retain evidence
After an API response, an order may still await a webhook or processing job. Check an observable state within a fixed time limit. Playwright’s web assertions retry checks, while the backend needs suitable verification through an API or test output. An arbitrary long pause does not explain what the test awaited.
On failure, record the step, order and payment IDs, last known state and available trace. Distinguish an incorrect expectation, setup problem, unavailable gateway and inconsistent business state. Do not publish complete payment details or access keys in reports. Automatic retries must not discard the first evidence or create an uncontrolled second order.
How to use the suite across releases
On changes, run fast logic and API checks alongside selected important UI journeys. Schedule broader variations according to duration and risk. Reports should also show skipped scenarios and their reasons. Manual checks remain useful for a new interface, clarity and unexpected combinations.
A sandbox does not establish live gateway availability. Separately designed production store monitoring needs agreed permissions and permitted side effects. A test purchase from development should not automatically be carried into production.
Start with one supported journey, an independent price expectation and server-state verification. Add a payment failure and a critical data variation next. This builds a suite that explains problems and can grow gradually.