Skip to Content
idomatic 1.6 adds SwiftUI, Flutter and Jetpack Compose. See what changed

Every element gets a name your tests can find.

idomatic reads the labels already in your code, like aria-label, placeholder and button text, and writes them into stable ids. On the web that's id; in SwiftUI, Flutter and Compose it's what their test tools look for. Ids you already have are never renamed.

npm init @idomatic
Read the docs
22 frameworks, web and native
Platform

Sign in

Where the name comes from

idomatic checks these in order and uses the first one it finds. Two elements that end up with the same name get -2, -3 and so on.

Native code works the same way: .accessibilityLabel, a title, labelText or contentDescription, then the text.

These labels are also an element's accessible name. If something comes out as plain div, a screen reader probably can't describe it either. Check it in your browser's accessibility panel or the Accessibility Inspector.

  1. aria-label<button aria-label="Submit login">button-submit-login
  2. name<input name="email">input-email
  3. placeholder<input placeholder="Search">input-search
  4. alt<img alt="Team photo">img-team-photo
  5. title<a title="Read more">a-read-more
  6. Text content (JSX)<h1>Sign in</h1>h1-sign-in
  7. Tag name<section>section

Works with the code you already have

Pick yours to see what it scans, what it writes and what your test looks like. Every example is real output from the parsers.

Component frameworks

Native apps

Server templates

Content

Markup that helpers build at runtime, like Rails' link_to, isn't in the file, so add those ids by hand.

React

Also Preact, Next.js, Remix

Set up
Run npm init @idomatic and choose React (JS/TSX).
Scans
.jsx.tsx.js.ts
Good to know
JSX goes through a real AST parser. Text content counts as a label. Fragments are skipped.
LoginForm.tsx
export function LoginForm() {
  return (
    <form onSubmit={signIn} id="form">
      <h1 id="h1-sign-in">Sign in</h1>
      <input name="email" placeholder="Email" id="input-email" />
      <button aria-label="Submit login" id="button-submit-login">Log in</button>
    </form>
  );
}
In Playwrightawait page.locator("#button-submit-login").click();

Make it a habit, not a cleanup

Run it once to catch up, then let CI keep it that way. New elements get their ids in the same pull request that adds them.

  1. Preview

    Lists the files that would change. Touches nothing.

    $ npx idomatic scan --dry
    [Dry Run] Would update: src/Login.tsx
    [Dry Run] Would update: ios/Login.swift
    
  2. Write

    Adds the missing ids. A second run finds nothing to do.

    $ npx idomatic scan --write
    ✅ Updated: src/Login.tsx
    ✅ Updated: ios/Login.swift
    
  3. Keep it

    Fail CI when a new element ships without one.

    # .github/workflows/ids.yml
    - run: npx idomatic scan --write
    - run: git diff --exit-code
    

Questions

Will it change ids I already have?

No. Before writing, idomatic collects every id already in the file. Those are never renamed, and new ids never collide with them. Running it twice gives the same file.

Can I use data-testid instead of id?

Yes. Set "attributeName": "data-testid" in .idomatic.config.json, or data-cy, or anything else. In Playwright you then select with page.getByTestId("button-submit-login").

What about elements rendered in a loop?

An element inside .map(), {#each} or {{#each}} is written once in the source, so every rendered copy shares one id. Scope it in your test, for example page.locator("#nav-main #a").nth(1).

Does it add ids to my own components?

Yes. In JSX, <Button> gets an id like any other element, so your component needs to pass it through to the element it renders. Add a component to excludeTags if it shouldn't get one.

Does it work for mobile apps?

Yes. React Native gets testID for Detox and Maestro. SwiftUI gets .accessibilityIdentifier for XCUITest, Flutter gets a Key for find.byKey, and Jetpack Compose gets Modifier.testTag for onNodeWithTag.

What can't it see?

Markup that only exists at runtime, such as HTML built by a helper function or a component library. idomatic only sees what is written in your files.

Try it on one folder first

Setup asks which framework you use, writes .idomatic.config.json and installs the right parser. Point excludeFiles at everything but one folder, run with --dry, and read the list.

npm init @idomatic