Merge pull request #7614 from backstage/rugvip/e2e-fix
e2e-test: improve page content checking resilience
This commit is contained in:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user