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