mirror of
https://github.com/puppeteer/puppeteer
synced 2024-06-14 14:02:48 +00:00
Implement Page.uploadFile (#61)
This patch implements `Page.uploadFile` method to support file upload inputs.
This commit is contained in:
committed by
Andrey Lushnikov
parent
739c1566a9
commit
da0cde1b45
24
test/test.js
24
test/test.js
@@ -544,6 +544,15 @@ describe('Puppeteer', function() {
|
||||
await page.click('button');
|
||||
expect(await page.evaluate(() => result)).toBe('Clicked');
|
||||
}));
|
||||
it('should fail to click a missing button', SX(async function() {
|
||||
await page.navigate(STATIC_PREFIX + '/input/button.html');
|
||||
try {
|
||||
await page.click('button.does-not-exist');
|
||||
fail('Clicking the button did not throw.');
|
||||
} catch (error) {
|
||||
expect(error.message).toBe('No node found for selector: button.does-not-exist');
|
||||
}
|
||||
}));
|
||||
it('should type into the textarea', SX(async function() {
|
||||
await page.navigate(STATIC_PREFIX + '/input/textarea.html');
|
||||
await page.focus('textarea');
|
||||
@@ -557,6 +566,21 @@ describe('Puppeteer', function() {
|
||||
await page.click('button');
|
||||
expect(await page.evaluate(() => result)).toBe('Clicked');
|
||||
}));
|
||||
it('should upload the file', SX(async function(){
|
||||
await page.navigate(STATIC_PREFIX + '/input/fileupload.html');
|
||||
await page.uploadFile('input', __dirname + '/assets/file-to-upload.txt');
|
||||
expect(await page.evaluate(() => {
|
||||
let input = document.querySelector('input');
|
||||
return input.files[0].name;
|
||||
})).toBe('file-to-upload.txt');
|
||||
expect(await page.evaluate(() => {
|
||||
let input = document.querySelector('input');
|
||||
let reader = new FileReader();
|
||||
let promise = new Promise(fulfill => reader.onload = fulfill);
|
||||
reader.readAsText(input.files[0]);
|
||||
return promise.then(() => reader.result);
|
||||
})).toBe('contents of the file');
|
||||
}));
|
||||
});
|
||||
describe('Page.setUserAgent', function() {
|
||||
it('should work', SX(async function() {
|
||||
|
||||
Reference in New Issue
Block a user