fix(setInputFiles): should throw when uploading file in directory upload

This commit is contained in:
Max Schmitt 2024-07-16 15:12:09 +02:00
parent a5ca9b7d37
commit 3022a42023
2 changed files with 11 additions and 0 deletions

View file

@ -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())

View file

@ -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');