feat(firefox): support elementHandle.uploadFile (#4058)

Fixes #3762
This commit is contained in:
Andrey Lushnikov 2019-02-22 17:22:46 -08:00 committed by GitHub
parent 1315dc8234
commit f1a14fec5b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 19 additions and 2 deletions

View File

@ -1,4 +1,5 @@
const {assert, debugError} = require('./helper');
const path = require('path');
class JSHandle {
@ -327,6 +328,18 @@ class ElementHandle extends JSHandle {
await this._frame._page.mouse.click(x, y, options);
}
/**
* @param {!Array<string>} filePaths
*/
async uploadFile(...filePaths) {
const files = filePaths.map(filePath => path.resolve(filePath));
await this._session.send('Page.setFileInputFiles', {
frameId: this._frameId,
objectId: this._objectId,
files,
});
}
async hover() {
await this._scrollIntoViewIfNeeded();
const {x, y} = await this._clickablePoint();

View File

@ -26,6 +26,10 @@ pref("browser.newtabpage.activity-stream.feeds.section.topstories", false);
// (bug 1176798, bug 1177018, bug 1210465)
pref("apz.content_response_timeout", 60000);
// Allow creating files in content process - required for
// |Page.setFileInputFiles| protocol method.
pref("dom.file.createInChild", true);
// Indicate that the download panel has been shown once so that
// whichever download test runs first doesn't show the popup
// inconsistently.

View File

@ -9,7 +9,7 @@
"node": ">=8.9.4"
},
"puppeteer": {
"firefox_revision": "86e93329fd528bd28ff1493f117f126b6f010eac"
"firefox_revision": "e0433ecec0642eca12cba778b0587ab2ae06e833"
},
"scripts": {
"install": "node install.js",

View File

@ -21,7 +21,7 @@ module.exports.addTests = function({testRunner, expect}) {
const {it, fit, xit, it_fails_ffox} = testRunner;
const {beforeAll, beforeEach, afterAll, afterEach} = testRunner;
describe('input', function() {
it_fails_ffox('should upload the file', async({page, server}) => {
it('should upload the file', async({page, server}) => {
await page.goto(server.PREFIX + '/input/fileupload.html');
const filePath = path.relative(process.cwd(), __dirname + '/assets/file-to-upload.txt');
const input = await page.$('input');