Skip to main content
This test logs in to a demo store, adds a product to the cart, and asserts that the cart has an item.

Watch it run

The test

add-to-cart.test.mjs

How it works

  • Each find() description starts with the visible label, then adds context (“Add to Cart, add to cart button under TestDriver Hat”).
  • The context tells the AI which of several identical buttons to pick.
  • performLogin() is the reusable helper from Click an icon. It reads the on-screen password with extract() and types it with secret: true.
  • assert() checks the result in plain language, not by inspecting markup.

Run it

The test is in the TestDriver SDK repository. Clone it, install dependencies, and run the file:
The test reads your API key from TD_API_KEY. Create a key at console.testdriver.ai/team/api-keys. Then set it in your environment or a .env file.