TokenCap
A tool that parses JSX ASTs to extract front-end test targeting attributes (data-testid, ARIA roles, aria-label, htmlFor/id pairs) and generates index snapshots for use by AI coding agents, aiming to solve the hallucination problem caused by agents guessing DOM selectors when generating tests.
Timeline (last 90 days)
TokenCap extracts explicit test attributes (data-testid, role, aria-*, etc.) by parsing JSX AST nodes and indexes them centrally, turning how AI agents locate elements from guessing into querying.
TokenCap defines and extracts four categories of attributes in src/frontend/testIds.js: data-testid/data-test/data-cy, role, aria-label/aria-labelledby/aria-describedby, and the pairing relationship between htmlFor and input id.
TokenCap generates a component snapshot via the `tokencap make` command, and the snapshot contains the Playwright-style (getByTestId/getByRole) locator for each locator along with the source line number.
Putting ARIA attributes and test identifiers in the same index can guide AI agents to use accessibility best-practice locators when generating tests, indirectly improving component accessibility.
If the frontend's own locator attributes are chaotic (non-standard data-testid naming, incomplete ARIA), the index can only faithfully reflect the chaos and cannot automatically fix testability.
Compared with having an AI agent read the entire DOM tree or rendered HTML, the AST-based indexing approach has controllable token consumption and higher accuracy.
For teams already using AI agents to write tests, incorporating test locator attributes into the frontend index is a change with a very high return on investment.
All Facts (7)
Putting ARIA attributes and test identifiers in the same index can guide AI agents to use accessibility best-practice locators when generating tests, indirectly improving component accessibility.
50%UnverifiedTokenCap defines and extracts four categories of attributes in src/frontend/testIds.js: data-testid/data-test/data-cy, role, aria-label/aria-labelledby/aria-describedby, and the pairing relationship between htmlFor and input id.
50%UnverifiedFor teams already using AI agents to write tests, incorporating test locator attributes into the frontend index is a change with a very high return on investment.
50%UnverifiedTokenCap extracts explicit test attributes (data-testid, role, aria-*, etc.) by parsing JSX AST nodes and indexes them centrally, turning how AI agents locate elements from guessing into querying.
50%UnverifiedIf the frontend's own locator attributes are chaotic (non-standard data-testid naming, incomplete ARIA), the index can only faithfully reflect the chaos and cannot automatically fix testability.
50%UnverifiedCompared with having an AI agent read the entire DOM tree or rendered HTML, the AST-based indexing approach has controllable token consumption and higher accuracy.
50%UnverifiedTokenCap generates a component snapshot via the `tokencap make` command, and the snapshot contains the Playwright-style (getByTestId/getByRole) locator for each locator along with the source line number.
50%