Guide
Build a testing agent with Claude Code and Playwright
One folder, one command: Claude explores a site, plans its tests, runs them with Playwright, and delivers a report backed by proof. 15 minutes to set up.
Create your tests
Run them
Keep them up to date
By stage
Who it’s for
AI writes the skeleton, the Playwright recorder supplies the real selectors, and you keep the judgment: a checkout test in about twenty minutes.
An AI assistant (ChatGPT, Claude, Gemini) writes the skeleton of a Playwright test in two minutes. The Playwright recorder then swaps its made-up selectors for the ones on your site, the AI makes the code more robust, you debug it, and the AI suggests the error cases. Plan on about twenty minutes for a full checkout flow, compared with one to two hours by hand in our experience. AI writes fast; you are the one who knows what deserves a test.
npx playwright codegen records the flow you click through by hand and gives you the real selectors.The test follows a customer’s journey in eight steps: log in, search for a product, open the first result, add it to the cart, go to the cart, fill in shipping, pay by card, and check the confirmation page.
You need Node.js, Playwright (npm init playwright@latest), an AI assistant, a test customer account, and your payment provider’s test mode. Never use a real payment in a test: the card numbers below are Stripe test cards and only work in test mode.
AI writes, Playwright corrects, you decide: five steps, from the skeleton to the error cases.
Describe the scenario to the assistant, with the data and the structure you expect:
Write a Playwright test in TypeScript for a full checkout flow.
1. Log in with test@example.com / Test1234!
2. Search for "bird cage" and open the first result
3. Add it to the cart, then go to the cart
4. Fill in shipping: Jane Smith, 12 Mine Street, Springfield 12345
5. Pay by card: 4242 4242 4242 4242, 12/30, 123
6. Check that we land on the confirmation page, with an order number
One assertion after each step, comments in English.
Here is an excerpt of what it returns:
import { test, expect } from '@playwright/test';
test('full purchase', async ({ page }) => {
await page.goto('https://shop.example');
// Login
await page.click('[data-testid="login-button"]');
await page.fill('[name="email"]', 'test@example.com');
await page.fill('[name="password"]', 'Test1234!');
await page.click('button[type="submit"]');
await expect(page.locator('[data-testid="user-menu"]')).toBeVisible();
// Search and add to cart
await page.fill('[data-testid="search-input"]', 'bird cage');
await page.press('[data-testid="search-input"]', 'Enter');
await page.locator('[data-testid="product-card"]').first().click();
await page.click('[data-testid="add-to-cart-button"]');
await expect(page.locator('[data-testid="cart-badge"]')).toContainText('1');
// … shipping and payment …
// Confirmation
await expect(page).toHaveURL(/confirmation/);
await expect(page.locator('[data-testid="order-number"]')).toBeVisible();
});
The structure is right: commented steps, an assertion after each one. But every selector is made up. There is no data-testid="login-button" on your site, unless you got lucky.
The Playwright recorder replaces them. Start it on your site, click through the flow by hand, and it writes the code as you go:
npx playwright codegen https://your-store.com
It produces selectors based on what the customer sees (a role, a label, a text), which hold up better than CSS classes:
await page.getByRole('link', { name: 'Sign in' }).click();
await page.getByLabel('Email').fill('test@example.com');
await page.getByLabel('Password').fill('Test1234!');
await page.getByRole('button', { name: 'Log in' }).click();
await page.getByPlaceholder('Search').fill('bird cage');
await page.getByPlaceholder('Search').press('Enter');
Copy these lines into the AI’s skeleton, step by step. You keep its structure and its assertions, with your site’s selectors.
Paste the test back into the assistant and ask for specific improvements:
Here is my Playwright test. Improve it:
1. One class per page (Page Object Model) to make it easier to maintain
2. A screenshot and a trace on failure, in the configuration
3. Empty the cart after the test
[your code]
The main test becomes readable, almost like a recipe:
test('full purchase', async ({ page }) => {
const account = new Account(page);
const catalog = new Catalog(page);
const checkout = new Checkout(page);
await page.goto('/');
await account.logIn('test@example.com', 'Test1234!');
await catalog.addFirstResult('bird cage');
await checkout.ship({ firstName: 'Jane', lastName: 'Smith', address: '12 Mine Street', zip: '12345', city: 'Springfield' });
await checkout.payByCard({ number: '4242424242424242', expiry: '12/30', cvc: '123' });
await expect(page.getByRole('heading', { name: /thank you for your order/i })).toBeVisible();
await expect(page.getByText(/order #/i)).toBeVisible();
});
And the screenshots move into the configuration, instead of living in each test:
// playwright.config.ts (excerpt)
use: {
baseURL: 'https://your-store.com',
screenshot: 'only-on-failure',
trace: 'on-first-retry',
},
Run the test with the browser visible:
npx playwright test checkout.spec.ts --headed
The first run almost always fails. For example:
Error: locator.click: Test timeout of 30000ms exceeded.
waiting for getByRole('button', { name: 'Add to cart' })
Open the inspector with --debug (or the UI with --ui): it shows the page at the moment of failure. You can also paste the error and the code into the assistant. On an e-commerce site, the causes are almost always the same:
/add/i).page.frameLocator(…), which AI often forgets.The fix takes a few minutes. The test passes.
The happy path is covered; what’s left is everything that should fail cleanly. Ask the assistant for five error tests, with the same classes and conventions: wrong password, out-of-stock product, empty cart, declined card, invalid ZIP code. For example:
test('a declined card shows a clear message', async ({ page }) => {
// … login, cart, and shipping as in the main test …
await checkout.payByCard({ number: '4000000000000002', expiry: '12/30', cvc: '123' });
await expect(page.getByRole('alert')).toContainText(/declined/i);
await expect(page).not.toHaveURL(/confirmation/);
});
test('an empty cart cannot be checked out', async ({ page }) => {
await page.goto('/cart');
await expect(page.getByRole('button', { name: 'Checkout' })).toBeDisabled();
});
After about twenty minutes, you have six tests: the full flow and its error cases. Next, write the ones for the journeys that bring in the most revenue.
AI writes repetitive code fast; you know what matters. The split fits in one table:
| AI does well | You do better |
|---|---|
| The structure, the imports, the setup | Choosing the journeys that matter for revenue |
| An assertion after every step, without missing one | Finding the odd cases: a customer who adds the same product a thousand times during a stock update |
| Classic error cases: empty field, invalid format | Judging whether a test is worth it: VAT, yes; a typo in a label, rarely |
| Variants of a test that works: other products, other customers | Understanding why a test fails one time in ten |
| Clues about why something fails | Keeping the whole suite consistent: naming, architecture, strategy |
The resulting test is still code. You need someone who can read it, run it, and fix it, and it will need fixing often: every page redesign and every renamed button breaks selectors. To schedule runs, keep the videos, and alert the team, you still need a CI server and some plumbing. AI can also repair a broken test: that’s self-healing, which has limits of its own.
Qanary, no-code automated testing for e-commerce, creates this flow without a single line of code: you record it in a built-in browser, you write each check in one sentence, and Qanary replays it several times a day. When a fragile selector changes, self-healing repairs the test; at the first bug, you get the video and the explanation. For the details, see functional testing.
Want to see Qanary test your site? with Julia or Antoine.
Guide
One folder, one command: Claude explores a site, plans its tests, runs them with Playwright, and delivers a report backed by proof. 15 minutes to set up.
Talk
Self-healing repairs a test when the site changes. Three approaches with AI, from the most guided to the most autonomous, and their limits (ParisTestConf 2026).
Talk
Define your critical journeys, document them in a spreadsheet, and move from reactive quality to quality you control: our talk at WordCamp Nice 2026.
Bugs only. Promise.
30 minutes, live on your site
Shall we look at your site together?