feat(page): use secondary world to drive clicks (#3828)

References #2671
This commit is contained in:
Andrey Lushnikov 2019-01-22 23:24:14 -05:00 committed by GitHub
parent 89a5c396bf
commit fb710120e9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 19 additions and 7 deletions

View File

@ -472,7 +472,7 @@ class Frame {
* @return {!Promise<String>}
*/
async content() {
return this._mainWorld.content();
return this._secondaryWorld.content();
}
/**
@ -480,7 +480,7 @@ class Frame {
* @param {!{timeout?: number, waitUntil?: string|!Array<string>}=} options
*/
async setContent(html, options = {}) {
return this._mainWorld.setContent(html, options);
return this._secondaryWorld.setContent(html, options);
}
/**
@ -539,21 +539,21 @@ class Frame {
* @param {!{delay?: number, button?: "left"|"right"|"middle", clickCount?: number}=} options
*/
async click(selector, options) {
return this._mainWorld.click(selector, options);
return this._secondaryWorld.click(selector, options);
}
/**
* @param {string} selector
*/
async focus(selector) {
return this._mainWorld.focus(selector);
return this._secondaryWorld.focus(selector);
}
/**
* @param {string} selector
*/
async hover(selector) {
return this._mainWorld.hover(selector);
return this._secondaryWorld.hover(selector);
}
/**
@ -569,7 +569,7 @@ class Frame {
* @param {string} selector
*/
async tap(selector) {
return this._mainWorld.tap(selector);
return this._secondaryWorld.tap(selector);
}
/**
@ -634,7 +634,7 @@ class Frame {
* @return {!Promise<string>}
*/
async title() {
return this._mainWorld.title();
return this._secondaryWorld.title();
}
/**

View File

@ -28,6 +28,12 @@ module.exports.addTests = function({testRunner, expect}) {
await page.click('button');
expect(await page.evaluate(() => result)).toBe('Clicked');
});
it('should click the button if window.Node is removed', async({page, server}) => {
await page.goto(server.PREFIX + '/input/button.html');
await page.evaluate(() => delete window.Node);
await page.click('button');
expect(await page.evaluate(() => result)).toBe('Clicked');
});
it('should click the button after navigation ', async({page, server}) => {
await page.goto(server.PREFIX + '/input/button.html');
await page.click('button');

View File

@ -64,6 +64,12 @@ module.exports.addTests = function({testRunner, expect}) {
await page.hover('#button-91');
expect(await page.evaluate(() => document.querySelector('button:hover').id)).toBe('button-91');
});
it('should trigger hover state with removed window.Node', async({page, server}) => {
await page.goto(server.PREFIX + '/input/scrollable.html');
await page.evaluate(() => delete window.Node);
await page.hover('#button-6');
expect(await page.evaluate(() => document.querySelector('button:hover').id)).toBe('button-6');
});
it('should set modifier keys on click', async({page, server}) => {
await page.goto(server.PREFIX + '/input/scrollable.html');
await page.evaluate(() => document.querySelector('#button-3').addEventListener('mousedown', e => window.lastEvent = e, true));