Lorixen.
EN

Automated checkout tests with Playwright

Short answer: Your checkout is the one journey you cannot afford to break, and it is also the one most likely to be broken by an unrelated change: a theme update, a new plugin, a tweak to shipping rules. An end-to-end test drives a real browser through the journey the way a customer would and fails loudly if any step stops working. Playwright is a free, open-source tool for this. Start with one test that adds a product, fills in the checkout and pays with a test card in your payment provider's test mode, run it on every change and every night, and add cases for discount codes and declined cards next.

Why checkout needs automated tests

Manual checks before each release are better than nothing, but they get skipped when people are busy, and they rarely cover the awkward paths such as a declined card, an expired discount code or a postcode outside your delivery zone. Unit tests check individual functions but not whether the "Pay now" button still works after a front-end change.

End-to-end tests sit at the top: slower and fewer, but they test what customers actually experience. Playwright's best-practice guide sums up the philosophy as testing user-visible behaviour rather than implementation details that users will not see or know about.

What to test first

Choose a small number of journeys that represent real money:

  1. The happy path. Visit a product, add it to the cart, go to checkout, enter delivery details, pay with a test card and see the confirmation page with an order number.
  2. A declined payment. Use a card number designed to fail and check that the customer sees a clear message and can try again.
  3. A discount code. Apply a valid code and confirm the total changes; apply an invalid one and confirm the error.
  4. Shipping rules. If you deliver to some regions only, check that an excluded postcode is handled gracefully.

That is four tests. They catch most regressions that would cost you sales.

Writing tests that don't break every week

Badly written browser tests are fragile: they fail because a CSS class changed, not because checkout broke. Playwright's guidance helps avoid that:

  • Locate elements the way users do. Use role- and label-based locators such as getByRole for a button with the name "Place order" or getByLabel for "Email address", rather than CSS selectors tied to your markup. If the visible label changes, that is a change worth noticing anyway.
  • Rely on auto-waiting. Playwright performs actionability checks before each action, waiting until an element is visible, stable and ready to receive input before clicking or typing. Avoid fixed sleeps; they make tests slow and still flaky.
  • Keep tests isolated. The best-practice guide recommends that each test runs independently with its own local storage, session storage, cookies and data. A test should never depend on the cart left behind by the previous one.
  • Reuse sign-in. For journeys that need a logged-in customer, the same guide shows logging in once in a setup step and reusing the saved state, so every test does not repeat the login form.

Handling payments safely

Never use real card details in tests. Stripe's testing documentation, for example, says not to use real card details, to use test API keys instead, and gives card numbers such as 4242 4242 4242 4242 with any future expiry date and any three-digit CVC for interactive testing. It also lists cards that simulate declines for various reasons. Other payment providers offer similar sandbox modes and test numbers; use your provider's documented ones.

Run your tests against a staging environment configured with test keys, never against your live shop with live keys.

Third parties: test what you control

Checkout often touches services you do not own: address lookup, fraud screening, shipping rate calculators and analytics scripts. Playwright's guide says to avoid testing third-party dependencies and only test what you control, because external sites are slow and can change without warning.

Playwright can intercept network requests and return a custom response instead, as its mocking documentation shows. Use this to give the shipping-rate API a fixed answer in tests, so a slow external service never fails your build. Keep the payment step real but in test mode, since that is the part most worth checking end to end.

Running the tests

  • On every pull request or deploy in your continuous integration pipeline, so a broken checkout never reaches customers.
  • On a schedule against staging, for example nightly, to catch problems from content or configuration changes that did not go through code review.
  • Debugging failures: the Playwright guide recommends its trace viewer for CI failures, rather than videos and screenshots. A trace shows the timeline, each action, network requests and the page state at every step.

Keep the suite fast. Four solid checkout tests that run in a couple of minutes are more useful than fifty slow, flaky ones nobody trusts.

A worked example

A hypothetical Calgary coffee roaster sold beans and subscriptions online. A theme update moved the "Place order" button inside a new container, and a leftover script stopped it from submitting on mobile screens. It took two days and a quiet sales report before anyone noticed.

The roaster's developer added four Playwright tests: a desktop and a mobile happy path, a declined card and a discount code. They run on every deploy and nightly against staging with payment test keys, and the shipping-rate API is mocked. A later plugin update that broke the discount field was caught in the pipeline before going live.

FAQ

Do I need to be a developer to use Playwright?

Some coding is needed, but Playwright includes a code generator that records your clicks as a starting script, which a developer can then tidy up.

Can I run tests against a hosted shop platform?

Yes, against a staging or development store, as long as the platform provides a test payment mode.

How often will the tests need updating?

When the checkout genuinely changes. Role- and label-based locators keep cosmetic changes from breaking them.

If you'd like a small set of checkout tests that catch breakages before customers do, describe your shop and its checkout steps.

Sources

WhatsAppBook a call