Skip to content

Commit

Permalink
fix(click): force any hover effects before waiting for hit target (#1869
Browse files Browse the repository at this point in the history
)

This way, any on-hover animations or click blockers will be accounted for.
  • Loading branch information
dgozman authored Apr 20, 2020
1 parent 6231d50 commit effeaaf
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/dom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ export class ElementHandle<T extends Node = Node> extends js.JSHandle<T> {
const point = position ? await this._offsetPoint(position) : await this._clickablePoint();
point.x = (point.x * 100 | 0) / 100;
point.y = (point.y * 100 | 0) / 100;
await this._page.mouse.move(point.x, point.y); // Force any hover effects before waiting for hit target.
if (!force)
await this._waitForHitTargetAt(point, deadline);

Expand Down
31 changes: 31 additions & 0 deletions test/click.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ describe('Page.click', function() {
'mouseover',
'mouseenter',
'mousemove',
'mousemove',
'mousedown',
'mouseup',
'click',
Expand Down Expand Up @@ -596,6 +597,36 @@ describe('Page.click', function() {
expect(clicked).toBe(true);
expect(await page.evaluate(() => window.clicked)).toBe(true);
});
it('should fail when element is blocked on hover', async({page, server}) => {
await page.setContent(`<style>
container { display: block; position: relative; width: 200px; height: 50px; }
div, button { position: absolute; left: 0; top: 0; bottom: 0; right: 0; }
div { pointer-events: none; }
container:hover div { pointer-events: auto; background: red; }
</style>
<container>
<button onclick="window.clicked=true">Click me</button>
<div></div>
</container>`);
const error = await page.click('button', { timeout: 3000 }).catch(e => e);
expect(error.message).toBe('waiting for element to receive pointer events failed: timeout exceeded');
expect(await page.evaluate(() => window.clicked)).toBe(undefined);
});
it('should wait while element is blocked on hover', async({page, server}) => {
await page.setContent(`<style>
@keyframes move-out { from { marign-left: 0; } to { margin-left: 150px; } }
container { display: block; position: relative; width: 200px; height: 50px; }
div, button { position: absolute; left: 0; top: 0; bottom: 0; right: 0; }
div { pointer-events: none; }
container:hover div { pointer-events: auto; background: red; animation: 3s linear move-out; animation-fill-mode: forwards; }
</style>
<container>
<button onclick="window.clicked=true">Click me</button>
<div></div>
</container>`);
await page.click('button');
expect(await page.evaluate(() => window.clicked)).toBe(true);
});
});

describe('Page.check', function() {
Expand Down

0 comments on commit effeaaf

Please sign in to comment.