diff --git a/src/dom.ts b/src/dom.ts index a9736d029f..13f9a9f228 100644 --- a/src/dom.ts +++ b/src/dom.ts @@ -275,17 +275,17 @@ export class ElementHandle extends js.JSHandle { point.y += border.y; } const metrics = await this._world.delegate.layoutViewport(); - // Give 15 extra pixels to avoid any issues on viewport edge. + // Give 20 extra pixels to avoid any issues on viewport edge. let scrollX = 0; - if (point.x < 15) - scrollX = point.x - 15; - if (point.x > metrics.width - 15) - scrollX = point.x - metrics.width + 15; + if (point.x < 20) + scrollX = point.x - 20; + if (point.x > metrics.width - 20) + scrollX = point.x - metrics.width + 20; let scrollY = 0; - if (point.y < 15) - scrollY = point.y - 15; - if (point.y > metrics.height - 15) - scrollY = point.y - metrics.height + 15; + if (point.y < 20) + scrollY = point.y - 20; + if (point.y > metrics.height - 20) + scrollY = point.y - metrics.height + 20; return { point, scrollX, scrollY }; } diff --git a/test/click.spec.js b/test/click.spec.js index af9d121fb2..c2dabe4499 100644 --- a/test/click.spec.js +++ b/test/click.spec.js @@ -93,9 +93,8 @@ module.exports.addTests = function({testRunner, expect, playwright, FFOX, CHROME }); it('should select the text by triple clicking', async({page, server}) => { 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.'; - await page.keyboard.type(text); + await page.fill('textarea', text); await page.tripleclick('textarea'); expect(await page.evaluate(() => { const textarea = document.querySelector('textarea'); @@ -284,12 +283,12 @@ module.exports.addTests = function({testRunner, expect, playwright, FFOX, CHROME }); it('should click the button with px border with relative point', async({page, server}) => { await page.goto(server.PREFIX + '/input/button.html'); - await page.$eval('button', button => button.style.borderWidth = '2px'); + await page.$eval('button', button => button.style.borderWidth = '8px'); await page.click('button', { relativePoint: { x: 20, y: 10 } }); expect(await page.evaluate(() => result)).toBe('Clicked'); // Safari reports border-relative offsetX/offsetY. - expect(await page.evaluate(() => offsetX)).toBe(WEBKIT ? 20 + 2 : 20); - expect(await page.evaluate(() => offsetY)).toBe(WEBKIT ? 10 + 2: 10); + expect(await page.evaluate(() => offsetX)).toBe(WEBKIT ? 20 + 8 : 20); + expect(await page.evaluate(() => offsetY)).toBe(WEBKIT ? 10 + 8 : 10); }); it('should click the button with em border with relative point', async({page, server}) => { await page.goto(server.PREFIX + '/input/button.html'); @@ -303,12 +302,13 @@ module.exports.addTests = function({testRunner, expect, playwright, FFOX, CHROME }); it('should click a very large button with relative point', async({page, server}) => { await page.goto(server.PREFIX + '/input/button.html'); + await page.$eval('button', button => button.style.borderWidth = '8px'); await page.$eval('button', button => button.style.height = button.style.width = '2000px'); await page.click('button', { relativePoint: { x: 1900, y: 1910 } }); expect(await page.evaluate(() => window.result)).toBe('Clicked'); // Safari reports border-relative offsetX/offsetY. - expect(await page.evaluate(() => offsetX)).toBe(WEBKIT ? 2 + 1900 : 1900); - expect(await page.evaluate(() => offsetY)).toBe(WEBKIT ? 2 + 1910 : 1910); + expect(await page.evaluate(() => offsetX)).toBe(WEBKIT ? 1900 + 8 : 1900); + expect(await page.evaluate(() => offsetY)).toBe(WEBKIT ? 1910 + 8 : 1910); }); xit('should click a button in scrolling container with relative point', async({page, server}) => { await page.goto(server.PREFIX + '/input/button.html');