feat(config): add locators.visible as the default visible for screen queries (ENG-1487)

Draft
SA
4d ago
+461-53

What

  • You can set locators at the top level or on each target to change the default visible of getByText, getByLabel, getByPlaceholder, getByDisplayValue, and getByTestId.
  • A target's locators.visible overrides the top-level value, and passing visible to a query overrides both. The default is false.
  • getByRole doesn't use the default.
export default {
  targets: [
    { engine: mobile({ platform: 'ios' }), app: { bundleId: 'com.example.app' } },
    { name: 'web', engine: web(), app: { url }, locators: { visible: false } },
  ],
  locators: { visible: true },
} satisfies E2EConfig;

On the iOS target, which inherits the top-level default:

await screen.getByText('Saved').tap();                       // hidden copies are skipped
await screen.getByText('Saved', { visible: false }).count(); // hidden copies are counted

Why

  • Role queries skip nodes hidden from the accessibility tree, but text and test id queries match hidden nodes too.
  • On native apps, previous screens stay mounted in the tree, so you end up passing { visible: true } to almost every query.

How it works

  1. locators is checked per target, using the target's visible, then the top-level value, then false (packages/core/src/config/resolve.ts:253, :702).
  2. The resolved value is stored on ResolvedTarget.locators (packages/core/src/config/targets.ts:46). It's included in the config digest only when visible is true (targets.ts:166). The top-level key is left out (resolve.ts:1046).
  3. The attempt's screen context gets the target's value (packages/core/src/run/fixtures.ts:152, :174).
  4. The five queries pass it to textQuery and testIdQuery (packages/core/src/locator/screen.ts:199), and visibility uses it when visible isn't set (packages/core/src/locator/expression.ts:41). roleQuery passes false (expression.ts:35), since a role query already skips nodes hidden from the accessibility tree on every engine.
  5. In an e2e mcp session, run_code's screen gets the same value (packages/e2e/src/session-tools/run-code.ts:248). locate and the test lines build their queries with one closure (packages/e2e/src/session-tools/catalog.ts:95, :201). When locate finds nothing under the default, its hint says hidden nodes were skipped (catalog.ts:251). Text, label, placeholder, and test id lines omit { visible: true } when locators.visible is true (packages/e2e/src/session-tools/test-lines.ts:578). Both catalog callers pass the target's value (packages/e2e/src/mcp/session.ts:488, packages/e2e/src/run/worker/held-test-tools.ts:504).

Error codes for invalid values:

CodeWhen
INVALID_CONFIGlocators (top level or on a target) isn't a plain object, has a key other than visible, or has a non-boolean visible

Verified

Ran it locally: yes, Chromium and Firefox.

A scratch config in the testbed set locators: { visible: true } on a Chromium and a Firefox target. The test runs on /controls, which has a hidden banner twin, and adds a hidden copy of the #coupon input:

await app.open('/controls');
await expect(screen.getByTestId('banner')).toHaveCount(1);
await screen.getByTestId('banner').tap();
await expect(screen.getByText('Sale')).toHaveText('Sale');
await expect(screen.getByTestId('banner', { visible: false })).toHaveCount(2);
// a hidden copy of #coupon (value SAVE10) is appended with browser.evaluate
await expect(screen.getByDisplayValue('SAVE10')).toHaveCount(1);
await expect(screen.getByDisplayValue('SAVE10', { visible: false })).toHaveCount(2);

node node_modules/e2e/dist/cli/bin.js run --config e2e.visible-verify.config.ts --video on:

      run 01a20d43-c624-78fa-b34e-bb5c71a5a0e5 · targets: chromium, firefox
 ✓ target "chromium" command at http://127.0.0.1:4371/ ready 90ms
   ✓ |chromium| tests-visible-verify/visible.e2e.ts > queries skip hidden twins without { visible: true } 499ms
   ✓ |firefox| tests-visible-verify/visible.e2e.ts > queries skip hidden twins without { visible: true } 1.48s
 Test Files  2 passed (2)

With locators: { visible: 'yes' }:

 ERROR  configuration error INVALID_CONFIG (config)
locators.visible must be a boolean, got "yes"
  • Firefox: locators-visible.test.ts and the run_code test in mcp-run-code.test.ts pass with their configs switched to web({ browser: 'firefox' }) (Firefox 159.0, checked with navigator.userAgent).
  • tests/integration/locators-visible.test.ts runs a config file through worker processes twice: once with a target that inherits visible: true, and once with a target that sets false. Both runs pass. Each also checks that a role query matches a zero-size checkbox unless the query sets visible: true.
  • tests/integration/mcp-run-code.test.ts runs run_code in a session whose config sets locators: { visible: true }.
  • iOS and Android: not run. The mobile engine reads the same visible predicate from the query (packages/mobile/src/locate.ts:131). This change doesn't touch it.
  • pnpm bench:ab: not run. An inherited visible: true gives the same locator predicate as an explicit { visible: true }.
  • Docs screenshots: not captured. The docs site isn't built from this repository, and pnpm docs:check covers the changed pages.

Videos from the Chromium and Firefox runs are attached below, in order.

Checklist

  • Changeset added (pnpm changeset) for any change to a published package, or the change is testbed, docs, or CI only.
  • Breaking change: title carries !, the changeset body names what breaks and what replaces it, and the deprecation warning landed a window earlier (stability policy in CONTRIBUTING.md).
  • Docs updated in the same PR: the docs/**/*.mdx page for the behavior, and skills/e2e/ if the skill describes it.
  • Contract change: emitted .d.ts reviewed, tests/types/sdk-types.ts updated; wire change edits the schema and both fixtures.
  • Engine contract change (e2e/engine): changesets for e2e, @e2e-dev/web, and @e2e-dev/mobile.

https://github.com/user-attachments/assets/4d9f39a2-68dd-477e-915c-527103d8f5c1

https://github.com/user-attachments/assets/3a24c6e3-3cb3-4114-9d57-01eb46cfa404