Automated shopping cart testing: build a browser scenario

2 min read Updated: 14.09.2026

On this page Prepare test data and a stopping point
  1. Prepare test data and a stopping point
  2. A sample product-to-cart scenario
  3. What should the test wait for?
  4. Assertions and screenshots
  5. Can an optional step hide a problem?

An automated shopping cart test should answer whether a customer can complete a defined part of the purchase journey. A useful scenario has a predictable product, unambiguous elements and a clear stopping point. In DockRay, you build it from steps in the panel without uploading a browser script.

Prepare test data and a stopping point

Choose a product intended for testing and keep it available. Use test data. Stop before creating an order or making a payment; if your store creates orders earlier in the journey, stop earlier. An ordinary button click can write data even when its label does not mention payment.

A sample product-to-cart scenario

  1. Open the product page. Enter a path within your project and check for an element identifying the product.
  2. Handle consent. If the banner appears only sometimes, make its button click optional. An absent banner should not stop the journey.
  3. Select a variant and quantity. Select an option or fill a field. Assert the field value when quantity matters.
  4. Click Add to cart. Identify the button by selector or text and wait for an element confirming that the cart has updated.
  5. Verify the outcome. Check the product row, an element count or a URL fragment. If the journey permits it, verify payment methods without confirming an order.

A selector such as [data-testid="add-to-cart"] is an example and must match your site's markup. A stable attribute is easier to maintain than an element's position in a long chain of CSS classes.

What should the test wait for?

A button that updates the cart through JavaScript usually does not reload the page. Avoid requiring navigation after every action. Use automatic waiting or explicitly wait for an element, text or the disappearance of a loading indicator. Fixed pauses are a fallback: a slower server response can outlast them.

Assertions and screenshots

DockRay can check text, the presence or absence of an element, field values, element counts, URL fragments and maximum step duration. A click alone does not verify success: add a condition that confirms its effect. Enable screenshots for steps whose successful appearance you want to inspect later.

Can an optional step hide a problem?

Use optional steps for supporting elements such as an occasional banner. Adding the product and checking the cart should remain required. Review selectors after changing your store template.

Read how to diagnose failures with screenshots and the introduction to synthetic monitoring.

Keep reading

DockRay newsletter

Application security in your inbox

Important vulnerabilities, actionable guidance and practical advice for your applications. Choose your technologies and follow what matters to your project.

  • A daily digest of new vulnerabilities, critical ones included.
  • Notifications about important updates.
  • Practical advice on application security and monitoring.

Leave empty to receive updates for every technology.

Free to subscribe. Unsubscribe with one click in any email.