From 5ce544ce51190a4b9e481fb3bb43d6d1fbf74746 Mon Sep 17 00:00:00 2001 From: seaona Date: Wed, 12 Feb 2025 14:05:35 +0100 Subject: [PATCH 1/8] waitforurlcontaning --- test/e2e/tests/bridge/bridge-test-utils.ts | 42 ++++++++-------------- test/e2e/webdriver/driver.js | 13 +++++++ 2 files changed, 28 insertions(+), 27 deletions(-) diff --git a/test/e2e/tests/bridge/bridge-test-utils.ts b/test/e2e/tests/bridge/bridge-test-utils.ts index 08607129654c..2fec7d17545d 100644 --- a/test/e2e/tests/bridge/bridge-test-utils.ts +++ b/test/e2e/tests/bridge/bridge-test-utils.ts @@ -1,6 +1,4 @@ -import { strict as assert } from 'assert'; import { Mockttp } from 'mockttp'; -import { Browser } from 'selenium-webdriver'; import FixtureBuilder from '../../fixture-builder'; import { generateGanacheOptions } from '../../helpers'; import { @@ -11,7 +9,6 @@ import { import { SMART_CONTRACTS } from '../../seeder/smart-contracts'; import { CHAIN_IDS } from '../../../../shared/constants/network'; import { Driver } from '../../webdriver/driver'; -import { isManifestV3 } from '../../../../shared/modules/mv3.utils'; import type { FeatureFlagResponse } from '../../../../shared/types/bridge'; import { DEFAULT_FEATURE_FLAGS_RESPONSE, @@ -19,8 +16,6 @@ import { MOCK_CURRENCY_RATES, } from './constants'; -const IS_FIREFOX = process.env.SELENIUM_BROWSER === Browser.FIREFOX; - export class BridgePage { driver: Driver; @@ -62,35 +57,28 @@ export class BridgePage { css: '[data-testid="multichain-token-list-button"]', text: symbol, }); - - await this.driver.delay(2000); - assert.ok((await this.driver.getCurrentUrl()).includes('asset')); + await this.driver.waitForUrlContaining({ + url: 'asset', + timeout: this.driver.timeout, + }); }; verifyPortfolioTab = async (expectedHandleCount: number) => { - await this.driver.delay(4000); + await this.driver.waitUntilXWindowHandles(expectedHandleCount); await this.driver.switchToWindowWithTitle('MetaMask Portfolio - Bridge'); - assert.equal( - (await this.driver.getAllWindowHandles()).length, - IS_FIREFOX || !isManifestV3 - ? expectedHandleCount - : expectedHandleCount + 1, - ); - assert.match( - await this.driver.getCurrentUrl(), - /^https:\/\/portfolio\.metamask\.io\/bridge/u, - ); + await this.driver.waitForUrlContaining({ + url: 'portfolio.metamask.io/bridge', + timeout: this.driver.timeout, + }); }; verifySwapPage = async (expectedHandleCount: number) => { - await this.driver.delay(4000); - assert.equal( - (await this.driver.getAllWindowHandles()).length, - IS_FIREFOX || !isManifestV3 - ? expectedHandleCount - : expectedHandleCount + 1, - ); - assert.match(await this.driver.getCurrentUrl(), /.+cross-chain\/swaps/u); + await this.driver.waitUntilXWindowHandles(expectedHandleCount); + await this.driver.switchToWindowWithTitle('MetaMask Portfolio - Bridge'); + await this.driver.waitForUrlContaining({ + url: 'cross-chain/swaps', + timeout: this.driver.timeout, + }); }; } diff --git a/test/e2e/webdriver/driver.js b/test/e2e/webdriver/driver.js index 580b9fa56968..a2f17889868e 100644 --- a/test/e2e/webdriver/driver.js +++ b/test/e2e/webdriver/driver.js @@ -1164,6 +1164,19 @@ class Driver { return await this.driver.wait(until.urlIs(url), timeout); } + /** + * Waits until the current URL includes the specified substring. + * + * @param {object} options - Parameters for the function. + * @param {string} options.url - Substring to wait for in the URL. + * @param {int} options.timeout - optional timeout period, defaults to this.timeout. + * @returns {Promise} Promise that resolves once the URL includes the substring. + * @throws {Error} Throws an error if the URL does not include the substring within the timeout period. + */ + async waitForUrlContaining({ url, timeout = this.timeout }) { + return await this.driver.wait(until.urlContains(url), timeout); + } + /** * Closes the current window tab in the browser session * From 08a9ed84dfd587c03ecd056aab840fcd1c8ea019 Mon Sep 17 00:00:00 2001 From: seaona Date: Wed, 12 Feb 2025 16:21:31 +0100 Subject: [PATCH 2/8] fix --- test/e2e/tests/bridge/bridge-test-utils.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/test/e2e/tests/bridge/bridge-test-utils.ts b/test/e2e/tests/bridge/bridge-test-utils.ts index 2fec7d17545d..85c4ccc390e1 100644 --- a/test/e2e/tests/bridge/bridge-test-utils.ts +++ b/test/e2e/tests/bridge/bridge-test-utils.ts @@ -74,7 +74,6 @@ export class BridgePage { verifySwapPage = async (expectedHandleCount: number) => { await this.driver.waitUntilXWindowHandles(expectedHandleCount); - await this.driver.switchToWindowWithTitle('MetaMask Portfolio - Bridge'); await this.driver.waitForUrlContaining({ url: 'cross-chain/swaps', timeout: this.driver.timeout, From 8e039b28bf11de17222533c137efa0dfe91f18a4 Mon Sep 17 00:00:00 2001 From: seaona <54408225+seaona@users.noreply.github.com> Date: Wed, 12 Feb 2025 17:40:49 +0100 Subject: [PATCH 3/8] David's comment: int to number Co-authored-by: David Murdoch <187813+davidmurdoch@users.noreply.github.com> --- test/e2e/webdriver/driver.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/e2e/webdriver/driver.js b/test/e2e/webdriver/driver.js index a2f17889868e..8ead92c21c3f 100644 --- a/test/e2e/webdriver/driver.js +++ b/test/e2e/webdriver/driver.js @@ -1169,7 +1169,7 @@ class Driver { * * @param {object} options - Parameters for the function. * @param {string} options.url - Substring to wait for in the URL. - * @param {int} options.timeout - optional timeout period, defaults to this.timeout. + * @param {number} options.timeout - optional timeout period, defaults to `this.timeout`. * @returns {Promise} Promise that resolves once the URL includes the substring. * @throws {Error} Throws an error if the URL does not include the substring within the timeout period. */ From 4599be81ee395edae0f263dab0d109c03bbe1560 Mon Sep 17 00:00:00 2001 From: seaona <54408225+seaona@users.noreply.github.com> Date: Wed, 12 Feb 2025 17:41:01 +0100 Subject: [PATCH 4/8] David's comment: return Co-authored-by: David Murdoch <187813+davidmurdoch@users.noreply.github.com> --- test/e2e/webdriver/driver.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/e2e/webdriver/driver.js b/test/e2e/webdriver/driver.js index 8ead92c21c3f..bd7ea1437996 100644 --- a/test/e2e/webdriver/driver.js +++ b/test/e2e/webdriver/driver.js @@ -1174,7 +1174,7 @@ class Driver { * @throws {Error} Throws an error if the URL does not include the substring within the timeout period. */ async waitForUrlContaining({ url, timeout = this.timeout }) { - return await this.driver.wait(until.urlContains(url), timeout); + await this.driver.wait(until.urlContains(url), timeout); } /** From b10cdcb69cb0b9dc3c72f64a5ffa528e3f573c91 Mon Sep 17 00:00:00 2001 From: seaona Date: Wed, 12 Feb 2025 17:41:39 +0100 Subject: [PATCH 5/8] address comments --- .circleci/config.yml | 2 -- test/e2e/tests/bridge/bridge-button-opens-portfolio.spec.ts | 6 +++--- test/e2e/tests/bridge/bridge-button-routing.spec.ts | 2 +- test/e2e/tests/bridge/bridge-test-utils.ts | 6 ++---- 4 files changed, 6 insertions(+), 10 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index c46b88be39d9..f2561ee18031 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -138,7 +138,6 @@ workflows: requires: - prep-deps - test-e2e-chrome-webpack: - <<: *main_master_rc_only requires: - prep-build-test-webpack - get-changed-files-with-git-diff @@ -147,7 +146,6 @@ workflows: - prep-build-test - get-changed-files-with-git-diff - test-e2e-firefox: - <<: *main_master_rc_only requires: - prep-build-test-mv2 - get-changed-files-with-git-diff diff --git a/test/e2e/tests/bridge/bridge-button-opens-portfolio.spec.ts b/test/e2e/tests/bridge/bridge-button-opens-portfolio.spec.ts index 31e365d7c47f..f43637855ec4 100644 --- a/test/e2e/tests/bridge/bridge-button-opens-portfolio.spec.ts +++ b/test/e2e/tests/bridge/bridge-button-opens-portfolio.spec.ts @@ -10,7 +10,7 @@ describe('Click bridge button', function (this: Suite) { const bridgePage = new BridgePage(driver); await logInWithBalanceValidation(driver, ganacheServer); await bridgePage.navigateToBridgePage(); - await bridgePage.verifyPortfolioTab(2); + await bridgePage.verifyPortfolioTab(); }, ); }); @@ -25,14 +25,14 @@ describe('Click bridge button', function (this: Suite) { // ETH await bridgePage.navigateToAssetPage('ETH'); await bridgePage.navigateToBridgePage('coin-overview'); - await bridgePage.verifyPortfolioTab(2); + await bridgePage.verifyPortfolioTab(); await bridgePage.reloadHome(); // TST await bridgePage.navigateToAssetPage('TST'); await bridgePage.navigateToBridgePage('token-overview'); - await bridgePage.verifyPortfolioTab(3); + await bridgePage.verifyPortfolioTab(); }, ); }); diff --git a/test/e2e/tests/bridge/bridge-button-routing.spec.ts b/test/e2e/tests/bridge/bridge-button-routing.spec.ts index d024cd1821bd..43d90363daf2 100644 --- a/test/e2e/tests/bridge/bridge-button-routing.spec.ts +++ b/test/e2e/tests/bridge/bridge-button-routing.spec.ts @@ -16,7 +16,7 @@ describe('Click bridge button', function (this: Suite) { const bridgePage = new BridgePage(driver); await logInWithBalanceValidation(driver, ganacheServer); await bridgePage.navigateToBridgePage(); - await bridgePage.verifySwapPage(1); + await bridgePage.verifySwapPage(); }, ); }); diff --git a/test/e2e/tests/bridge/bridge-test-utils.ts b/test/e2e/tests/bridge/bridge-test-utils.ts index 85c4ccc390e1..79feaf23d6f2 100644 --- a/test/e2e/tests/bridge/bridge-test-utils.ts +++ b/test/e2e/tests/bridge/bridge-test-utils.ts @@ -63,8 +63,7 @@ export class BridgePage { }); }; - verifyPortfolioTab = async (expectedHandleCount: number) => { - await this.driver.waitUntilXWindowHandles(expectedHandleCount); + verifyPortfolioTab = async () => { await this.driver.switchToWindowWithTitle('MetaMask Portfolio - Bridge'); await this.driver.waitForUrlContaining({ url: 'portfolio.metamask.io/bridge', @@ -72,8 +71,7 @@ export class BridgePage { }); }; - verifySwapPage = async (expectedHandleCount: number) => { - await this.driver.waitUntilXWindowHandles(expectedHandleCount); + verifySwapPage = async () => { await this.driver.waitForUrlContaining({ url: 'cross-chain/swaps', timeout: this.driver.timeout, From cb847c2a35a08021ce46e64af990d510fa57f4e7 Mon Sep 17 00:00:00 2001 From: seaona Date: Wed, 12 Feb 2025 17:44:18 +0100 Subject: [PATCH 6/8] lint --- test/e2e/webdriver/driver.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/e2e/webdriver/driver.js b/test/e2e/webdriver/driver.js index bd7ea1437996..33217ccb9df5 100644 --- a/test/e2e/webdriver/driver.js +++ b/test/e2e/webdriver/driver.js @@ -1174,7 +1174,7 @@ class Driver { * @throws {Error} Throws an error if the URL does not include the substring within the timeout period. */ async waitForUrlContaining({ url, timeout = this.timeout }) { - await this.driver.wait(until.urlContains(url), timeout); + await this.driver.wait(until.urlContains(url), timeout); } /** From 78462aed1d91fa4f3dc8cca8c4798617b92bc6e1 Mon Sep 17 00:00:00 2001 From: seaona Date: Wed, 12 Feb 2025 17:56:13 +0100 Subject: [PATCH 7/8] optional jsdoc and remove unnecessary value --- test/e2e/tests/bridge/bridge-test-utils.ts | 3 --- test/e2e/webdriver/driver.js | 2 +- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/test/e2e/tests/bridge/bridge-test-utils.ts b/test/e2e/tests/bridge/bridge-test-utils.ts index 79feaf23d6f2..57c9bbfb6565 100644 --- a/test/e2e/tests/bridge/bridge-test-utils.ts +++ b/test/e2e/tests/bridge/bridge-test-utils.ts @@ -59,7 +59,6 @@ export class BridgePage { }); await this.driver.waitForUrlContaining({ url: 'asset', - timeout: this.driver.timeout, }); }; @@ -67,14 +66,12 @@ export class BridgePage { await this.driver.switchToWindowWithTitle('MetaMask Portfolio - Bridge'); await this.driver.waitForUrlContaining({ url: 'portfolio.metamask.io/bridge', - timeout: this.driver.timeout, }); }; verifySwapPage = async () => { await this.driver.waitForUrlContaining({ url: 'cross-chain/swaps', - timeout: this.driver.timeout, }); }; } diff --git a/test/e2e/webdriver/driver.js b/test/e2e/webdriver/driver.js index 33217ccb9df5..1ec1f195c354 100644 --- a/test/e2e/webdriver/driver.js +++ b/test/e2e/webdriver/driver.js @@ -1169,7 +1169,7 @@ class Driver { * * @param {object} options - Parameters for the function. * @param {string} options.url - Substring to wait for in the URL. - * @param {number} options.timeout - optional timeout period, defaults to `this.timeout`. + * @param {number} [options.timeout] - optional timeout period, defaults to `this.timeout`. * @returns {Promise} Promise that resolves once the URL includes the substring. * @throws {Error} Throws an error if the URL does not include the substring within the timeout period. */ From b02539bb674ac45d5bc5225425ec8547e569e1bf Mon Sep 17 00:00:00 2001 From: seaona Date: Wed, 12 Feb 2025 18:22:46 +0100 Subject: [PATCH 8/8] add ci filters back --- .circleci/config.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.circleci/config.yml b/.circleci/config.yml index f2561ee18031..c46b88be39d9 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -138,6 +138,7 @@ workflows: requires: - prep-deps - test-e2e-chrome-webpack: + <<: *main_master_rc_only requires: - prep-build-test-webpack - get-changed-files-with-git-diff @@ -146,6 +147,7 @@ workflows: - prep-build-test - get-changed-files-with-git-diff - test-e2e-firefox: + <<: *main_master_rc_only requires: - prep-build-test-mv2 - get-changed-files-with-git-diff