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

This commit is contained in:
Max Schmitt 2024-07-16 15:55:35 +02:00 коммит произвёл GitHub
Родитель 96e0a96ac1
Коммит 7ce9b7e56b
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: B5690EEEBB952194
3 изменённых файлов: 13 добавлений и 3 удалений

Просмотреть файл

@ -125,7 +125,7 @@ All API classes, methods, and events should have a description in [`docs/src`](h
To 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:

Просмотреть файл

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

Просмотреть файл

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