message: e2e-test: improve page content checking resilience
diff: @@ -129,33 +129,17 @@ 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);
  - break;
  - } catch (error) {
  - if (error.message.match(EXPECTED_LOAD_ERRORS)) {
  - loadAttempts++;
  - if (loadAttempts >= maxLoadAttempts) {
  - throw new Error(
  - `Failed to load page '${path}', max number of attempts reached`,
  - );
  - }
  - } else {
  - throw error;
  - }
  - }
  - }
  - // 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,
  @@ -163,10 +147,13 @@ export async function waitForPageWithText(
  );
  break;
  } catch (error) {
  - findTextAttempts++;
  - if (findTextAttempts <= maxFindTextAttempts) {
  - await new Promise(resolve => setTimeout(resolve, intervalMs));
  - continue;
  + if (error.message.match(EXPECTED_LOAD_ERRORS)) {
  + loadAttempts++;
  + if (loadAttempts >= maxLoadAttempts) {
  + throw new Error(
  + `Failed to load page '${path}', max number of attempts reached`,
  + );
  + }
  } else {
  throw error;
  }
  