Skip to content

Commit

Permalink
feat(firefox): support elementHandle.uploadFile (#4058)
Browse files Browse the repository at this point in the history
Fixes #3762
  • Loading branch information
aslushnikov committed Feb 23, 2019
1 parent 1315dc8 commit f1a14fe
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 2 deletions.
13 changes: 13 additions & 0 deletions experimental/puppeteer-firefox/lib/JSHandle.js
@@ -1,4 +1,5 @@
const {assert, debugError} = require('./helper');
const path = require('path');

class JSHandle {

Expand Down Expand Up @@ -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();
Expand Down
4 changes: 4 additions & 0 deletions experimental/puppeteer-firefox/misc/puppeteer.cfg
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion experimental/puppeteer-firefox/package.json
Expand Up @@ -9,7 +9,7 @@
"node": ">=8.9.4"
},
"puppeteer": {
"firefox_revision": "86e93329fd528bd28ff1493f117f126b6f010eac"
"firefox_revision": "e0433ecec0642eca12cba778b0587ab2ae06e833"
},
"scripts": {
"install": "node install.js",
Expand Down
2 changes: 1 addition & 1 deletion test/input.spec.js
Expand Up @@ -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');
Expand Down

0 comments on commit f1a14fe

Please sign in to comment.