diff --git a/packages/e2e-test/src/lib/helpers.ts b/packages/e2e-test/src/lib/helpers.ts index 2182a9d324..db6c31512c 100644 --- a/packages/e2e-test/src/lib/helpers.ts +++ b/packages/e2e-test/src/lib/helpers.ts @@ -129,13 +129,22 @@ export async function waitForPageWithText( browser: any, path: string, text: string, - { intervalMs = 1000, maxLoadAttempts = 240, maxFindTextAttempts = 3 } = {}, + { intervalMs = 1000, maxLoadAttempts = 50 } = {}, ) { let loadAttempts = 0; for (;;) { try { - await new Promise(resolve => setTimeout(resolve, intervalMs)); + const waitTimeMs = intervalMs * (Math.log10(loadAttempts + 1) + 1); + console.log(`Attempting to load page at ${path}, waiting ${waitTimeMs}`); + await new Promise(resolve => setTimeout(resolve, waitTimeMs)); await browser.visit(path); + + const escapedText = text.replace(/"|\\/g, '\\$&'); + browser.assert.evaluate( + `Array.from(document.querySelectorAll("*")).some(el => el.textContent === "${escapedText}")`, + true, + `expected to find text ${text}`, + ); break; } catch (error) { if (error.message.match(EXPECTED_LOAD_ERRORS)) { @@ -150,28 +159,6 @@ export async function waitForPageWithText( } } } - - // The page may not be fully loaded and hence we need to retry. - let findTextAttempts = 0; - const escapedText = text.replace(/"|\\/g, '\\$&'); - for (;;) { - try { - browser.assert.evaluate( - `Array.from(document.querySelectorAll("*")).some(el => el.textContent === "${escapedText}")`, - true, - `expected to find text ${text}`, - ); - break; - } catch (error) { - findTextAttempts++; - if (findTextAttempts <= maxFindTextAttempts) { - await new Promise(resolve => setTimeout(resolve, intervalMs)); - continue; - } else { - throw error; - } - } - } } export function print(msg: string) {