Switch to v2 to see which selectors break.
Add to Chrome

A/B test automation practice

Practice locating elements under an A/B test. On v1 the sign-up form shows variant A; switch to v2 and it shows variant B, with new button copy, a new heading and the button moved below the field. Roles and test ids stay the same, and the variant never changes between visits. Open the shop catalog

Newsletter sign-up, A/B testedv1 shows variant A, v2 variant B.

Built well

Get release notes by email

Built to break

Get release notes by email

Subscribe

Tasks: write a locator, get a grade

1Find the sign-up button. Then switch to v2 (variant B) and check the same answer.Copy changes
2Find the email field of the sign-up form.Layout changes
How to locate A/B variants

An experiment rewrites the page under your test

Product teams test copy and layout: “Subscribe” against “Sign me up”, the button beside the field or below it. A test that finds the button by its text passes for half the users and fails for the other half, and a positional locator breaks as soon as the layout variant moves the button.

Real experiments usually assign a variant per visitor or per session, so the same test can pass and fail on consecutive runs. This page ties the variant to the release instead, so a result can be reproduced: v1 is always A, v2 is always B.

The well-built form here rewords too, because the copy is the point of the experiment. What it keeps is its structure: a labelled field, a real submit button, and test ids that both variants share.

What a stable locator looks like

Locate by role and test id, not by copy or position, and assert on the outcome rather than the wording. When a test must cover a specific variant, force it (a query parameter, a cookie or a feature-flag override) instead of hoping for it.

// Same locators for variant A and variant B
await page.getByTestId('ab-email').fill('[email protected]');
await page.getByTestId('ab-subscribe').click();
await expect(page.getByTestId('ab-result')).toHaveText('You are on the list.');

// Variant A only: page.getByRole('button', { name: 'Subscribe' })

In a real workflow

The shop catalog's "Buy now" becomes "Add to bag" on v2, like a copy experiment. Open the catalog, add a product by its card's test id, then switch to v2 and run the same steps.

COR Lens generates locators for shadow DOM, iframes and tables, and grades each one. Click the a/b variants above with it and compare its pick with yours.

Add to Chrome