mirror of
https://github.com/puppeteer/puppeteer
synced 2024-06-14 14:02:48 +00:00
chore: add Prettier (#5825)
This commit is contained in:
@@ -15,21 +15,25 @@
|
||||
*/
|
||||
|
||||
const expect = require('expect');
|
||||
const {getTestState,setupTestPageAndContextHooks, setupTestBrowserHooks} = require('./mocha-utils');
|
||||
const {
|
||||
getTestState,
|
||||
setupTestPageAndContextHooks,
|
||||
setupTestBrowserHooks,
|
||||
} = require('./mocha-utils');
|
||||
const utils = require('./utils');
|
||||
|
||||
describe('Page.click', function() {
|
||||
describe('Page.click', function () {
|
||||
setupTestBrowserHooks();
|
||||
setupTestPageAndContextHooks();
|
||||
it('should click the button', async() => {
|
||||
const {page, server} = getTestState();
|
||||
it('should click the button', async () => {
|
||||
const { page, server } = getTestState();
|
||||
|
||||
await page.goto(server.PREFIX + '/input/button.html');
|
||||
await page.click('button');
|
||||
expect(await page.evaluate(() => result)).toBe('Clicked');
|
||||
});
|
||||
itFailsFirefox('should click svg', async() => {
|
||||
const {page} = getTestState();
|
||||
itFailsFirefox('should click svg', async () => {
|
||||
const { page } = getTestState();
|
||||
|
||||
await page.setContent(`
|
||||
<svg height="100" width="100">
|
||||
@@ -39,19 +43,24 @@ describe('Page.click', function() {
|
||||
await page.click('circle');
|
||||
expect(await page.evaluate(() => window.__CLICKED)).toBe(42);
|
||||
});
|
||||
itFailsFirefox('should click the button if window.Node is removed', async() => {
|
||||
const {page, server} = getTestState();
|
||||
itFailsFirefox(
|
||||
'should click the button if window.Node is removed',
|
||||
async () => {
|
||||
const { page, server } = getTestState();
|
||||
|
||||
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');
|
||||
});
|
||||
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');
|
||||
}
|
||||
);
|
||||
// @see https://github.com/puppeteer/puppeteer/issues/4281
|
||||
itFailsFirefox('should click on a span with an inline element inside', async() => {
|
||||
const {page} = getTestState();
|
||||
itFailsFirefox(
|
||||
'should click on a span with an inline element inside',
|
||||
async () => {
|
||||
const { page } = getTestState();
|
||||
|
||||
await page.setContent(`
|
||||
await page.setContent(`
|
||||
<style>
|
||||
span::before {
|
||||
content: 'q';
|
||||
@@ -59,20 +68,21 @@ describe('Page.click', function() {
|
||||
</style>
|
||||
<span onclick='javascript:window.CLICKED=42'></span>
|
||||
`);
|
||||
await page.click('span');
|
||||
expect(await page.evaluate(() => window.CLICKED)).toBe(42);
|
||||
});
|
||||
it('should not throw UnhandledPromiseRejection when page closes', async() => {
|
||||
const {page} = getTestState();
|
||||
await page.click('span');
|
||||
expect(await page.evaluate(() => window.CLICKED)).toBe(42);
|
||||
}
|
||||
);
|
||||
it('should not throw UnhandledPromiseRejection when page closes', async () => {
|
||||
const { page } = getTestState();
|
||||
|
||||
const newPage = await page.browser().newPage();
|
||||
await Promise.all([
|
||||
newPage.close(),
|
||||
newPage.mouse.click(1, 2),
|
||||
]).catch(error => {});
|
||||
]).catch((error) => {});
|
||||
});
|
||||
it('should click the button after navigation ', async() => {
|
||||
const {page, server} = getTestState();
|
||||
it('should click the button after navigation ', async () => {
|
||||
const { page, server } = getTestState();
|
||||
|
||||
await page.goto(server.PREFIX + '/input/button.html');
|
||||
await page.click('button');
|
||||
@@ -80,21 +90,20 @@ describe('Page.click', function() {
|
||||
await page.click('button');
|
||||
expect(await page.evaluate(() => result)).toBe('Clicked');
|
||||
});
|
||||
itFailsFirefox('should click with disabled javascript', async() => {
|
||||
const {page, server} = getTestState();
|
||||
itFailsFirefox('should click with disabled javascript', async () => {
|
||||
const { page, server } = getTestState();
|
||||
|
||||
await page.setJavaScriptEnabled(false);
|
||||
await page.goto(server.PREFIX + '/wrappedlink.html');
|
||||
await Promise.all([
|
||||
page.click('a'),
|
||||
page.waitForNavigation()
|
||||
]);
|
||||
await Promise.all([page.click('a'), page.waitForNavigation()]);
|
||||
expect(page.url()).toBe(server.PREFIX + '/wrappedlink.html#clicked');
|
||||
});
|
||||
itFailsFirefox('should click when one of inline box children is outside of viewport', async() => {
|
||||
const {page} = getTestState();
|
||||
itFailsFirefox(
|
||||
'should click when one of inline box children is outside of viewport',
|
||||
async () => {
|
||||
const { page } = getTestState();
|
||||
|
||||
await page.setContent(`
|
||||
await page.setContent(`
|
||||
<style>
|
||||
i {
|
||||
position: absolute;
|
||||
@@ -103,30 +112,37 @@ describe('Page.click', function() {
|
||||
</style>
|
||||
<span onclick='javascript:window.CLICKED = 42;'><i>woof</i><b>doggo</b></span>
|
||||
`);
|
||||
await page.click('span');
|
||||
expect(await page.evaluate(() => window.CLICKED)).toBe(42);
|
||||
});
|
||||
it('should select the text by triple clicking', async() => {
|
||||
const {page, server} = getTestState();
|
||||
await page.click('span');
|
||||
expect(await page.evaluate(() => window.CLICKED)).toBe(42);
|
||||
}
|
||||
);
|
||||
it('should select the text by triple clicking', async () => {
|
||||
const { page, server } = getTestState();
|
||||
|
||||
await page.goto(server.PREFIX + '/input/textarea.html');
|
||||
await page.focus('textarea');
|
||||
const text = 'This is the text that we are going to try to select. Let\'s see how it goes.';
|
||||
const text =
|
||||
"This is the text that we are going to try to select. Let's see how it goes.";
|
||||
await page.keyboard.type(text);
|
||||
await page.click('textarea');
|
||||
await page.click('textarea', {clickCount: 2});
|
||||
await page.click('textarea', {clickCount: 3});
|
||||
expect(await page.evaluate(() => {
|
||||
const textarea = document.querySelector('textarea');
|
||||
return textarea.value.substring(textarea.selectionStart, textarea.selectionEnd);
|
||||
})).toBe(text);
|
||||
await page.click('textarea', { clickCount: 2 });
|
||||
await page.click('textarea', { clickCount: 3 });
|
||||
expect(
|
||||
await page.evaluate(() => {
|
||||
const textarea = document.querySelector('textarea');
|
||||
return textarea.value.substring(
|
||||
textarea.selectionStart,
|
||||
textarea.selectionEnd
|
||||
);
|
||||
})
|
||||
).toBe(text);
|
||||
});
|
||||
itFailsFirefox('should click offscreen buttons', async() => {
|
||||
const {page, server} = getTestState();
|
||||
itFailsFirefox('should click offscreen buttons', async () => {
|
||||
const { page, server } = getTestState();
|
||||
|
||||
await page.goto(server.PREFIX + '/offscreenbuttons.html');
|
||||
const messages = [];
|
||||
page.on('console', msg => messages.push(msg.text()));
|
||||
page.on('console', (msg) => messages.push(msg.text()));
|
||||
for (let i = 0; i < 11; ++i) {
|
||||
// We might've scrolled to click a button - reset to (0, 0).
|
||||
await page.evaluate(() => window.scrollTo(0, 0));
|
||||
@@ -143,20 +159,20 @@ describe('Page.click', function() {
|
||||
'button #7 clicked',
|
||||
'button #8 clicked',
|
||||
'button #9 clicked',
|
||||
'button #10 clicked'
|
||||
'button #10 clicked',
|
||||
]);
|
||||
});
|
||||
|
||||
it('should click wrapped links', async() => {
|
||||
const {page, server} = getTestState();
|
||||
it('should click wrapped links', async () => {
|
||||
const { page, server } = getTestState();
|
||||
|
||||
await page.goto(server.PREFIX + '/wrappedlink.html');
|
||||
await page.click('a');
|
||||
expect(await page.evaluate(() => window.__clicked)).toBe(true);
|
||||
});
|
||||
|
||||
it('should click on checkbox input and toggle', async() => {
|
||||
const {page, server} = getTestState();
|
||||
it('should click on checkbox input and toggle', async () => {
|
||||
const { page, server } = getTestState();
|
||||
|
||||
await page.goto(server.PREFIX + '/input/checkbox.html');
|
||||
expect(await page.evaluate(() => result.check)).toBe(null);
|
||||
@@ -176,8 +192,8 @@ describe('Page.click', function() {
|
||||
expect(await page.evaluate(() => result.check)).toBe(false);
|
||||
});
|
||||
|
||||
itFailsFirefox('should click on checkbox label and toggle', async() => {
|
||||
const {page, server} = getTestState();
|
||||
itFailsFirefox('should click on checkbox label and toggle', async () => {
|
||||
const { page, server } = getTestState();
|
||||
|
||||
await page.goto(server.PREFIX + '/input/checkbox.html');
|
||||
expect(await page.evaluate(() => result.check)).toBe(null);
|
||||
@@ -192,50 +208,60 @@ describe('Page.click', function() {
|
||||
expect(await page.evaluate(() => result.check)).toBe(false);
|
||||
});
|
||||
|
||||
it('should fail to click a missing button', async() => {
|
||||
const {page, server} = getTestState();
|
||||
it('should fail to click a missing button', async () => {
|
||||
const { page, server } = getTestState();
|
||||
|
||||
await page.goto(server.PREFIX + '/input/button.html');
|
||||
let error = null;
|
||||
await page.click('button.does-not-exist').catch(error_ => error = error_);
|
||||
expect(error.message).toBe('No node found for selector: button.does-not-exist');
|
||||
await page
|
||||
.click('button.does-not-exist')
|
||||
.catch((error_) => (error = error_));
|
||||
expect(error.message).toBe(
|
||||
'No node found for selector: button.does-not-exist'
|
||||
);
|
||||
});
|
||||
// @see https://github.com/puppeteer/puppeteer/issues/161
|
||||
it('should not hang with touch-enabled viewports', async() => {
|
||||
const {page, puppeteer} = getTestState();
|
||||
it('should not hang with touch-enabled viewports', async () => {
|
||||
const { page, puppeteer } = getTestState();
|
||||
|
||||
await page.setViewport(puppeteer.devices['iPhone 6'].viewport);
|
||||
await page.mouse.down();
|
||||
await page.mouse.move(100, 10);
|
||||
await page.mouse.up();
|
||||
});
|
||||
it('should scroll and click the button', async() => {
|
||||
const {page, server} = getTestState();
|
||||
it('should scroll and click the button', async () => {
|
||||
const { page, server } = getTestState();
|
||||
|
||||
await page.goto(server.PREFIX + '/input/scrollable.html');
|
||||
await page.click('#button-5');
|
||||
expect(await page.evaluate(() => document.querySelector('#button-5').textContent)).toBe('clicked');
|
||||
expect(
|
||||
await page.evaluate(() => document.querySelector('#button-5').textContent)
|
||||
).toBe('clicked');
|
||||
await page.click('#button-80');
|
||||
expect(await page.evaluate(() => document.querySelector('#button-80').textContent)).toBe('clicked');
|
||||
expect(
|
||||
await page.evaluate(
|
||||
() => document.querySelector('#button-80').textContent
|
||||
)
|
||||
).toBe('clicked');
|
||||
});
|
||||
itFailsFirefox('should double click the button', async() => {
|
||||
const {page, server} = getTestState();
|
||||
itFailsFirefox('should double click the button', async () => {
|
||||
const { page, server } = getTestState();
|
||||
|
||||
await page.goto(server.PREFIX + '/input/button.html');
|
||||
await page.evaluate(() => {
|
||||
window.double = false;
|
||||
const button = document.querySelector('button');
|
||||
button.addEventListener('dblclick', event => {
|
||||
button.addEventListener('dblclick', (event) => {
|
||||
window.double = true;
|
||||
});
|
||||
});
|
||||
const button = await page.$('button');
|
||||
await button.click({clickCount: 2});
|
||||
await button.click({ clickCount: 2 });
|
||||
expect(await page.evaluate('double')).toBe(true);
|
||||
expect(await page.evaluate('result')).toBe('Clicked');
|
||||
});
|
||||
it('should click a partially obscured button', async() => {
|
||||
const {page, server} = getTestState();
|
||||
it('should click a partially obscured button', async () => {
|
||||
const { page, server } = getTestState();
|
||||
|
||||
await page.goto(server.PREFIX + '/input/button.html');
|
||||
await page.evaluate(() => {
|
||||
@@ -247,62 +273,85 @@ describe('Page.click', function() {
|
||||
await page.click('button');
|
||||
expect(await page.evaluate(() => window.result)).toBe('Clicked');
|
||||
});
|
||||
it('should click a rotated button', async() => {
|
||||
const {page, server} = getTestState();
|
||||
it('should click a rotated button', async () => {
|
||||
const { page, server } = getTestState();
|
||||
|
||||
await page.goto(server.PREFIX + '/input/rotatedButton.html');
|
||||
await page.click('button');
|
||||
expect(await page.evaluate(() => result)).toBe('Clicked');
|
||||
});
|
||||
it('should fire contextmenu event on right click', async() => {
|
||||
const {page, server} = getTestState();
|
||||
it('should fire contextmenu event on right click', async () => {
|
||||
const { page, server } = getTestState();
|
||||
|
||||
await page.goto(server.PREFIX + '/input/scrollable.html');
|
||||
await page.click('#button-8', {button: 'right'});
|
||||
expect(await page.evaluate(() => document.querySelector('#button-8').textContent)).toBe('context menu');
|
||||
await page.click('#button-8', { button: 'right' });
|
||||
expect(
|
||||
await page.evaluate(() => document.querySelector('#button-8').textContent)
|
||||
).toBe('context menu');
|
||||
});
|
||||
// @see https://github.com/puppeteer/puppeteer/issues/206
|
||||
itFailsFirefox('should click links which cause navigation', async() => {
|
||||
const {page, server} = getTestState();
|
||||
itFailsFirefox('should click links which cause navigation', async () => {
|
||||
const { page, server } = getTestState();
|
||||
|
||||
await page.setContent(`<a href="${server.EMPTY_PAGE}">empty.html</a>`);
|
||||
// This await should not hang.
|
||||
await page.click('a');
|
||||
});
|
||||
itFailsFirefox('should click the button inside an iframe', async() => {
|
||||
const {page, server} = getTestState();
|
||||
itFailsFirefox('should click the button inside an iframe', async () => {
|
||||
const { page, server } = getTestState();
|
||||
|
||||
await page.goto(server.EMPTY_PAGE);
|
||||
await page.setContent('<div style="width:100px;height:100px">spacer</div>');
|
||||
await utils.attachFrame(page, 'button-test', server.PREFIX + '/input/button.html');
|
||||
await utils.attachFrame(
|
||||
page,
|
||||
'button-test',
|
||||
server.PREFIX + '/input/button.html'
|
||||
);
|
||||
const frame = page.frames()[1];
|
||||
const button = await frame.$('button');
|
||||
await button.click();
|
||||
expect(await frame.evaluate(() => window.result)).toBe('Clicked');
|
||||
});
|
||||
// @see https://github.com/puppeteer/puppeteer/issues/4110
|
||||
xit('should click the button with fixed position inside an iframe', async() => {
|
||||
const {page, server} = getTestState();
|
||||
xit('should click the button with fixed position inside an iframe', async () => {
|
||||
const { page, server } = getTestState();
|
||||
|
||||
await page.goto(server.EMPTY_PAGE);
|
||||
await page.setViewport({width: 500, height: 500});
|
||||
await page.setContent('<div style="width:100px;height:2000px">spacer</div>');
|
||||
await utils.attachFrame(page, 'button-test', server.CROSS_PROCESS_PREFIX + '/input/button.html');
|
||||
await page.setViewport({ width: 500, height: 500 });
|
||||
await page.setContent(
|
||||
'<div style="width:100px;height:2000px">spacer</div>'
|
||||
);
|
||||
await utils.attachFrame(
|
||||
page,
|
||||
'button-test',
|
||||
server.CROSS_PROCESS_PREFIX + '/input/button.html'
|
||||
);
|
||||
const frame = page.frames()[1];
|
||||
await frame.$eval('button', button => button.style.setProperty('position', 'fixed'));
|
||||
await frame.$eval('button', (button) =>
|
||||
button.style.setProperty('position', 'fixed')
|
||||
);
|
||||
await frame.click('button');
|
||||
expect(await frame.evaluate(() => window.result)).toBe('Clicked');
|
||||
});
|
||||
itFailsFirefox('should click the button with deviceScaleFactor set', async() => {
|
||||
const {page, server} = getTestState();
|
||||
itFailsFirefox(
|
||||
'should click the button with deviceScaleFactor set',
|
||||
async () => {
|
||||
const { page, server } = getTestState();
|
||||
|
||||
await page.setViewport({width: 400, height: 400, deviceScaleFactor: 5});
|
||||
expect(await page.evaluate(() => window.devicePixelRatio)).toBe(5);
|
||||
await page.setContent('<div style="width:100px;height:100px">spacer</div>');
|
||||
await utils.attachFrame(page, 'button-test', server.PREFIX + '/input/button.html');
|
||||
const frame = page.frames()[1];
|
||||
const button = await frame.$('button');
|
||||
await button.click();
|
||||
expect(await frame.evaluate(() => window.result)).toBe('Clicked');
|
||||
});
|
||||
await page.setViewport({ width: 400, height: 400, deviceScaleFactor: 5 });
|
||||
expect(await page.evaluate(() => window.devicePixelRatio)).toBe(5);
|
||||
await page.setContent(
|
||||
'<div style="width:100px;height:100px">spacer</div>'
|
||||
);
|
||||
await utils.attachFrame(
|
||||
page,
|
||||
'button-test',
|
||||
server.PREFIX + '/input/button.html'
|
||||
);
|
||||
const frame = page.frames()[1];
|
||||
const button = await frame.$('button');
|
||||
await button.click();
|
||||
expect(await frame.evaluate(() => window.result)).toBe('Clicked');
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user