From 66b1a1f34b2a4f47fd38eb29538037f0359d8793 Mon Sep 17 00:00:00 2001 From: Calixte Denizet Date: Sun, 29 Oct 2023 18:20:58 +0100 Subject: [PATCH] Fix the intermittent failures with PageOpen/PageClose test --- test/integration/scripting_spec.mjs | 2 +- test/integration/test_utils.mjs | 21 +++++---------------- 2 files changed, 6 insertions(+), 17 deletions(-) diff --git a/test/integration/scripting_spec.mjs b/test/integration/scripting_spec.mjs index fc0700551..83d5bfeeb 100644 --- a/test/integration/scripting_spec.mjs +++ b/test/integration/scripting_spec.mjs @@ -816,7 +816,7 @@ describe("Interaction", () => { "window.PDFViewerApplication.scriptingReady === true" ); - await scrollIntoView(page, getSelector("171R")); + await scrollIntoView(page, getSelector("138R")); let sum = 0; for (const [id, val] of [ diff --git a/test/integration/test_utils.mjs b/test/integration/test_utils.mjs index d5114b20a..ea8c06d96 100644 --- a/test/integration/test_utils.mjs +++ b/test/integration/test_utils.mjs @@ -255,23 +255,12 @@ async function scrollIntoView(page, selector) { await page.evaluate(sel => { const element = document.querySelector(sel); element.scrollIntoView({ behavior: "instant", block: "start" }); + return new Promise(resolve => { + document + .getElementById("viewerContainer") + .addEventListener("scrollend", resolve, { once: true }); + }); }, 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 - ); } async function hover(page, selector) {