Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
aa8e3a4
feat: support in-memory file uploads
WellDunDun Nov 17, 2026
3afd1fe
fix: negotiate payload upload support with engines
WellDunDun Nov 17, 2026
9f6883e
fix: address payload capability review findings
WellDunDun Nov 17, 2026
073135c
fix: preserve compatibility with older core engines
WellDunDun Nov 17, 2026
e53f6ce
chore: sync main for translated docs
WellDunDun Nov 17, 2026
a0974fe
fix: validate upload payloads and isolate wire encoding
WellDunDun Nov 17, 2026
313b9f8
fix: address upload compatibility review follow-ups
WellDunDun Nov 18, 2026
a3b65c4
fix: clarify upload fallback and manifest requirements
WellDunDun Nov 18, 2026
6f05fca
fix(locator): declare in-memory uploads explicitly
WellDunDun Nov 18, 2026
6ca57b9
Merge remote-tracking branch 'origin/main' into feat/in-memory-file-u…
WellDunDun Nov 18, 2026
d2f621c
test(protocol): use an upload-capable manifest fixture
WellDunDun Nov 18, 2026
f37de12
docs(engine): clean up upload capability references
WellDunDun Nov 19, 2026
6e7a796
fix(web): require core and e2e 0.24.1 for locator actions
WellDunDun Nov 19, 2026
8ffe845
fix(locator): clear files on payload-only engines
WellDunDun Nov 20, 2026
7f5ad2f
Merge main after locator blur landed
WellDunDun Nov 20, 2026
0023573
fix(locator): route upload clearing in the locator
WellDunDun Nov 20, 2026
8a21b1e
Merge main and preserve upload type assertions
WellDunDun Nov 21, 2026
08cd2cf
Merge main and preserve upload path validation
WellDunDun Nov 22, 2026
f95fb42
test(locator): distinguish unsupported upload clearing
WellDunDun Nov 22, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changeset/in-memory-file-uploads.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@e2e-dev/core": patch
"e2e": patch
"@e2e-dev/web": patch
---

Accept in-memory file payloads in `locator.setInputFiles({ name, mimeType, buffer })`, including payload arrays.
80 changes: 73 additions & 7 deletions apps/testbed/tests/set-input-files.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,12 @@
* root, and what the server received is what `/upload` answers with.
*/

/*
* Not ported:
* - should set from memory: `setInputFiles` takes file paths, not `{ name, mimeType, buffer }` payloads.
* - input event.composed should be true and cross shadow dom boundary: sets a `{ name, mimeType, buffer }` payload, whose events Playwright dispatches itself.
*/

import { test, type Browser } from '@e2e-dev/web';
import { expect } from 'e2e';
import fs from 'node:fs';
import os from 'node:os';
import path from 'node:path';
import { asset, content, PREFIX } from './helpers.ts';
import { asset, content, failure, PREFIX } from './helpers.ts';

const EMPTY_PAGE = `${PREFIX}/empty.html`;

Expand Down Expand Up @@ -67,6 +61,78 @@ test.describe('page set input files', { requires: ['browser'], tags: ['playwrigh
for (const dir of outputDirs.splice(0)) fs.rmSync(dir, { recursive: true, force: true });
});

test('should set from memory', async ({ browser }) => {
await browser.goto(content('<input type=file>'));
await browser.locator('input').setInputFiles({
name: 'test.txt', mimeType: 'text/plain', buffer: Buffer.from('this is a test'),
});
expect(await browser.evaluate("() => document.querySelector('input').files.length")).toBe(1);
expect(await browser.evaluate("() => document.querySelector('input').files[0].name")).toBe('test.txt');
});

test('input event.composed should be true and cross shadow dom boundary', async ({ browser }) => {
await browser.goto(content(`<body><script>
const div = document.createElement('div');
const shadowRoot = div.attachShadow({ mode: 'open' });
shadowRoot.innerHTML = '<input type=file>';
document.body.appendChild(div);
window.firedEvents = [];
window.firedBodyEvents = [];
for (const event of ['input', 'change']) {
document.body.addEventListener(event, e => window.firedBodyEvents.push(e.type + ':' + e.composed));
shadowRoot.querySelector('input').addEventListener(event, e => window.firedEvents.push(e.type + ':' + e.composed));
}
</script></body>`));
await browser.locator('input').setInputFiles({
name: 'test.txt', mimeType: 'text/plain', buffer: Buffer.from('this is a test'),
});
expect(await browser.evaluate('() => window.firedEvents')).toEqual(['input:true', 'change:false']);
expect(await browser.evaluate('() => window.firedBodyEvents')).toEqual(['input:true']);
});

test('rejects an oversized payload without closing the engine connection', async ({ browser }) => {
await browser.goto(content('<input type=file>'));
const error = await failure(() => browser.locator('input').setInputFiles({
name: 'large.bin', mimeType: 'application/octet-stream', buffer: Buffer.alloc(50 * 1024 * 1024),
}));
expect(error).toHaveProperty('code', 'INVALID_ARGUMENT');
expect(error).toHaveProperty('message', 'Cannot set buffer larger than 50Mb, please write it to a file and pass its path instead.');
await browser.locator('input').setInputFiles({ name: 'small.txt', mimeType: 'text/plain', buffer: Buffer.from('still connected') });
expect(await browser.evaluate(readFirstFile('input'))).toBe('still connected');
});

test('uploads an in-memory file through the public locator API', async ({ browser }) => {
await browser.goto('/input/fileupload.html');
await browser.locator('input[type=file]').setInputFiles({
name: 'résumé.txt', mimeType: 'text/plain', buffer: Buffer.from('In-memory résumé'),
});
expect(await browser.evaluate("() => document.querySelector('input').files[0].name")).toBe('résumé.txt');
expect(await browser.evaluate("() => document.querySelector('input').files[0].type")).toBe('text/plain');
expect(await browser.evaluate(readFirstFile('input'))).toBe('In-memory résumé');
});

test('uploads in-memory binary files and clears them', async ({ browser }) => {
await browser.goto('/input/fileupload-multi.html');
await browser.locator('input[type=file]').setInputFiles([
{ name: 'binary.bin', mimeType: 'application/octet-stream', buffer: Buffer.from([0, 128, 255]) },
{ name: 'empty.txt', mimeType: 'text/plain', buffer: Buffer.alloc(0) },
]);
expect(await browser.evaluate(`async () => Promise.all([...document.querySelector('input').files].map(async file => ({
name: file.name, mimeType: file.type, bytes: [...new Uint8Array(await file.arrayBuffer())],
})))`)).toEqual([
{ name: 'binary.bin', mimeType: 'application/octet-stream', bytes: [0, 128, 255] },
{ name: 'empty.txt', mimeType: 'text/plain', bytes: [] },
]);
await browser.locator('input[type=file]').setInputFiles([]);
expect(await browser.evaluate("() => document.querySelector('input').files.length")).toBe(0);
});

test('uploads an in-memory file through a chooser button', async ({ browser }) => {
await browser.goto(content(`<button onclick="document.querySelector('input').click()">Choose file</button><input type="file" hidden>`));
await browser.locator('button').setInputFiles({ name: 'receipt.txt', mimeType: 'text/plain', buffer: Buffer.from('receipt') });
expect(await browser.evaluate(readFirstFile('input'))).toBe('receipt');
});

test('should upload the file', async ({ browser }) => {
await browser.goto('/input/fileupload.html');
await browser.locator('input[type=file]').setInputFiles(asset('file-to-upload.txt'));
Expand Down
8 changes: 8 additions & 0 deletions docs/ja/reference/engine.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,8 @@ export interface Engine {
* reaches the engine.
*/
readonly tapModifiers?: boolean;
/** Opts in to in-memory file payloads, in addition to declaring the action. */
readonly filePayloads?: boolean;
/** capability: keyboard - requires observation. Input to whatever holds focus; see `EngineKeyboard`. */
readonly keyboard?: EngineKeyboard;
/**
Expand Down Expand Up @@ -1093,6 +1095,11 @@ export type LocatorAction =
| { readonly kind: 'press'; readonly key: Key }
| { readonly kind: 'selectOption'; readonly value: SelectOption }
| { readonly kind: 'setInputFiles'; readonly paths: readonly string[] }
| {
readonly kind: 'setInputFilePayloads';
/** In-memory files; the protocol encodes their bytes only when crossing the wire. */
readonly files: readonly { readonly name: string; readonly mimeType: string; readonly buffer: Uint8Array }[];
}
| { readonly kind: 'dragTo'; readonly target: NodeRef }
| {
readonly kind: 'swipe';
Expand All @@ -1119,6 +1126,7 @@ export const LOCATOR_ACTION_KINDS = [
'scrollIntoView',
'selectOption',
'setInputFiles',
'setInputFilePayloads',
'dragTo',
'swipe',
] as const satisfies readonly LocatorActionKind[];
Expand Down
7 changes: 5 additions & 2 deletions docs/ja/reference/screen.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -725,12 +725,15 @@ await screen.getByRole('button', 'Account').hover();
#### `setInputFiles`

```ts
/** Sets the files of exactly one file input, or of a control that opens a file chooser; paths resolve from the project root, and an empty array clears the input. */
setInputFiles(paths: string | readonly string[], options?: ActionOptions): Promise<void>;
/** Sets the files of exactly one file input, or of a control that opens a file chooser; paths resolve from the project root, payloads supply bytes in memory, and an empty array clears the input. */
setInputFiles(files: string | readonly string[] | FilePayload | readonly FilePayload[], options?: ActionOptions): Promise<void>;
```

```ts
await screen.getByLabel('Receipt').setInputFiles('fixtures/receipt.pdf');
await screen.getByLabel('Receipt').setInputFiles({
name: 'receipt.txt', mimeType: 'text/plain', buffer: Buffer.from('Receipt total: 12.00'),
});
await screen.getByLabel('Receipt').setInputFiles([]);
```

Expand Down
3 changes: 2 additions & 1 deletion docs/migrate/playwright.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ run only in a browser, so a test that uses it declares
| `click({ button: 'right' })`, `click({ delay })` | `secondaryTap()`, `longPress({ duration })` |
| `click({ position })`, `click({ modifiers })` | `tap({ position })`, `tap({ modifiers })` |
| `fill()`, `pressSequentially()`, `clear()`, `focus()`, `hover()`, `check()`, `uncheck()`, `dragTo()`, `setInputFiles(path)`, `selectOption({ label })` or `{ value }` | the same, without `force`, `trial`, or `position` |
| `setInputFiles({ name, mimeType, buffer })` | the same, web only |
| `press(key)` | the same for one character or a [named key](/reference/engine#keys); `browser.keyboard.press` after `focus()` for a key code |
| `innerText()`, `allInnerTexts()`, `scrollIntoViewIfNeeded()` | `textContent()`, `allTextContents()`, `scrollIntoView()` |
| `textContent()`, `allTextContents()`, `inputValue()`, `getAttribute()`, `boundingBox()`, `isVisible()`, `isHidden()`, `isEnabled()`, `isDisabled()`, `isChecked()`, `waitFor({ state })` | the same |
Expand Down Expand Up @@ -248,7 +249,7 @@ purpose. Use the workaround, or keep the test in Playwright.
| --- | --- |
| `locator.locator(selector)`, `locator.and()`, `filter({ visible })` | One `browser.locator` selector, such as `'.card >> .close'`, or a `screen` query inside the scope |
| `locator.evaluate()`, `expect(locator).toHaveClass()`, `toHaveCSS()`, `dispatchEvent()` | `browser.evaluate(fn, selector)`; `expect(browser).toHaveClass(locator, cls)` |
| `setInputFiles({ buffer })`, `selectOption([...])`, `click({ clickCount })`, `hover({ position })` | A temp file path; `browser.evaluate` for a multi-select; `browser.mouse` with `boundingBox()` |
| `selectOption([...])`, `click({ clickCount })`, `hover({ position })` | `browser.evaluate` for a multi-select; `browser.mouse` with `boundingBox()` |

</Accordion>
<Accordion title="Assertions">
Expand Down
2 changes: 1 addition & 1 deletion docs/reference/engine-protocol.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ params are the member's arguments by name, with every `OperationContext` as
`artifacts/screenshot` returns `{ data, mediaType: 'image/png' }`, the image
in base64, when the server cannot write the attempt's artifact directory,
such as a server on a device. The client writes it under `screenshots/`.
Observation pixels cross the same way: `pixels.data` is base64.
Observation pixels cross the same way: `pixels.data` is base64. File payload buffers also cross as base64 in `engine/perform`; engines receive them as `Uint8Array` bytes.

`screens` in `lifecycle/startAttempt` says whether the attempt keeps a
trace, which is when the server may send `attempt/screen`.
Expand Down
12 changes: 12 additions & 0 deletions docs/reference/engine.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ rules:
| `perform`, `actions` | One without the other. An `actions` list that is empty, repeats a kind, or names one outside `LOCATOR_ACTION_KINDS`. |
| `performAt`, `pointerActions` | One without the other. A `pointerActions` list that is empty, repeats a kind, or names one outside `POINTER_ACTION_KINDS`. |
| `tapModifiers` | Not a boolean, or `true` without `perform`. |
| `filePayloads` | Not a boolean, or `true` without the `setInputFilePayloads` action. |
| `keyboard`, `state`, `artifacts`, `session` | An unknown key or a non-function member. `keyboard` without `type` and `press`; `state` without both `capture` and `restore`; `artifacts` without `screenshot`; `startVideo` without `stopVideo`, or the reverse. |
| `secrets` | Not an array of `secrets.get()` handles. |
| `fixtures` | Not an object, a fixture that is not a factory function, or a fixture name that is not a lower-camel identifier or shadows `agent`, `app`, `screen`, `platform`, or `session`. |
Expand Down Expand Up @@ -135,6 +136,7 @@ The body of one target. Every member but `name`, `version`, and
| [`locate`](#capabilities) | method |
| [`performAt`, `pointerActions`](#pointer-actions) | method, kinds |
| [`tapModifiers`](#capabilities) | `boolean` |
| [`filePayloads`](#capabilities) | `boolean` |
| [`keyboard`](#keyboard) | `EngineKeyboard` |
| [`fixtures`](#contributed-fixtures) | factories |
| [`state`](#state) | `EngineStateCapability` |
Expand Down Expand Up @@ -235,6 +237,8 @@ export interface Engine {
* reaches the engine.
*/
readonly tapModifiers?: boolean;
/** Opts in to in-memory file payloads, in addition to declaring the action. */
readonly filePayloads?: boolean;
/** capability: keyboard - requires observation. Input to whatever holds focus; see `EngineKeyboard`. */
readonly keyboard?: EngineKeyboard;
/**
Expand Down Expand Up @@ -379,6 +383,7 @@ member. Three gaps end differently:
| `perform` + `actions` | `actions` | `observe` | Node actions of the declared kinds, with platform actionability checks. |
| `locate` | `location` | `observe` | `screen`, `Locator`, `expect(locator)`. |
| `tapModifiers: true` | - | `perform` | `modifiers` on `tap`, `doubleTap`, and `secondaryTap`. |
| `filePayloads: true` | - | `perform`, `setInputFilePayloads` action | In-memory file payloads. Without this flag the payload action is removed from the advertised actions; a payload-only declaration fails with `INVALID_CONFIG`. |
| `performAt` + `pointerActions` | `pointer` | `observe` | One pointer action at a viewport point, with no node behind it. |
| `keyboard.{type,press,dismiss?}` | `keyboard` | `observe` | Input to whatever holds focus. |
| `fixtures.<name>` | `<name>` | - | A contributed fixture. |
Expand Down Expand Up @@ -1138,6 +1143,7 @@ honors in `actions` and `pointerActions`.
| `scrollIntoView` | - | yes | - |
| `selectOption` | `value` | yes | - |
| `setInputFiles` | `paths`; empty clears the input | yes | - |
| `setInputFilePayloads` | `files` with `name`, `mimeType`, and `Uint8Array` `buffer`; requires `filePayloads: true` on the engine | yes | - |
| `dragTo` | `target`: a `NodeRef` or a `ViewportPoint` | yes | yes |
| `swipe` | `direction`, `momentum?` | yes | yes |
| `swipeTo` | `target`, `durationMs?` | - | yes |
Expand Down Expand Up @@ -1188,6 +1194,11 @@ export type LocatorAction =
| { readonly kind: 'press'; readonly key: Key }
| { readonly kind: 'selectOption'; readonly value: SelectOption }
| { readonly kind: 'setInputFiles'; readonly paths: readonly string[] }
| {
readonly kind: 'setInputFilePayloads';
/** In-memory files; the protocol encodes their bytes only when crossing the wire. */
readonly files: readonly { readonly name: string; readonly mimeType: string; readonly buffer: Uint8Array }[];
}
| { readonly kind: 'dragTo'; readonly target: NodeRef }
| {
readonly kind: 'swipe';
Expand All @@ -1214,6 +1225,7 @@ export const LOCATOR_ACTION_KINDS = [
'scrollIntoView',
'selectOption',
'setInputFiles',
'setInputFilePayloads',
'dragTo',
'swipe',
] as const satisfies readonly LocatorActionKind[];
Expand Down
13 changes: 8 additions & 5 deletions docs/reference/screen.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -858,21 +858,24 @@ await screen.getByRole('button', 'Account').hover();
#### `setInputFiles`

```ts
/** Sets the files of exactly one file input, or of a control that opens a file chooser; paths resolve from the project root, and an empty array clears the input. */
setInputFiles(paths: string | readonly string[], options?: ActionOptions): Promise<void>;
/** Sets the files of exactly one file input, or of a control that opens a file chooser; paths resolve from the project root, payloads supply bytes in memory, and an empty array clears the input. */
setInputFiles(files: string | readonly string[] | FilePayload | readonly FilePayload[], options?: ActionOptions): Promise<void>;
```

```ts
await screen.getByLabel('Receipt').setInputFiles('fixtures/receipt.pdf');
await screen.getByLabel('Receipt').setInputFiles({
name: 'receipt.txt', mimeType: 'text/plain', buffer: Buffer.from('Receipt total: 12.00'),
});
await screen.getByLabel('Receipt').setInputFiles([]);
```

Web only. An empty array clears the input and fires `input` and `change`. It also takes a button that opens a file chooser.
Web only. A `FilePayload` has `name: string`, `mimeType: string`, and `buffer: Buffer`. Pass one payload or an array of payloads; do not mix paths and payloads in an array. The combined payload size must be less than 50 MiB; use paths for larger files. An empty array clears the input and fires `input` and `change`. A button that opens a file chooser accepts the same inputs.

| Throws | When |
| --- | --- |
| `INVALID_ARGUMENT` | A blank path. |
| `UNSUPPORTED_CAPABILITY` | On a device, which has no file input. |
| `INVALID_ARGUMENT` | A blank path, an invalid payload, mixed paths and payloads, or payloads totaling 50 MiB or more. |
| `UNSUPPORTED_CAPABILITY` | On a device, or for payloads on an engine that does not declare `setInputFilePayloads`. |
| `ACTION_FAILED` | A button that opens no file chooser. |

#### `dragTo`
Expand Down
8 changes: 8 additions & 0 deletions docs/zh/reference/engine.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,8 @@ export interface Engine {
* reaches the engine.
*/
readonly tapModifiers?: boolean;
/** Opts in to in-memory file payloads, in addition to declaring the action. */
readonly filePayloads?: boolean;
/** capability: keyboard - requires observation. Input to whatever holds focus; see `EngineKeyboard`. */
readonly keyboard?: EngineKeyboard;
/**
Expand Down Expand Up @@ -1093,6 +1095,11 @@ export type LocatorAction =
| { readonly kind: 'press'; readonly key: Key }
| { readonly kind: 'selectOption'; readonly value: SelectOption }
| { readonly kind: 'setInputFiles'; readonly paths: readonly string[] }
| {
readonly kind: 'setInputFilePayloads';
/** In-memory files; the protocol encodes their bytes only when crossing the wire. */
readonly files: readonly { readonly name: string; readonly mimeType: string; readonly buffer: Uint8Array }[];
}
| { readonly kind: 'dragTo'; readonly target: NodeRef }
| {
readonly kind: 'swipe';
Expand All @@ -1119,6 +1126,7 @@ export const LOCATOR_ACTION_KINDS = [
'scrollIntoView',
'selectOption',
'setInputFiles',
'setInputFilePayloads',
'dragTo',
'swipe',
] as const satisfies readonly LocatorActionKind[];
Expand Down
7 changes: 5 additions & 2 deletions docs/zh/reference/screen.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -725,12 +725,15 @@ await screen.getByRole('button', 'Account').hover();
#### `setInputFiles`

```ts
/** Sets the files of exactly one file input, or of a control that opens a file chooser; paths resolve from the project root, and an empty array clears the input. */
setInputFiles(paths: string | readonly string[], options?: ActionOptions): Promise<void>;
/** Sets the files of exactly one file input, or of a control that opens a file chooser; paths resolve from the project root, payloads supply bytes in memory, and an empty array clears the input. */
setInputFiles(files: string | readonly string[] | FilePayload | readonly FilePayload[], options?: ActionOptions): Promise<void>;
```

```ts
await screen.getByLabel('Receipt').setInputFiles('fixtures/receipt.pdf');
await screen.getByLabel('Receipt').setInputFiles({
name: 'receipt.txt', mimeType: 'text/plain', buffer: Buffer.from('Receipt total: 12.00'),
});
await screen.getByLabel('Receipt').setInputFiles([]);
```

Expand Down
1 change: 1 addition & 0 deletions packages/core/src/core/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export type {
AppPermissionState,
ClickOptions,
Expectable,
FilePayload,
JsonPrimitive,
JsonValue,
KeyModifier,
Expand Down
6 changes: 6 additions & 0 deletions packages/core/src/engine/contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,11 @@ export type LocatorAction =
| { readonly kind: 'press'; readonly key: Key }
| { readonly kind: 'selectOption'; readonly value: SelectOption }
| { readonly kind: 'setInputFiles'; readonly paths: readonly string[] }
| {
readonly kind: 'setInputFilePayloads';
/** In-memory files; the protocol encodes their bytes only when crossing the wire. */
readonly files: readonly { readonly name: string; readonly mimeType: string; readonly buffer: Uint8Array }[];
}
| { readonly kind: 'dragTo'; readonly target: NodeRef }
| {
readonly kind: 'swipe';
Expand All @@ -318,6 +323,7 @@ export const LOCATOR_ACTION_KINDS = [
'scrollIntoView',
'selectOption',
'setInputFiles',
'setInputFilePayloads',
'dragTo',
'swipe',
] as const satisfies readonly LocatorActionKind[];
Expand Down
2 changes: 2 additions & 0 deletions packages/core/src/engine/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -860,6 +860,8 @@ export interface Engine {
* that predates the field never drops one silently.
*/
readonly tapModifiers?: boolean;
/** Opts in to `setInputFilePayloads`; older engines may import the shared action list without implementing new kinds. */
readonly filePayloads?: boolean;
/** capability: keyboard - requires observation. Input to whatever holds focus; see `EngineKeyboard`. */
readonly keyboard?: EngineKeyboard;
/**
Expand Down
Loading
Loading