feat: large files upload in ff and wk (#12937)

This commit is contained in:
Yury Semikhatsky 2022-03-25 13:26:12 -07:00 committed by GitHub
parent c8cc62a2e6
commit 97e8ead57c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 22 additions and 7 deletions

View file

@ -533,7 +533,15 @@ export class FFPage implements PageDelegate {
} }
async setInputFilePaths(handle: dom.ElementHandle<HTMLInputElement>, files: string[]): Promise<void> { async setInputFilePaths(handle: dom.ElementHandle<HTMLInputElement>, files: string[]): Promise<void> {
throw new Error('Not implemented'); await Promise.all([
this._session.send('Page.setFileInputFiles', {
frameId: handle._context.frame._id,
objectId: handle._objectId,
files
}),
handle.dispatchEvent('input'),
handle.dispatchEvent('change')
]);
} }
async adoptElementHandle<T extends Node>(handle: dom.ElementHandle<T>, to: dom.FrameExecutionContext): Promise<dom.ElementHandle<T>> { async adoptElementHandle<T extends Node>(handle: dom.ElementHandle<T>, to: dom.FrameExecutionContext): Promise<dom.ElementHandle<T>> {

View file

@ -936,8 +936,13 @@ export class WKPage implements PageDelegate {
await this._session.send('DOM.setInputFiles', { objectId, files: protocolFiles }); await this._session.send('DOM.setInputFiles', { objectId, files: protocolFiles });
} }
async setInputFilePaths(handle: dom.ElementHandle<HTMLInputElement>, files: string[]): Promise<void> { async setInputFilePaths(handle: dom.ElementHandle<HTMLInputElement>, paths: string[]): Promise<void> {
throw new Error('Not implemented'); const pageProxyId = this._pageProxySession.sessionId;
const objectId = handle._objectId;
await Promise.all([
this._pageProxySession.connection.browserSession.send('Playwright.grantFileReadAccess', { pageProxyId, paths }),
this._session.send('DOM.setInputFiles', { objectId, paths })
]);
} }
async adoptElementHandle<T extends Node>(handle: dom.ElementHandle<T>, to: dom.FrameExecutionContext): Promise<dom.ElementHandle<T>> { async adoptElementHandle<T extends Node>(handle: dom.ElementHandle<T>, to: dom.FrameExecutionContext): Promise<dom.ElementHandle<T>> {

View file

@ -16,6 +16,7 @@
*/ */
import fs from 'fs'; import fs from 'fs';
import os from 'os';
import * as path from 'path'; import * as path from 'path';
import { getUserAgent } from '../packages/playwright-core/lib/utils/utils'; import { getUserAgent } from '../packages/playwright-core/lib/utils/utils';
import WebSocket from 'ws'; import WebSocket from 'ws';
@ -574,8 +575,8 @@ test('should fulfill with global fetch result', async ({ browserType, startRemot
expect(await response.json()).toEqual({ 'foo': 'bar' }); expect(await response.json()).toEqual({ 'foo': 'bar' });
}); });
test('should upload large file', async ({ browserType, startRemoteServer, server, browserName }, testInfo) => { test('should upload large file', async ({ browserType, startRemoteServer, server, browserName, isMac }, testInfo) => {
test.skip(browserName !== 'chromium'); test.skip(browserName === 'webkit' && isMac && parseInt(os.release(), 10) < 20, 'WebKit for macOS 10.15 is frozen and does not have corresponding protocol features.');
test.slow(); test.slow();
const remoteServer = await startRemoteServer(); const remoteServer = await startRemoteServer();
const browser = await browserType.connect(remoteServer.wsEndpoint()); const browser = await browserType.connect(remoteServer.wsEndpoint());

View file

@ -20,6 +20,7 @@ import { attachFrame } from '../config/utils';
import path from 'path'; import path from 'path';
import fs from 'fs'; import fs from 'fs';
import os from 'os';
import formidable from 'formidable'; import formidable from 'formidable';
it('should upload the file', async ({ page, server, asset }) => { it('should upload the file', async ({ page, server, asset }) => {
@ -36,8 +37,8 @@ it('should upload the file', async ({ page, server, asset }) => {
}, input)).toBe('contents of the file'); }, input)).toBe('contents of the file');
}); });
it('should upload large file', async ({ page, server, browserName }, testInfo) => { it('should upload large file', async ({ page, server, browserName, isMac }, testInfo) => {
it.skip(browserName !== 'chromium'); 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.slow(); it.slow();
await page.goto(server.PREFIX + '/input/fileupload.html'); await page.goto(server.PREFIX + '/input/fileupload.html');
const uploadFile = testInfo.outputPath('200MB.zip'); const uploadFile = testInfo.outputPath('200MB.zip');