feat(config): add locators.visible as the default visible for screen queries (ENG-1487)
Draft
SA
4d ago+461+461+012345678901234567890123456789-53-53-01234567890123456789
What
- You can set
locatorsat the top level or on each target to change the defaultvisibleofgetByText,getByLabel,getByPlaceholder,getByDisplayValue, andgetByTestId. - A target's
locators.visibleoverrides the top-level value, and passingvisibleto a query overrides both. The default isfalse. getByRoledoesn'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
locatorsis checked per target, using the target'svisible, then the top-level value, thenfalse(packages/core/src/config/resolve.ts:253,:702).- The resolved value is stored on
ResolvedTarget.locators(packages/core/src/config/targets.ts:46). It's included in the config digest only whenvisibleis true (targets.ts:166). The top-level key is left out (resolve.ts:1046). - The attempt's screen context gets the target's value (
packages/core/src/run/fixtures.ts:152,:174). - The five queries pass it to
textQueryandtestIdQuery(packages/core/src/locator/screen.ts:199), andvisibilityuses it whenvisibleisn't set (packages/core/src/locator/expression.ts:41).roleQuerypassesfalse(expression.ts:35), since a role query already skips nodes hidden from the accessibility tree on every engine. - In an
e2e mcpsession,run_code's screen gets the same value (packages/e2e/src/session-tools/run-code.ts:248).locateand the test lines build their queries with one closure (packages/e2e/src/session-tools/catalog.ts:95,:201). Whenlocatefinds nothing under the default, its hint says hidden nodes were skipped (catalog.ts:251). Text, label, placeholder, and test id lines omit{ visible: true }whenlocators.visibleistrue(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:
| Code | When |
|---|---|
INVALID_CONFIG | locators (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.tsand therun_codetest inmcp-run-code.test.tspass with their configs switched toweb({ browser: 'firefox' })(Firefox 159.0, checked withnavigator.userAgent). tests/integration/locators-visible.test.tsruns a config file through worker processes twice: once with a target that inheritsvisible: true, and once with a target that setsfalse. Both runs pass. Each also checks that a role query matches a zero-size checkbox unless the query setsvisible: true.tests/integration/mcp-run-code.test.tsrunsrun_codein a session whose config setslocators: { visible: true }.- iOS and Android: not run. The mobile engine reads the same
visiblepredicate from the query (packages/mobile/src/locate.ts:131). This change doesn't touch it. pnpm bench:ab: not run. An inheritedvisible: truegives 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:checkcovers 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/**/*.mdxpage for the behavior, andskills/e2e/if the skill describes it. - Contract change: emitted
.d.tsreviewed,tests/types/sdk-types.tsupdated; wire change edits the schema and both fixtures. - Engine contract change (
e2e/engine): changesets fore2e,@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