Refactor JavaScript dialog API

This patch introduces a Dialog class and a new 'dialog'
event instead of the 'alert', 'beforeunload', 'confirm' and
'prompt' events and 'Page.handleDialog' method.

Fixes #2.
This commit is contained in:
Andrey Lushnikov
2017-06-15 21:22:41 -07:00
parent 14a75a83ea
commit f62cfc3b34
4 changed files with 110 additions and 27 deletions

View File

@@ -155,6 +155,27 @@ describe('Puppeteer', function() {
expect(failedResources).toBe(1);
}));
});
describe('Page.Events.Dialog', function() {
it('should fire', function(done) {
page.on('dialog', dialog => {
expect(dialog.type).toBe('alert');
expect(dialog.message()).toBe('yo');
done();
});
page.evaluate(() => alert('yo'));
});
// TODO Enable this when crbug.com/718235 is fixed.
xit('should allow accepting prompts', SX(async function(done) {
page.on('dialog', dialog => {
expect(dialog.type).toBe('prompt');
expect(dialog.message()).toBe('question?');
dialog.accept('answer!');
});
var result = await page.evaluate(() => prompt('question?'));
expect(result).toBe('answer!');
}));
});
});
// Since Jasmine doesn't like async functions, they should be wrapped