fix(electron): fill, check, select, and upload through more of a real app's forms

KD
4h ago
+245-57

What

fill, check, selectOption, and setInputFiles on an Electron target now handle more real forms, as they do on web():

  • getByText('Email').fill(...) and getByText('Remember me').check() act on the control that the label's text names (Playwright's follow-label retargeting).
  • fill on an element inside a contenteditable (a <span> in a rich text editor) focuses the editing host and replaces that element's text.
  • check() and uncheck() work on a switch that Chromium knows through ElementInternals (internals.role = 'switch'), on a role list (role="switch checkbox"), and on an upper-case aria-checked="TRUE".
  • selectOption focuses 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 the mimeType the test gave. It used to take the type its name implied. A directory passed as a path is refused as INVALID_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) is INVALID_ARGUMENT too.

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

  1. labelled() retargets a node that is not a control itself (a label's own text) to label.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, and readChecked act through it.
  2. selectContents focuses the editing host of an element inside a contenteditable, checks the element is still there, and selects its contents (node-ops.ts:283-298).
  3. readChecked reads the first token of a role list and aria-checked in any case. When the page cannot tell, it falls back to the node's checked in Chromium's accessibility tree, which knows ElementInternals (packages/electron/src/actions.ts:222).
  4. selectOption and setValue focus first and call stillThere() before they change the element (node-ops.ts:278, :321-333). The check throws inside Budget.send, after the focus went out, so translate reports ACTION_MAY_HAVE_COMMITTED.
  5. 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 fires input and change as untrusted events, as Playwright does for in-memory files on the web. attachFiles shares 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).
  6. setInputFiles checks each path with statOf and refuses one that is not a regular file (actions.ts:282). statOf turns an error statSync throws (ENAMETOOLONG, ELOOP, EACCES on a parent directory) into INVALID_ARGUMENT, as main's existsSync check did (actions.ts:299). A regular file the user cannot read passes stat and goes to DOM.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), and pnpm check. After the review fixes, at the current head, I ran the Electron unit tests, tests/integration/launch.test.ts and tests/integration/node-ops.test.ts, typecheck, and oxlint again; they pass.
  • main against this branch: this branch's tests run against origin/main's packages/electron/src. These tests fail there and pass here:
SuiteTestmainthis PR
integrationcheck() reads a switch Chromium knows by ElementInternals, a role list, or an upper-case aria-checkedfailspasses
integrationnodeOp finds an option by label, then text, value, or index, and refuses a missing or disabled onefailspasses
integrationnodeOp selects the contents of an element inside an editing host, focusing the hostfailspasses
integrationnodeOp selects nothing in an editing host whose focus handler replaced the elementfailspasses
testbedtests/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 contentfailspasses
testbedtests/sign-in.e2e.ts > sign-in window > fills and checks the control a label's text names, as web() doesfailspasses
testbedtests/sign-in.e2e.ts > sign-in window > attaches a file by path and refuses a path that names nothingfailspasses
  • 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.

Metricbase 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.open23.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.selectOption4.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.tap4.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.fill3.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.restart2.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.dragTo1.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.pressSequentially1.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.title1.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.window955 ms (954 ms-956 ms)955 ms (954 ms-957 ms)0.0% (-0.1% to +0.2%)same
step electron.waitForWindow940 ms (938 ms-941 ms)938 ms (938 ms-939 ms)-0.1% (-0.4% to +0.3%)same, under the floor
step locator.scrollIntoView928 ms (926 ms-928 ms)927 ms (927 ms-928 ms)-0.1% (-0.3% to +0.2%)same, under the floor
step electron.launch914 ms (913 ms-916 ms)915 ms (914 ms-915 ms)+0.1% (-0.3% to +0.2%)same, under the floor
step locator.longPress905 ms (904 ms-906 ms)905 ms (904 ms-906 ms)0.0% (-0.2% to +0.2%)same
step locator.waitFor904 ms (903 ms-904 ms)903 ms (903 ms-904 ms)-0.1% (-0.1% to +0.1%)same, under the floor
step expect.toHaveValue758 ms (747 ms-760 ms)759 ms (756 ms-761 ms)+0.1% (-0.4% to +1.9%)same, under the floor
step locator.setInputFiles529 ms (528 ms-531 ms)531 ms (530 ms-531 ms)+0.3% (-0.2% to +1.7%)same, under the floor
step electron.waitForDownload518 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.toHaveValue518 ms (516 ms-518 ms)516 ms (515 ms-517 ms)-0.3% (-0.7% to +0.6%)same, under the floor
step electron.evaluate476 ms (474 ms-477 ms)474 ms (469 ms-477 ms)-0.1% (-1.9% to +1.1%)same, under the floor
step expect.toBeVisible446 ms (444 ms-446 ms)442 ms (440 ms-442 ms)-0.9% (-1.2% to +1.5%)same, under the floor
step app.clearState340 ms (339 ms-341 ms)339 ms (337 ms-339 ms)-0.4% (-1.3% to +0.0%)same, under the floor
step expect.toHaveText325 ms (322 ms-328 ms)325 ms (321 ms-328 ms)-0.8% (-3.2% to +2.8%)same, under the floor
step locator.check318 ms (316 ms-319 ms)320 ms (318 ms-322 ms)+0.5% (-0.8% to +3.3%)same, under the floor
step app.screenshot125 ms (121 ms-127 ms)122 ms (118 ms-126 ms)-3.2% (-9.1% to +14.7%)same, under the floor
step expect.toHaveCount100 ms (99 ms-101 ms)100 ms (98 ms-102 ms)-0.5% (-3.0% to +5.6%)same, under the floor
step app.stopRecording85 ms (84 ms-86 ms)85 ms (80 ms-87 ms)-0.6% (-7.2% to +3.2%)same, under the floor
step locator.press51 ms (50 ms-51 ms)51 ms (50 ms-51 ms)0.0% (-1.9% to +3.0%)same
step locator.clear48 ms (47 ms-48 ms)49 ms (48 ms-50 ms)+3.2% (-2.1% to +8.6%)same, under the floor
step locator.focus36 ms (35 ms-37 ms)37 ms (36 ms-38 ms)0.0% (-2.7% to +11.3%)same
step locator.swipe36 ms (35 ms-36 ms)36 ms (35 ms-37 ms)0.0% (-4.0% to +29.4%)same
step electron.keyboard.press34 ms (33 ms-36 ms)35 ms (34 ms-36 ms)+3.0% (-2.9% to +16.9%)same, under the floor
step expect.toBeChecked33 ms (31 ms-34 ms)33 ms (32 ms-34 ms)0.0% (-4.7% to +8.3%)same
step app.startRecording23 ms (23 ms-24 ms)23 ms (23 ms-23 ms)0.0% (-2.1% to 0.0%)same
step expect.toBeHidden21 ms (21 ms-21 ms)22 ms (21 ms-22 ms)+4.8% (-9.3% to +7.3%)same, under the floor
step expect.toBeDisabled21 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.type21 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.toBeChecked20 ms (19 ms-21 ms)19 ms (17 ms-21 ms)-2.7% (-22.1% to +5.1%)same, under the floor
step expect.toBeEditable19 ms (18 ms-19 ms)19 ms (18 ms-19 ms)0.0% (-5.3% to +5.6%)same
step locator.uncheck16 ms (15 ms-16 ms)16 ms (15 ms-17 ms)0.0% (0.0% to +18.3%)same
step locator.hover16 ms (11 ms-16 ms)15 ms (10 ms-16 ms)-9.4% (-41.9% to +83.2%)same, under the floor
step expect.toHaveAttribute12 ms (11 ms-13 ms)12 ms (12 ms-12 ms)+3.8% (-3.9% to +9.1%)same, under the floor
step expect.toBeInViewport12 ms (11 ms-12 ms)12 ms (11 ms-12 ms)-3.2% (-12.6% to +14.4%)same, under the floor
step locator.dblclick12 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.down11 ms (10 ms-11 ms)11 ms (10 ms-11 ms)0.0% (-4.7% to +19.6%)same
step electron.keyboard.up10 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.toBeEmpty10 ms (9 ms-10 ms)11 ms (10 ms-11 ms)+4.9% (-5.1% to +22.2%)same, under the floor
step expect.toBeEmpty10 ms (10 ms-10 ms)10 ms (10 ms-10 ms)0.0% (-5.1% to +5.4%)same
step expect.not.toBeEditable9 ms (8 ms-9 ms)9 ms (8 ms-9 ms)0.0% (-15.7% to +12.5%)same
step expect.not.toBeInViewport9 ms (9 ms-9 ms)9 ms (9 ms-10 ms)0.0% (-9.1% to +5.4%)same
step expect.toContainText8 ms (8 ms-8 ms)8 ms (8 ms-8 ms)0.0% (0.0% to +13.4%)same
step window.reload8 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.toHaveAttribute6 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.toBeHidden6 ms (6 ms-6 ms)6 ms (5 ms-6 ms)0.0% (-16.7% to 0.0%)same
step screen.tree5 ms (5 ms-5 ms)5 ms (5 ms-5 ms)0.0% (-10.6% to +11.8%)same
step expect.toHaveRole5 ms (5 ms-5 ms)5 ms (4 ms-5 ms)0.0% (-30.7% to +26.5%)same
step electron.keyboard.insertText5 ms (5 ms-5 ms)5 ms (5 ms-5 ms)0.0% (-8.7% to +18.3%)same
step app.back5 ms (4 ms-6 ms)5 ms (5 ms-6 ms)0.0% (-8.7% to +36.9%)same
step expect.toBeFocused4 ms (4 ms-5 ms)4 ms (4 ms-5 ms)0.0% (-20.0% to +25.0%)same
step expect.toHaveAccessibleName4 ms (4 ms-4 ms)4 ms (4 ms-4 ms)0.0% (-13.4% to 0.0%)same
step expect.not.toHaveRole4 ms (4 ms-5 ms)5 ms (4 ms-5 ms)0.0% (0.0% to +25.0%)same
step expect.toBeSelected4 ms (4 ms-4 ms)4 ms (4 ms-4 ms)0.0% (0.0% to 0.0%)same
step window.evaluate4 ms (3 ms-4 ms)4 ms (3 ms-4 ms)0.0% (-25.0% to +15.5%)same
step expect.not.toBeEnabled4 ms (4 ms-5 ms)4 ms (4 ms-4 ms)0.0% (-20.0% to 0.0%)same
step expect.toHaveScreenshot2 ms (1 ms-2 ms)1 ms (1 ms-2 ms)0.0% (-50.0% to +41.4%)same
step window.close1 ms (1 ms-1 ms)1 ms (1 ms-2 ms)0.0% (0.0% to +100.0%)same

Counters

Counterbasehead
attempts8788
events engine121126
events navigation126-133128-134
events poll225230
steps579592-593
tests passed8788
Tests outside the threshold: 0 of 84

With 84 tests compared at 95%, about 4.2 could land outside by chance.

- Video: none attached. The change is in what the engine reads and when it acts, which the tests above pin down; a recording would show the same window either way. - Local macOS runs, on both sides, started Electron with `-ApplePersistenceIgnoreState YES` from #2500, applied without committing it. Without it, an Electron the tests killed makes macOS ask to reopen its windows, and the next launch waits out its timeout. The Linux and Windows CI jobs do not need it.

Fresh-context review (Codex gpt-6.2-sol, read-only, on this branch's diff):

  • Fixed: an element inside a contenteditable that the host's focus handler replaced was taken as selected (cead0ea81, with a test).
  • Fixed: added the changeset.
  • Dismissed: in-memory files fire untrusted input and change events. 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 statSync throws on failed as ENGINE_FAILURE, not INVALID_ARGUMENT (9186b8122, with a unit test).
  • Fixed: the changeset said selectOption waits 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 with ACTION_MAY_HAVE_COMMITTED instead (e2bb81831). The docs' Upload row now ties name and mimeType to 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; setFiles on 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 through JSON.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.