Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: remove unnecessary delays and wait for condition with waitForUrlContaning #30265

Merged
merged 8 commits into from
Feb 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions test/e2e/tests/bridge/bridge-button-opens-portfolio.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
},
);
});
Expand All @@ -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();
},
);
});
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/tests/bridge/bridge-button-routing.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
},
);
});
Expand Down
40 changes: 11 additions & 29 deletions test/e2e/tests/bridge/bridge-test-utils.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -11,16 +9,13 @@ 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,
ETH_CONVERSION_RATE_USD,
MOCK_CURRENCY_RATES,
} from './constants';

const IS_FIREFOX = process.env.SELENIUM_BROWSER === Browser.FIREFOX;

export class BridgePage {
driver: Driver;

Expand Down Expand Up @@ -62,35 +57,22 @@ 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',
});
};

verifyPortfolioTab = async (expectedHandleCount: number) => {
await this.driver.delay(4000);
verifyPortfolioTab = async () => {
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',
});
};

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);
verifySwapPage = async () => {
await this.driver.waitForUrlContaining({
url: 'cross-chain/swaps',
});
};
}

Expand Down
13 changes: 13 additions & 0 deletions test/e2e/webdriver/driver.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {number} [options.timeout] - optional timeout period, defaults to `this.timeout`.
* @returns {Promise<void>} 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 }) {
await this.driver.wait(until.urlContains(url), timeout);
}

/**
* Closes the current window tab in the browser session
*
Expand Down
Loading