Generating integration and end-to-end tests with AI coding agents is one of the highest-leverage developer workflows. However, agents routinely fail at one specific step: guessing DOM element selectors.
An agent will write:
await page.click(".btn-primary-submit"); // Fails: Class name does not exist
In TokenCap, we solve this by parsing JSX AST nodes and extracting explicit testing attributes in src/frontend/testIds.js.
What TokenCap Indexes
- Test Identifiers:
data-testid,data-test,data-cy - Accessibility Roles:
role="button",role="navigation",role="dialog" - Screen Reader Labels:
aria-label,aria-labelledby,aria-describedby - Form Associations:
htmlForand inputidpairings
Snapshot Excerpt
When tokencap make runs, frontend components include their test locator contract:
### Component: UserBillingForm (src/components/UserBillingForm.jsx)
Testing Selectors:
- Submit Button: `getByTestId("billing-submit-button")` (line 42)
- Plan Selector: `getByRole("combobox", { name: "Billing Tier" })` (line 68)
- Card Input: `getByTestId("card-element-input")` (line 95)
With this context provided up front, coding agents generate robust, locator-accurate tests using modern accessibility best practices rather than brittle CSS path queries.
Explore the frontend indexing engine at tokencap.vansharora.app
Top comments (0)