diff --git a/development/lib/retry.js b/development/lib/retry.js index ea469958b221..2b38aaf486a0 100644 --- a/development/lib/retry.js +++ b/development/lib/retry.js @@ -14,8 +14,10 @@ * @param {string} args.retryUntilFailure - Retries until the function fails. * @param {Function} functionToRetry - The function that is run and tested for * failure. - * @returns {Promise} a promise that either resolves to null if - * the function is successful or is rejected with rejectionMessage otherwise. + * @returns {Promise<* | null | Error>} a promise that either resolves with one of the following: + * - If successful, resolves with the return value of functionToRetry. + * - If functionToRetry fails while retryUntilFailure is true, resolves with null. + * - Otherwise it is rejected with rejectionMessage. */ async function retry( { @@ -33,14 +35,14 @@ async function retry( } try { - await functionToRetry(); + const result = await functionToRetry(); if (!retryUntilFailure) { - return; + return result; } } catch (error) { console.error(error); if (retryUntilFailure) { - return; + return null; } } finally { attempts += 1; diff --git a/test/e2e/webdriver/driver.js b/test/e2e/webdriver/driver.js index 5dfaf22258b8..1061fe1b59bd 100644 --- a/test/e2e/webdriver/driver.js +++ b/test/e2e/webdriver/driver.js @@ -8,6 +8,7 @@ const { until, } = require('selenium-webdriver'); const cssToXPath = require('css-to-xpath'); +const { retry } = require('../../../development/lib/retry'); /** * Temporary workaround to patch selenium's element handle API with methods @@ -435,15 +436,25 @@ class Driver { initialWindowHandles, delayStep = 1000, timeout = this.timeout, + { retries = 8, retryDelay = 2500 } = {}, ) { let windowHandles = initialWindowHandles || (await this.driver.getAllWindowHandles()); let timeElapsed = 0; + while (timeElapsed <= timeout) { for (const handle of windowHandles) { - await this.driver.switchTo().window(handle); + const handleTitle = await retry( + { + retries, + delay: retryDelay, + }, + async () => { + await this.driver.switchTo().window(handle); + return await this.driver.getTitle(); + }, + ); - const handleTitle = await this.driver.getTitle(); if (handleTitle === title) { return handle; }