fix: throw error if setInputFile does not exist (#29944)

Fixes https://github.com/microsoft/playwright/issues/29941
This commit is contained in:
Max Schmitt 2024-03-14 20:27:33 +01:00 committed by GitHub
parent 93dc89fa1f
commit 7cbef691ae
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 15 additions and 2 deletions

View File

@ -14,6 +14,7 @@
* limitations under the License.
*/
import fs from 'fs';
import type * as channels from '@protocol/channels';
import * as injectedScriptSource from '../generated/injectedScriptSource';
import { isSessionClosedError } from './protocolError';
@ -642,10 +643,14 @@ export class ElementHandle<T extends Node = Node> extends js.JSHandle<T> {
await progress.beforeInputAction(this);
await this._page._frameManager.waitForSignalsCreatedBy(progress, options.noWaitAfter, async () => {
progress.throwIfAborted(); // Avoid action that has side-effects.
if (localPaths)
if (localPaths) {
await Promise.all(localPaths.map(localPath => (
fs.promises.access(localPath, fs.constants.F_OK)
)));
await this._page._delegate.setInputFilePaths(retargeted, localPaths);
else
} else {
await this._page._delegate.setInputFiles(retargeted, filePayloads!);
}
});
return 'done';
}

View File

@ -105,6 +105,14 @@ it('should upload large file', async ({ page, server, browserName, isMac, isAndr
await Promise.all([uploadFile, file1.filepath].map(fs.promises.unlink));
});
it('should throw an error if the file does not exist', async ({ page, server, asset }) => {
await page.goto(server.PREFIX + '/input/fileupload.html');
const input = await page.$('input');
const error = await input.setInputFiles('i actually do not exist.txt').catch(e => e);
expect(error.message).toContain('ENOENT: no such file or directory');
expect(error.message).toContain('i actually do not exist.txt');
});
it('should upload multiple large files', async ({ page, server, browserName, isMac, isAndroid, isWebView2, mode }, testInfo) => {
it.skip(browserName === 'webkit' && isMac && parseInt(os.release(), 10) < 20, 'WebKit for macOS 10.15 is frozen and does not have corresponding protocol features.');
it.skip(isAndroid);