Skip to content

Commit

Permalink
fix(click): timing out in page while waiting for interactable should …
Browse files Browse the repository at this point in the history
…have proper error (#1199)

This fixes flaky 'Page.click should timeout waiting for visible' test.
  • Loading branch information
dgozman authored Mar 4, 2020
1 parent 23790f7 commit 15c70c9
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/injected/injected.ts
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ class Injected {
throw new Error('Not a checkbox');
}

waitForDisplayedAtStablePosition(node: Node, timeout: number) {
async waitForDisplayedAtStablePosition(node: Node, timeout: number) {
if (!node.isConnected)
throw new Error('Element is not attached to the DOM');
const element = node.nodeType === Node.ELEMENT_NODE ? (node as Element) : node.parentElement;
Expand All @@ -375,7 +375,7 @@ class Injected {

let lastRect: types.Rect | undefined;
let counter = 0;
return this.poll('raf', undefined, timeout, () => {
const result = await this.poll('raf', undefined, timeout, () => {
// First raf happens in the same animation frame as evaluation, so it does not produce
// any client rect difference compared to synchronous call. We skip the synchronous call
// and only force layout during actual rafs as a small optimisation.
Expand All @@ -387,18 +387,22 @@ class Injected {
lastRect = rect;
return isDisplayedAndStable;
});
if (!result)
throw new Error(`waiting for element to be displayed and not moving failed: timeout ${timeout}ms exceeded`);
}

waitForHitTargetAt(node: Node, timeout: number, point: types.Point) {
async waitForHitTargetAt(node: Node, timeout: number, point: types.Point) {
const element = node.nodeType === Node.ELEMENT_NODE ? (node as Element) : node.parentElement;
if (!element)
throw new Error('Element is not attached to the DOM');
return this.poll('raf', undefined, timeout, () => {
const result = await this.poll('raf', undefined, timeout, () => {
let hitElement = this.utils.deepElementFromPoint(document, point.x, point.y);
while (hitElement && hitElement !== element)
hitElement = this.utils.parentElementOrShadowHost(hitElement);
return hitElement === element;
});
if (!result)
throw new Error(`waiting for element to receive mouse events failed: timeout ${timeout}ms exceeded`);
}
}

Expand Down

0 comments on commit 15c70c9

Please sign in to comment.