Skip to content

Commit

Permalink
Fix the intermittent failures with PageOpen/PageClose test
Browse files Browse the repository at this point in the history
  • Loading branch information
calixteman committed Oct 29, 2023
1 parent 6115a32 commit 1867240
Showing 1 changed file with 9 additions and 16 deletions.
25 changes: 9 additions & 16 deletions test/integration/test_utils.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -252,26 +252,19 @@ async function waitForTextLayer(page) {
}

async function scrollIntoView(page, selector) {
const promise = page.evaluate(
() =>
new Promise(resolve => {
document
.getElementById("viewerContainer")
.addEventListener("scrollend", resolve, { once: true });
})
);
await page.evaluate(sel => {
const element = document.querySelector(sel);
element.scrollIntoView({ behavior: "instant", block: "start" });
}, selector);
await page.waitForFunction(
sel => {
const toolbarHeight = document
.querySelector("#toolbarContainer")
.getBoundingClientRect().height;
const element = document.querySelector(sel);
const { top, bottom } = element.getBoundingClientRect();
return (
Math.abs(top) < toolbarHeight + 100 ||
Math.abs(bottom - window.innerHeight) < 100 ||
(top > toolbarHeight && bottom < window.innerHeight)
);
},
{},
selector
);
await promise;
}

async function hover(page, selector) {
Expand Down

0 comments on commit 1867240

Please sign in to comment.