Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.
TypeScript automationchromechromiume2e-testingelectronend-to-end-testingfirefoxjavascriptplaywrighttesttest-automationtestingtesting-toolswebwebkit
fix(setInputFiles): throw when uploading file in directory upload (#31706)
Max Schmitt7ce9b7e56be4
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.mdindex 5b71ccde04..30e89e6bee 100644--- a/CONTRIBUTING.md+++ b/CONTRIBUTING.md@@ -125,7 +125,7 @@ All API classes, methods, and events should have a description in [`docs/src`](hTo run the documentation linter, use:```bash-npm run doclint+npm run doc```To build the documentation site locally and test how your changes will look in practice:diff --git a/packages/playwright-core/src/server/dom.ts b/packages/playwright-core/src/server/dom.tsindex 30eb04d3f6..52e648abe0 100644--- a/packages/playwright-core/src/server/dom.ts+++ b/packages/playwright-core/src/server/dom.ts@@ -639,6 +639,8 @@ export class ElementHandle<T extends Node = Node> extends js.JSHandle<T> {throw injected.createStacklessError('Non-multiple file input can only accept single file');if (directoryUpload && !inputElement.webkitdirectory)throw injected.createStacklessError('File input does not support directories, pass individual files instead');+ if (!directoryUpload && inputElement.webkitdirectory)+ throw injected.createStacklessError('[webkitdirectory] input requires passing a path to a directory');return inputElement;}, { multiple, directoryUpload: !!localDirectory });if (result === 'error:notconnected' || !result.asElement())diff --git a/tests/page/page-set-input-files.spec.ts b/tests/page/page-set-input-files.spec.tsindex 76a53fa571..a32db203bd 100644--- a/tests/page/page-set-input-files.spec.ts+++ b/tests/page/page-set-input-files.spec.ts@@ -120,6 +120,15 @@ it('should throw when uploading a folder in a normal file upload input', async (await expect(input.setInputFiles(dir)).rejects.toThrow('File input does not support directories, pass individual files instead');});+it('should throw when uploading a file in a directory upload input', async ({ page, server, isAndroid, asset }) => {+ it.skip(isAndroid);+ it.skip(os.platform() === 'darwin' && parseInt(os.release().split('.')[0], 10) <= 21, 'WebKit on macOS-12 is frozen');++ await page.goto(server.PREFIX + '/input/folderupload.html');+ const input = await page.$('input');+ await expect(input.setInputFiles(asset('file to upload.txt'))).rejects.toThrow('[webkitdirectory] input requires passing a path to a directory');+});+it('should upload a file after popup', async ({ page, server, asset }) => {it.info().annotations.push({ type: 'issue', description: 'https://github.com/microsoft/playwright/issues/29923' });await page.goto(server.PREFIX + '/input/fileupload.html');@@ -341,8 +350,7 @@ it('should emit event via prepend', async ({ page, server }) => {expect(chooser).toBeTruthy();});-it('should emit event for iframe', async ({ page, server, browserName }) => {- it.skip(browserName === 'firefox');+it('should emit event for iframe', async ({ page, server }) => {const frame = await attachFrame(page, 'frame1', server.EMPTY_PAGE);await frame.setContent(`<input type=file>`);const [chooser] = await Promise.all([