Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/helper/Playwright.js
Original file line number Diff line number Diff line change
Expand Up @@ -1525,6 +1525,7 @@ class Playwright extends Helper {
assertElementExists(el, locator)
}

await el.scrollIntoViewIfNeeded()
// Use manual mouse.move instead of .hover() so the offset can be added to the coordinates
const { x, y } = await clickablePoint(el)
await this.page.mouse.move(x + offsetX, y + offsetY)
Expand Down
3 changes: 3 additions & 0 deletions lib/helper/Puppeteer.js
Original file line number Diff line number Diff line change
Expand Up @@ -845,6 +845,9 @@ class Puppeteer extends Helper {
}
}

if (!(await el.isIntersectingViewport({ threshold: 1 }))) {
await el.evaluate(el => el.scrollIntoView({ block: 'center', inline: 'center' }))
}
// Use manual mouse.move instead of .hover() so the offset can be added to the coordinates
const { x, y } = await getClickablePoint(el)
await this.page.mouse.move(x + offsetX, y + offsetY)
Expand Down
3 changes: 3 additions & 0 deletions test/data/app/view/form/hover.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,8 @@

<div id="show"></div>

<div id="offscreen_show"></div>
<span id="offscreen_hover" style="display: inline-block; margin-top: 2000px" onmouseover="document.getElementById('offscreen_show').innerText = 'Hovered offscreen!'">Hover me too!</span>

</body>
</html>
12 changes: 12 additions & 0 deletions test/helper/Playwright_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,18 @@ describe('Playwright', function () {
I.amOnPage('/form/hover')
.then(() => I.moveCursorTo('#hover', 'body'))
.then(() => I.see('Hovered', '#show')))

it('should scroll element into view before hovering', async () => {
await I.amOnPage('/form/hover')
await I.moveCursorTo('#offscreen_hover')
await I.see('Hovered offscreen', '#offscreen_show')
})

it('should scroll element into view before hovering within a context', async () => {
await I.amOnPage('/form/hover')
await I.moveCursorTo('#offscreen_hover', 'body')
await I.see('Hovered offscreen', '#offscreen_show')
})
})

describe('#switchToNextTab, #switchToPreviousTab, #openNewTab, #closeCurrentTab, #closeOtherTabs, #grabNumberOfOpenTabs, #waitForNumberOfTabs', () => {
Expand Down
12 changes: 12 additions & 0 deletions test/helper/Puppeteer_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,18 @@ describe('Puppeteer', function () {
I.amOnPage('/form/hover')
.then(() => I.moveCursorTo('#hover', 'body'))
.then(() => I.see('Hovered', '#show')))

it('should scroll element into view before hovering', async () => {
await I.amOnPage('/form/hover')
await I.moveCursorTo('#offscreen_hover')
await I.see('Hovered offscreen', '#offscreen_show')
})

it('should scroll element into view before hovering within a context', async () => {
await I.amOnPage('/form/hover')
await I.moveCursorTo('#offscreen_hover', 'body')
await I.see('Hovered offscreen', '#offscreen_show')
})
})

describe('#switchToNextTab, #switchToPreviousTab, #openNewTab, #closeCurrentTab, #closeOtherTabs, #grabNumberOfOpenTabs, #waitForNumberOfTabs', () => {
Expand Down
Loading