mirror of
https://github.com/microsoft/playwright.git
synced 2025-06-26 21:40:17 +00:00
fix: throw error if setInputFile does not exist (#29944)
Fixes https://github.com/microsoft/playwright/issues/29941
This commit is contained in:
parent
93dc89fa1f
commit
7cbef691ae
@ -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';
|
||||
}
|
||||
|
||||
@ -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);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user