From d843bed4e3a69485fc1bfd19320fc08f0495c8cf Mon Sep 17 00:00:00 2001 From: Erik Marks <25517051+rekmarks@users.noreply.github.com> Date: Fri, 23 Oct 2020 16:24:20 -0700 Subject: [PATCH] Robustify waiting logic in e2e test (#9704) * Robustify waiting for popup to open Co-authored-by: Mark Stacey --- test/e2e/metamask-ui.spec.js | 3 +-- test/e2e/webdriver/driver.js | 5 +++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/test/e2e/metamask-ui.spec.js b/test/e2e/metamask-ui.spec.js index 9bdc9c124..4ef3b056f 100644 --- a/test/e2e/metamask-ui.spec.js +++ b/test/e2e/metamask-ui.spec.js @@ -772,9 +772,8 @@ describe('MetaMask', function () { await driver.delay(regularDelayMs * 2) await driver.clickElement(By.xpath(`//button[contains(text(), 'Create Token')]`)) - await driver.delay(largeDelayMs) + windowHandles = await driver.waitUntilXWindowHandles(3) - windowHandles = await driver.getAllWindowHandles() const popup = windowHandles[2] await driver.switchToWindow(popup) await driver.delay(regularDelayMs) diff --git a/test/e2e/webdriver/driver.js b/test/e2e/webdriver/driver.js index dcd516e41..c4a551b36 100644 --- a/test/e2e/webdriver/driver.js +++ b/test/e2e/webdriver/driver.js @@ -124,10 +124,11 @@ class Driver { async waitUntilXWindowHandles (x, delayStep = 1000, timeout = 5000) { let timeElapsed = 0 + let windowHandles = [] while (timeElapsed <= timeout) { - const windowHandles = await this.driver.getAllWindowHandles() + windowHandles = await this.driver.getAllWindowHandles() if (windowHandles.length === x) { - return + return windowHandles } await this.delay(delayStep) timeElapsed += delayStep