Skip to content
Merged
Show file tree
Hide file tree
Changes from 18 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.
95 changes: 88 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,93 @@ 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('blurs a focused field, then uploads and clears an in-memory file', async ({ browser }) => {
await browser.goto(content('<input id="field"><input type="file">'));
const field = browser.locator('#field');
await field.focus();
await expect(field).toBeFocused();
await field.blur();
await expect(field).not.toBeFocused();

const input = browser.locator('input[type=file]');
await input.setInputFiles({ name: 'notes.txt', mimeType: 'text/plain', buffer: Buffer.from('notes') });
expect(await browser.evaluate(readFirstFile('input[type=file]'))).toBe('notes');
await input.setInputFiles([]);
expect(await browser.evaluate("() => document.querySelector('input[type=file]').files.length")).toBe(0);
});

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
3 changes: 2 additions & 1 deletion docs/ja/migrate/playwright.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ test('checkout', async ({ app, agent, screen }) => {
| `click({ button: 'right' })`, `click({ delay })` | `secondaryTap()`、`longPress({ duration })` |
| `click({ position })`, `click({ modifiers })` | `tap({ position })`、`tap({ modifiers })` |
| `fill()`, `pressSequentially()`, `clear()`, `focus()`, `blur()`, `hover()`, `check()`, `uncheck()`, `dragTo()`, `setInputFiles(path)`, `selectOption({ label })` または `{ value }` | 同じ。ただし `force`、`trial`、`position` はなし |
| `setInputFiles({ name, mimeType, buffer })` | Web のみ。`name`、`mimeType`、`buffer` だけを持つプレーンオブジェクトを渡します。 |
| `press(key)` | 1 文字または[名前付きキー](/reference/engine#keys)なら同じ。キーコードは `focus()` 後に `browser.keyboard.press` |
| `innerText()`, `allInnerTexts()`, `scrollIntoViewIfNeeded()` | `textContent()`、`allTextContents()`、`scrollIntoView()` |
| `textContent()`, `allTextContents()`, `inputValue()`, `getAttribute()`, `boundingBox()`, `isVisible()`, `isHidden()`, `isEnabled()`, `isDisabled()`, `isChecked()`, `waitFor({ state })` | 同じ |
Expand Down Expand Up @@ -239,7 +240,7 @@ export const test = base.extend<{ accountPage: AccountPage }>({
| --- | --- |
| `locator.locator(selector)`, `locator.and()`, `filter({ visible })` | `'.card >> .close'` のような単一の `browser.locator` セレクター、またはスコープ内の `screen` クエリ |
| `locator.evaluate()`, `expect(locator).toHaveClass()`, `toHaveCSS()`, `dispatchEvent()` | `browser.evaluate(fn, selector)`。`expect(browser).toHaveClass(locator, cls)` |
| `setInputFiles({ buffer })`, `selectOption([...])`, `click({ clickCount })`, `hover({ position })` | 一時ファイルのパス。複数選択には `browser.evaluate`。`boundingBox()` と `browser.mouse` |
| `selectOption([...])`, `click({ clickCount })`, `hover({ position })` | 複数選択には `browser.evaluate`。`boundingBox()` と `browser.mouse` |

</Accordion>
<Accordion title="アサーション">
Expand Down
7 changes: 6 additions & 1 deletion docs/ja/reference/engine.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -1123,6 +1123,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; an empty array clears the input. The protocol encodes bytes only on the wire. */
readonly files: readonly { readonly name: string; readonly mimeType: string; readonly buffer: Uint8Array }[];
}
| { readonly kind: 'dragTo'; readonly target: NodeRef }
| {
readonly kind: 'swipe';
Expand Down Expand Up @@ -1154,7 +1159,7 @@ export const LOCATOR_ACTION_KINDS = [
] as const satisfies readonly LocatorActionKind[];

/** Every action kind understood by this version of core. */
export const KNOWN_LOCATOR_ACTION_KINDS = [...LOCATOR_ACTION_KINDS, 'blur'] as const satisfies readonly LocatorActionKind[];
export const KNOWN_LOCATOR_ACTION_KINDS = [...LOCATOR_ACTION_KINDS, 'blur', 'setInputFilePayloads'] 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 @@ -777,12 +777,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 @@ -122,6 +122,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()`, `blur()`, `hover()`, `check()`, `uncheck()`, `dragTo()`, `setInputFiles(path)`, `selectOption({ label })` or `{ value }` | the same, without `force`, `trial`, or `position` |
| `setInputFiles({ name, mimeType, buffer })` | Web only. Pass a plain object with only `name`, `mimeType`, and `buffer`. |
| `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 @@ -257,7 +258,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 @@ -253,7 +253,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
8 changes: 7 additions & 1 deletion docs/reference/engine.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -1174,6 +1174,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`. An empty `files` array clears the input. The runner uses it to clear when the engine declares this action without `setInputFiles`. | yes | - |
| `dragTo` | `target`: a `NodeRef` or a `ViewportPoint` | yes | yes |
| `swipe` | `direction`, `momentum?` | yes | yes |
| `swipeTo` | `target`, `durationMs?` | - | yes |
Expand Down Expand Up @@ -1225,6 +1226,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; an empty array clears the input. The protocol encodes bytes only on the wire. */
readonly files: readonly { readonly name: string; readonly mimeType: string; readonly buffer: Uint8Array }[];
}
| { readonly kind: 'dragTo'; readonly target: NodeRef }
| {
readonly kind: 'swipe';
Expand Down Expand Up @@ -1256,7 +1262,7 @@ export const LOCATOR_ACTION_KINDS = [
] as const satisfies readonly LocatorActionKind[];

/** Every action kind understood by this version of core. */
export const KNOWN_LOCATOR_ACTION_KINDS = [...LOCATOR_ACTION_KINDS, 'blur'] as const satisfies readonly LocatorActionKind[];
export const KNOWN_LOCATOR_ACTION_KINDS = [...LOCATOR_ACTION_KINDS, 'blur', 'setInputFilePayloads'] as const satisfies readonly LocatorActionKind[];
```

#### Pointer actions
Expand Down
13 changes: 8 additions & 5 deletions docs/reference/screen.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -932,21 +932,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. Pass a plain object with only the fields of `FilePayload`: `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. For larger files, use a path if the target supports transferring files of that size. 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, or a path that does not exist or sits under a directory the runner cannot search. |
| `UNSUPPORTED_CAPABILITY` | On a device, which has no file input. |
| `INVALID_ARGUMENT` | A blank or missing path, a path under a directory the runner cannot search, 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
3 changes: 2 additions & 1 deletion docs/zh/migrate/playwright.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ test('checkout', async ({ app, agent, screen }) => {
| `click({ button: 'right' })`, `click({ delay })` | `secondaryTap()`、`longPress({ duration })` |
| `click({ position })`, `click({ modifiers })` | `tap({ position })`、`tap({ modifiers })` |
| `fill()`, `pressSequentially()`, `clear()`, `focus()`, `blur()`, `hover()`, `check()`, `uncheck()`, `dragTo()`, `setInputFiles(path)`, `selectOption({ label })` 或 `{ value }` | 相同,但不支持 `force`、`trial` 或 `position` |
| `setInputFiles({ name, mimeType, buffer })` | 仅限 Web。传入只含 `name`、`mimeType` 和 `buffer` 的普通对象。 |
| `press(key)` | 单个字符或[命名按键](/reference/engine#keys)的用法相同;按键代码则在 `focus()` 后使用 `browser.keyboard.press` |
| `innerText()`, `allInnerTexts()`, `scrollIntoViewIfNeeded()` | `textContent()`、`allTextContents()`、`scrollIntoView()` |
| `textContent()`, `allTextContents()`, `inputValue()`, `getAttribute()`, `boundingBox()`, `isVisible()`, `isHidden()`, `isEnabled()`, `isDisabled()`, `isChecked()`, `waitFor({ state })` | 相同 |
Expand Down Expand Up @@ -239,7 +240,7 @@ export const test = base.extend<{ accountPage: AccountPage }>({
| --- | --- |
| `locator.locator(selector)`, `locator.and()`, `filter({ visible })` | 一个 `browser.locator` 选择器,例如 `'.card >> .close'`,或作用域内的 `screen` 查询 |
| `locator.evaluate()`, `expect(locator).toHaveClass()`, `toHaveCSS()`, `dispatchEvent()` | `browser.evaluate(fn, selector)`;`expect(browser).toHaveClass(locator, cls)` |
| `setInputFiles({ buffer })`, `selectOption([...])`, `click({ clickCount })`, `hover({ position })` | 临时文件路径;多选使用 `browser.evaluate`;`browser.mouse` 配合 `boundingBox()` |
| `selectOption([...])`, `click({ clickCount })`, `hover({ position })` | 多选使用 `browser.evaluate`;`browser.mouse` 配合 `boundingBox()` |

</Accordion>
<Accordion title="断言">
Expand Down
7 changes: 6 additions & 1 deletion docs/zh/reference/engine.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -1123,6 +1123,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; an empty array clears the input. The protocol encodes bytes only on the wire. */
readonly files: readonly { readonly name: string; readonly mimeType: string; readonly buffer: Uint8Array }[];
}
| { readonly kind: 'dragTo'; readonly target: NodeRef }
| {
readonly kind: 'swipe';
Expand Down Expand Up @@ -1154,7 +1159,7 @@ export const LOCATOR_ACTION_KINDS = [
] as const satisfies readonly LocatorActionKind[];

/** Every action kind understood by this version of core. */
export const KNOWN_LOCATOR_ACTION_KINDS = [...LOCATOR_ACTION_KINDS, 'blur'] as const satisfies readonly LocatorActionKind[];
export const KNOWN_LOCATOR_ACTION_KINDS = [...LOCATOR_ACTION_KINDS, 'blur', 'setInputFilePayloads'] as const satisfies readonly LocatorActionKind[];
```

#### 指针操作
Expand Down
Loading
Loading