Repository navigation
feat(expect): add toBeEmpty locator matcher (ENG-1229) - #2219
Merged
Merged
Conversation
Contributor
🟢 e2e web agent: 34 passed36 agent steps · 26 replayed from cache · 25 model calls · 128.5k tokens (94% cached) · $0.0054 All 34 tests in 5 files
Tested by e2e 0.24.0 · 1m 42s · web · run artifacts |
Contributor
🟢 e2e web: 95 passedAll 95 tests in 43 files
Tested by e2e 0.24.0 · 1m 15s · web · run artifacts |
Contributor
🟢 e2e ios: 60 passed, 1 skippedAll 61 tests in 7 files
Tested by e2e 0.24.0 · 6m 56s · ios-simulator · run artifacts |
Contributor
🟢 e2e ios agent: 21 passed, 1 skipped25 agent steps · 12 replayed from cache · 60 model calls · 421.4k tokens (84% cached) · $0.0272 All 22 tests in 1 file
Tested by e2e 0.24.0 · 8m 25s · ios-simulator · run artifacts |
Contributor
🟢 e2e android agent: 20 passed24 agent steps · 15 replayed from cache · 33 model calls · 191.3k tokens (88% cached) · $0.0105 All 20 tests in 1 file
Tested by e2e 0.24.0 · 5m 59s · android-emulator · run artifacts |
toBeEmpty decided value vs text by role in core, since a semantic node has no tag, so an ARIA combobox or listbox, a non-editable ARIA textbox, a native select, a submit input, and a checkbox all read as empty where Playwright finds them not empty. Engines now report an empty node state on located nodes, never in an observation and never on a secure field. The web engine reads it in the page as Playwright does: an input or textarea by its raw value, any other element by its trimmed text content. The mobile engine reads a text field by its value and any other node by the text and values in its subtree. toBeEmpty reads only that state, like toBeEditable reads readonly, and fails either way where an engine reports none (desktop, older engines). The empty state stays out of state-matcher failure messages and MCP locate output.
- Web: read an input or textarea by tag name, as Playwright does. A filled input adopted from another frame failed instanceof, fell through to its empty text content, and passed toBeEmpty. - Mobile: a field below a container counts by its value alone and a secure one not at all, so a container holding only an empty field with a label or hint is empty, and a filled password field is not told. - Document that iOS reports a field Flutter or Compose Multiplatform draws as a plain view, so its placeholder counts.
KrzysztofMoch
force-pushed
the
krzysztof/to-be-empty
branch
from
November 24, 2026 17:46
cf55a8f to
70b7f9d
Compare
Contributor
🟢 e2e android: 61 passed, 1 skippedAll 62 tests in 7 files
Tested by e2e 0.24.0 · 9m 4s · android-emulator · run artifacts |
okwasniewski
approved these changes
Nov 24, 2026
2 of 5 tasks
3 of 5 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
expect(locator).toBeEmpty()waits for a node to be empty, with Playwright's rules on the web.inputortextareais empty when its value is'', read as it is, so a space is not empty. Any other element is empty when its trimmedtextContentis'', hidden text included.toBeEmptyfails either way there, with a message that says so.It takes only
{ timeout }, works with.notand a custom message, and isPOLICY_DENIEDon a secure field, liketoHaveValue.Takes over #1869 by @ftaakash. Their commit is the first one here, with them as author.
Why
toBeEmptyis on the Playwright parity list (ENG-1229). #1869 decided value or text by role in core, because a semantic node has no tag. That made it pass on six elements that show text: an ARIA combobox, an ARIA listbox, a non-editable ARIA textbox, a nativeselect, a submit input and a checkbox. Playwright decides by tag, so the engine has to answer.toBeEditable(#1962) took the same route for read-only.How it works
emptynode state (packages/core/src/engine/contract.ts:201). Engines report it on the nodeslocatereturns, never in an observation and never on a secure field, so agent prompts, replay-cache anchors and the mobile golden trees don't change.emptyOf,packages/web/src/in-page/read-semantics.ts:1699), only in the single-node projection that locator reads use (:1841). It checks the tag name, notinstanceof, so a filled input moved in from another frame still reads by its value.withEmptyState,packages/mobile/src/nodes.ts:129, called frompackages/mobile/src/surface.ts:1299). Fields go by role (textbox,searchbox) rather thanmayTakeText, since an iOSotherholding only text is as often a container as a drawn field. Below a container, a field counts only by its value and a secure field counts as nothing.toBeEmptyreads only that state (packages/e2e/src/expect/async.ts:482), the waytoBeEditablereadsreadonly. A node with no state keeps the poll waiting and fails withobserved: no empty state, which this engine does not report.locatelines leaveemptyout (async.ts:689,packages/e2e/src/session-tools/catalog.ts:289), sotoBeCheckednever printsstates: empty.expectand engine references, the Playwright and Cypress migration rows, the skill, and the ja/zhtoBeEmptysections. The peer floors already require>=0.25.0, the unreleased version this ships in.Not done: desktop. It's a macOS-only prototype, and #1962 also left it without
readonly. iOS reports a field drawn by Flutter or Compose Multiplatform as a plain view, so its placeholder counts and an empty one never reads empty. The reference page documents this.Issue
Part of #1855. Replaces #1869.
Verified
Ran it locally: yes (Linux, Chromium)
Testbed, the built CLI against a scratch test (not committed): Playwright's cases, the six elements from #1869's review table, a fill then clear, a custom-message failure and a password field.
The two failures are the intended ones. The password value appears in no file under
.e2e/.<button role="combobox">Select a fruit</button><ul role="listbox"><li role="option">Apple</li></ul><div role="textbox">hello</div><select>with options<input type="submit" value="Go"><input type="checkbox">The left column is what #1869's own
web-platform.test.tsasserted at that head. Each case now passesnot.toBeEmpty()inweb-platform.test.ts:124.textContentfails the hidden-text case;instanceofinstead of the tag name fails the adopted-input case. The mobile unit test has a container holding only a labeled empty field and a filled password field; the old subtree rule read it as not empty.locator-frame.e2e.ts"should wait for frame to go" flake, which feat: add expect(locator).toBeEmpty() #1869's CI also hit on a head that didn't touch the web engine.pnpm bench:ab --suite testbed -- tests/forms.e2e.ts, a locator-read-heavy suite. Every located node on the web now also computes itsemptystate:bench-ab:
425cdb28(merge base with origin/main) vsd5ed00b1(this branch before its rebase onto main, same code)apps/testbed:
e2e run --workers 1 tests/forms.e2e.ts. 6 pairs in random order, resolved after 6 pairs. Threshold ±5% and 10 ms. linux x64, AMD Ryzen 7 8845HS w/ Radeon 780M Graphics x16, Node 24.18.0, load 1.1.Behavior
Every test ran the same steps with the same outcome on every run of both builds.
Timings
Counters
Every counter matched on every run of both builds.
Tests outside the threshold: 0 of 608
With 608 tests compared at 95%, about 30.4 could land outside by chance.
Taken over and finished by Claude Code (Opus 5.5).
to-be-empty.webm