Playwright: test the purchase, not just the button

A visible cart does not prove that someone can buy a product. Choose browser tests that protect the journeys that matter.

Pages load, but orders are not created

Imagine a release where every page opens correctly. A customer later discovers that the delivery form rejects postal codes. A test checking only whether the Buy button exists could never detect this failure.

Playwright recommends testing user-visible behavior, isolating cases and using locators based on roles or labels. Its best-practices guide helps make tests less dependent on HTML implementation details.

Build a short, valuable journey

In an example store, a test can find a product, select a variant, add it to the cart, enter delivery details and verify order creation in a test environment. External payments should use a sandbox or controlled response rather than a real charge.

Prepare data independent of previous runs. The test should not require somebody to reset stock manually. Define the expected outcome too: reaching a thank-you page may be insufficient if the order was never stored.

A failing test should provide evidence

Keep a trace, screenshot and enough context to reproduce the failure. Avoid arbitrary long sleeps; wait for a meaningful interface state. Investigate instability rather than automatically adding more retries.

Start with checkout, login and the most important contact form. Choose mobile views that reflect actual usage. A few dependable journeys checked before deployment provide a more useful signal than hundreds of checks the team has stopped trusting.