fix(electron): fill, check, select, and upload through more of a real app's forms
What
fill, check, selectOption, and setInputFiles on an Electron target now handle more real forms, as they do on web():
getByText('Email').fill(...)andgetByText('Remember me').check()act on the control that the label's text names (Playwright's follow-label retargeting).fillon an element inside acontenteditable(a<span>in a rich text editor) focuses the editing host and replaces that element's text.check()anduncheck()work on a switch that Chromium knows throughElementInternals(internals.role = 'switch'), on a role list (role="switch checkbox"), and on an upper-casearia-checked="TRUE".selectOptionfocuses the select before it looks for the option, so a select whose focus handler reorders its options gets the option the test asked for.- An element that a focus handler replaced (a select, a picker input, an element in an editing host) is no longer edited after it left the page. The action fails with
ACTION_MAY_HAVE_COMMITTED, which the harness does not retry, since the focus already reached the app. - An in-memory file (
setInputFiles({ name, mimeType, buffer })) keeps themimeTypethe test gave. It used to take the type its name implied. A directory passed as a path is refused asINVALID_ARGUMENT; it used to be attached as an empty file. A path the file system cannot look up (a name too long, a link loop) isINVALID_ARGUMENTtoo.
Why
These are the gaps a form test written for web() met on electron(). The worst were the uploads: the engine wrote each in-memory file to disk and attached it by path, so the page saw a different MIME type, and DOM.setFileInputFiles reports success for a directory.
How it works
labelled()retargets a node that is not a control itself (a label's own text) tolabel.control, unless the node is on Playwright's follow-label list (FOLLOW_LABEL_STOPS) or editable (packages/electron/src/in-page/node-ops.ts:101).fill,check, andreadCheckedact through it.selectContentsfocuses the editing host of an element inside acontenteditable, checks the element is still there, and selects its contents (node-ops.ts:283-298).readCheckedreads the first token of a role list andaria-checkedin any case. When the page cannot tell, it falls back to the node'scheckedin Chromium's accessibility tree, which knowsElementInternals(packages/electron/src/actions.ts:222).selectOptionandsetValuefocus first and callstillThere()before they change the element (node-ops.ts:278,:321-333). The check throws insideBudget.send, after the focus went out, sotranslatereportsACTION_MAY_HAVE_COMMITTED.- In-memory files are built in the page from their bytes, name, and type, and set on the input through a
DataTransfer(setFiles,node-ops.ts:353). The page firesinputandchangeas untrusted events, as Playwright does for in-memory files on the web.attachFilesshares the file-input and file-chooser paths between files from disk and in-memory files, and the attempt's temporary uploads directory is gone (actions.ts:323,packages/electron/src/surface.ts). setInputFileschecks each path withstatOfand refuses one that is not a regular file (actions.ts:282).statOfturns an errorstatSyncthrows (ENAMETOOLONG,ELOOP,EACCESon a parent directory) intoINVALID_ARGUMENT, as main'sexistsSynccheck did (actions.ts:299). A regular file the user cannot read passesstatand goes toDOM.setFileInputFiles, as on main.
Verified
Ran it locally: yes, on macOS (Apple Silicon) with Electron 45.5.0.
- This branch passes the Electron package's unit and integration tests, the Electron testbed run through the built CLI (
pnpm --filter @e2e-dev/electron-testbed test), andpnpm check. After the review fixes, at the current head, I ran the Electron unit tests,tests/integration/launch.test.tsandtests/integration/node-ops.test.ts, typecheck, and oxlint again; they pass. - main against this branch: this branch's tests run against
origin/main'spackages/electron/src. These tests fail there and pass here:
| Suite | Test | main | this PR |
|---|---|---|---|
| integration | check() reads a switch Chromium knows by ElementInternals, a role list, or an upper-case aria-checked | fails | passes |
| integration | nodeOp finds an option by label, then text, value, or index, and refuses a missing or disabled one | fails | passes |
| integration | nodeOp selects the contents of an element inside an editing host, focusing the host | fails | passes |
| integration | nodeOp selects nothing in an editing host whose focus handler replaced the element | fails | passes |
| testbed | tests/parity.e2e.ts > what an Electron target shares with the web > attaches a file from memory, which the page reads by its name, type, and content | fails | passes |
| testbed | tests/sign-in.e2e.ts > sign-in window > fills and checks the control a label's text names, as web() does | fails | passes |
| testbed | tests/sign-in.e2e.ts > sign-in window > attaches a file by path and refuses a path that names nothing | fails | passes |
- Benchmark:
pnpm bench:ab --suite electron-testbed, the merge base with main against this head, on a Mac. Both builds ran with-ApplePersistenceIgnoreState(#2500) applied locally and uncommitted, since without it a launch after a killed app stalls 120 s on the reopen-windows alert. The "uncommitted changes" in the header are that line.
Result: suite time is the same (-0.0%, 95% CI -0.1% to +0.5%). The added, removed, and changed tests are the testbed tests this PR adds or edits (one new test, one renamed, one with a new assertion), which is why the attempt and step counts rise. One fixture test (mouse moves) changes its step sequence between runs of the same build, as it does on main, so it is noise.
bench:ab output
bench-ab: 7c1b2b25 (merge base with origin/main) vs 4136057f + uncommitted changes
apps/electron-testbed: e2e run --workers 1. 6 pairs in random order, resolved after 6 pairs. Threshold ±5% and 10 ms. darwin arm64, Apple M5 Pro x18, Node 26.13.1, load 2.6.
The suite's tests or config differ between base and head, so each side ran its own. A timing change can be the test change.
Behavior
These tests are left out of the timing rows below.
-
unstable on head (2 different step sequences) tests/fixture.e2e.ts › electron.keyboard and a window's page › moves, presses, and scrolls with the mouse where the test points it (electron)
-
removed tests/parity.e2e.ts › what an Electron target shares with the web › attaches a file from memory, which the page reads by its name and content (electron)
-
added tests/parity.e2e.ts › what an Electron target shares with the web › attaches a file from memory, which the page reads by its name, type, and content (electron)
-
changed tests/sign-in.e2e.ts › sign-in window › attaches a file by path and refuses a path that names nothing (electron)
+ locator locator.setInputFiles "getByTestId(\"attachment\")" failed INVALID_ARGUMENT + assertion expect.toHaveText "getByTestId(\"attachment-name\")" passed -
added tests/sign-in.e2e.ts › sign-in window › fills and checks the control a label's text names, as web() does (electron)
Timings
Every row but the process wall clock covers the 84 tests whose behavior matched.
| Metric | base median (IQR) | head median (IQR) | change (95% CI) | verdict |
|---|---|---|---|---|
| wall (process) | 64.22 s (64.20 s-64.24 s) | 64.62 s (64.61 s-64.68 s) | +0.7% (+0.6% to +1.4%) | same |
| suite (sum of attempts) | 62.71 s (62.71 s-62.75 s) | 62.72 s (62.69 s-62.72 s) | -0.0% (-0.1% to +0.5%) | same |
| action (events) | 16.90 s (16.88 s-16.90 s) | 16.91 s (16.90 s-16.91 s) | +0.2% (-0.0% to +0.5%) | same |
| step app.open | 23.80 s (23.80 s-23.81 s) | 23.80 s (23.78 s-23.80 s) | -0.0% (-0.1% to +0.5%) | same, under the floor |
| step locator.selectOption | 4.73 s (4.73 s-4.73 s) | 4.73 s (4.73 s-4.73 s) | +0.0% (-0.1% to +1.1%) | same, under the floor |
| step locator.tap | 4.40 s (4.39 s-4.41 s) | 4.40 s (4.40 s-4.41 s) | +0.1% (-0.2% to +0.3%) | same, under the floor |
| step locator.fill | 3.38 s (3.37 s-3.38 s) | 3.38 s (3.38 s-3.39 s) | +0.1% (+0.1% to +0.4%) | same, under the floor |
| step app.restart | 2.00 s (2.00 s-2.00 s) | 1.99 s (1.99 s-2.00 s) | -0.2% (-0.6% to +0.3%) | same, under the floor |
| step locator.dragTo | 1.43 s (1.43 s-1.44 s) | 1.43 s (1.43 s-1.44 s) | +0.3% (-0.4% to +0.5%) | same, under the floor |
| step locator.pressSequentially | 1.08 s (1.08 s-1.08 s) | 1.08 s (1.08 s-1.09 s) | 0.0% (-0.0% to +0.3%) | same |
| step window.title | 1.01 s (1.01 s-1.01 s) | 1.00 s (1.00 s-1.01 s) | -0.1% (-0.2% to -0.0%) | same, under the floor |
| step electron.window | 955 ms (954 ms-956 ms) | 955 ms (954 ms-957 ms) | 0.0% (-0.1% to +0.2%) | same |
| step electron.waitForWindow | 940 ms (938 ms-941 ms) | 938 ms (938 ms-939 ms) | -0.1% (-0.4% to +0.3%) | same, under the floor |
| step locator.scrollIntoView | 928 ms (926 ms-928 ms) | 927 ms (927 ms-928 ms) | -0.1% (-0.3% to +0.2%) | same, under the floor |
| step electron.launch | 914 ms (913 ms-916 ms) | 915 ms (914 ms-915 ms) | +0.1% (-0.3% to +0.2%) | same, under the floor |
| step locator.longPress | 905 ms (904 ms-906 ms) | 905 ms (904 ms-906 ms) | 0.0% (-0.2% to +0.2%) | same |
| step locator.waitFor | 904 ms (903 ms-904 ms) | 903 ms (903 ms-904 ms) | -0.1% (-0.1% to +0.1%) | same, under the floor |
| step expect.toHaveValue | 758 ms (747 ms-760 ms) | 759 ms (756 ms-761 ms) | +0.1% (-0.4% to +1.9%) | same, under the floor |
| step locator.setInputFiles | 529 ms (528 ms-531 ms) | 531 ms (530 ms-531 ms) | +0.3% (-0.2% to +1.7%) | same, under the floor |
| step electron.waitForDownload | 518 ms (517 ms-519 ms) | 518 ms (517 ms-519 ms) | -0.0% (-0.4% to +0.6%) | same, under the floor |
| step expect.not.toHaveValue | 518 ms (516 ms-518 ms) | 516 ms (515 ms-517 ms) | -0.3% (-0.7% to +0.6%) | same, under the floor |
| step electron.evaluate | 476 ms (474 ms-477 ms) | 474 ms (469 ms-477 ms) | -0.1% (-1.9% to +1.1%) | same, under the floor |
| step expect.toBeVisible | 446 ms (444 ms-446 ms) | 442 ms (440 ms-442 ms) | -0.9% (-1.2% to +1.5%) | same, under the floor |
| step app.clearState | 340 ms (339 ms-341 ms) | 339 ms (337 ms-339 ms) | -0.4% (-1.3% to +0.0%) | same, under the floor |
| step expect.toHaveText | 325 ms (322 ms-328 ms) | 325 ms (321 ms-328 ms) | -0.8% (-3.2% to +2.8%) | same, under the floor |
| step locator.check | 318 ms (316 ms-319 ms) | 320 ms (318 ms-322 ms) | +0.5% (-0.8% to +3.3%) | same, under the floor |
| step app.screenshot | 125 ms (121 ms-127 ms) | 122 ms (118 ms-126 ms) | -3.2% (-9.1% to +14.7%) | same, under the floor |
| step expect.toHaveCount | 100 ms (99 ms-101 ms) | 100 ms (98 ms-102 ms) | -0.5% (-3.0% to +5.6%) | same, under the floor |
| step app.stopRecording | 85 ms (84 ms-86 ms) | 85 ms (80 ms-87 ms) | -0.6% (-7.2% to +3.2%) | same, under the floor |
| step locator.press | 51 ms (50 ms-51 ms) | 51 ms (50 ms-51 ms) | 0.0% (-1.9% to +3.0%) | same |
| step locator.clear | 48 ms (47 ms-48 ms) | 49 ms (48 ms-50 ms) | +3.2% (-2.1% to +8.6%) | same, under the floor |
| step locator.focus | 36 ms (35 ms-37 ms) | 37 ms (36 ms-38 ms) | 0.0% (-2.7% to +11.3%) | same |
| step locator.swipe | 36 ms (35 ms-36 ms) | 36 ms (35 ms-37 ms) | 0.0% (-4.0% to +29.4%) | same |
| step electron.keyboard.press | 34 ms (33 ms-36 ms) | 35 ms (34 ms-36 ms) | +3.0% (-2.9% to +16.9%) | same, under the floor |
| step expect.toBeChecked | 33 ms (31 ms-34 ms) | 33 ms (32 ms-34 ms) | 0.0% (-4.7% to +8.3%) | same |
| step app.startRecording | 23 ms (23 ms-24 ms) | 23 ms (23 ms-23 ms) | 0.0% (-2.1% to 0.0%) | same |
| step expect.toBeHidden | 21 ms (21 ms-21 ms) | 22 ms (21 ms-22 ms) | +4.8% (-9.3% to +7.3%) | same, under the floor |
| step expect.toBeDisabled | 21 ms (20 ms-22 ms) | 21 ms (21 ms-22 ms) | +4.4% (-4.7% to +10.3%) | same, under the floor |
| step electron.keyboard.type | 21 ms (20 ms-21 ms) | 21 ms (21 ms-21 ms) | +2.5% (0.0% to +7.7%) | same, under the floor |
| step expect.not.toBeChecked | 20 ms (19 ms-21 ms) | 19 ms (17 ms-21 ms) | -2.7% (-22.1% to +5.1%) | same, under the floor |
| step expect.toBeEditable | 19 ms (18 ms-19 ms) | 19 ms (18 ms-19 ms) | 0.0% (-5.3% to +5.6%) | same |
| step locator.uncheck | 16 ms (15 ms-16 ms) | 16 ms (15 ms-17 ms) | 0.0% (0.0% to +18.3%) | same |
| step locator.hover | 16 ms (11 ms-16 ms) | 15 ms (10 ms-16 ms) | -9.4% (-41.9% to +83.2%) | same, under the floor |
| step expect.toHaveAttribute | 12 ms (11 ms-13 ms) | 12 ms (12 ms-12 ms) | +3.8% (-3.9% to +9.1%) | same, under the floor |
| step expect.toBeInViewport | 12 ms (11 ms-12 ms) | 12 ms (11 ms-12 ms) | -3.2% (-12.6% to +14.4%) | same, under the floor |
| step locator.dblclick | 12 ms (12 ms-13 ms) | 13 ms (12 ms-13 ms) | +4.1% (-3.9% to +8.3%) | same, under the floor |
| step electron.keyboard.down | 11 ms (10 ms-11 ms) | 11 ms (10 ms-11 ms) | 0.0% (-4.7% to +19.6%) | same |
| step electron.keyboard.up | 10 ms (10 ms-11 ms) | 10 ms (9 ms-10 ms) | -5.1% (-14.2% to +8.7%) | same, under the floor |
| step expect.not.toBeEmpty | 10 ms (9 ms-10 ms) | 11 ms (10 ms-11 ms) | +4.9% (-5.1% to +22.2%) | same, under the floor |
| step expect.toBeEmpty | 10 ms (10 ms-10 ms) | 10 ms (10 ms-10 ms) | 0.0% (-5.1% to +5.4%) | same |
| step expect.not.toBeEditable | 9 ms (8 ms-9 ms) | 9 ms (8 ms-9 ms) | 0.0% (-15.7% to +12.5%) | same |
| step expect.not.toBeInViewport | 9 ms (9 ms-9 ms) | 9 ms (9 ms-10 ms) | 0.0% (-9.1% to +5.4%) | same |
| step expect.toContainText | 8 ms (8 ms-8 ms) | 8 ms (8 ms-8 ms) | 0.0% (0.0% to +13.4%) | same |
| step window.reload | 8 ms (7 ms-8 ms) | 8 ms (8 ms-8 ms) | +13.4% (-6.5% to +14.3%) | same, under the floor |
| step expect.not.toHaveAttribute | 6 ms (6 ms-6 ms) | 7 ms (7 ms-7 ms) | +16.7% (+8.0% to +16.7%) | same, under the floor |
| step expect.not.toBeHidden | 6 ms (6 ms-6 ms) | 6 ms (5 ms-6 ms) | 0.0% (-16.7% to 0.0%) | same |
| step screen.tree | 5 ms (5 ms-5 ms) | 5 ms (5 ms-5 ms) | 0.0% (-10.6% to +11.8%) | same |
| step expect.toHaveRole | 5 ms (5 ms-5 ms) | 5 ms (4 ms-5 ms) | 0.0% (-30.7% to +26.5%) | same |
| step electron.keyboard.insertText | 5 ms (5 ms-5 ms) | 5 ms (5 ms-5 ms) | 0.0% (-8.7% to +18.3%) | same |
| step app.back | 5 ms (4 ms-6 ms) | 5 ms (5 ms-6 ms) | 0.0% (-8.7% to +36.9%) | same |
| step expect.toBeFocused | 4 ms (4 ms-5 ms) | 4 ms (4 ms-5 ms) | 0.0% (-20.0% to +25.0%) | same |
| step expect.toHaveAccessibleName | 4 ms (4 ms-4 ms) | 4 ms (4 ms-4 ms) | 0.0% (-13.4% to 0.0%) | same |
| step expect.not.toHaveRole | 4 ms (4 ms-5 ms) | 5 ms (4 ms-5 ms) | 0.0% (0.0% to +25.0%) | same |
| step expect.toBeSelected | 4 ms (4 ms-4 ms) | 4 ms (4 ms-4 ms) | 0.0% (0.0% to 0.0%) | same |
| step window.evaluate | 4 ms (3 ms-4 ms) | 4 ms (3 ms-4 ms) | 0.0% (-25.0% to +15.5%) | same |
| step expect.not.toBeEnabled | 4 ms (4 ms-5 ms) | 4 ms (4 ms-4 ms) | 0.0% (-20.0% to 0.0%) | same |
| step expect.toHaveScreenshot | 2 ms (1 ms-2 ms) | 1 ms (1 ms-2 ms) | 0.0% (-50.0% to +41.4%) | same |
| step window.close | 1 ms (1 ms-1 ms) | 1 ms (1 ms-2 ms) | 0.0% (0.0% to +100.0%) | same |
Counters
| Counter | base | head |
|---|---|---|
| attempts | 87 | 88 |
| events engine | 121 | 126 |
| events navigation | 126-133 | 128-134 |
| events poll | 225 | 230 |
| steps | 579 | 592-593 |
| tests passed | 87 | 88 |
Tests outside the threshold: 0 of 84
With 84 tests compared at 95%, about 4.2 could land outside by chance.
Fresh-context review (Codex gpt-6.2-sol, read-only, on this branch's diff):
- Fixed: an element inside a
contenteditablethat the host's focus handler replaced was taken as selected (cead0ea81, with a test). - Fixed: added the changeset.
- Dismissed: in-memory files fire untrusted
inputandchangeevents. They are built in the page so the test's MIME type holds, as Playwright does for in-memory files on the web, where the events are untrusted too.
Bot review (cubic, CodeQL):
- Fixed: a path
statSyncthrows on failed asENGINE_FAILURE, notINVALID_ARGUMENT(9186b8122, with a unit test). - Fixed: the changeset said
selectOptionwaits for an option a focus handler adds. Its readiness check looks before focus, so only a reorder is covered (5c599ce5b). It also said a replaced element is located again; the action fails withACTION_MAY_HAVE_COMMITTEDinstead (e2bb81831). The docs' Upload row now tiesnameandmimeTypeto in-memory files (6fefae4b2). - Left out as unlikely edge cases: a custom switch with a role list inside a label that also holds a native input; a switch known only through
ElementInternals, checked through its label's text;setFileson an input whose type changes between the readiness check and the upload. - Dismissed: CodeQL's "improper code sanitization" in
launch.test.ts. The page is HTML the test writes, passed throughJSON.stringify(encodeURIComponent(...))as main's tests in that file do.
🤖 Generated with Claude Code
Summary by CodeRabbit
- New Features
- Form actions support fields identified by their labels, contenteditable areas, and switch controls.
- Option selection uses the choices available after a field receives focus.
- In-memory file uploads preserve supplied filenames and MIME types across file inputs and upload-button choosers.
- Providing an empty file list clears a file input.
- Bug Fixes
- Actions report a failure when a field is replaced during interaction, without changing the replacement field.
- Uploads reject directories and invalid filesystem paths.
- Documentation
- Clarified in-memory upload behavior and errors for invalid filesystem paths.