Skip to content

Commit 904fb44

Browse files
test: Run E2E on Chrome 137 (#47453)
<!-- Please submit this PR as a draft initially. Do not mark it as "Ready for review" until the template has been completely filled out, and PR status checks have passed at least once. --> ## **Description** Modifies E2E configuration to run tests on Chrome 137, in preparation for updating the minimum required browser versions. Fixes the problems that crop up following that: - E2Es now require access to `Window` without scuttling (we already do not scuttle `window`) - Increased height of headless viewport to prevent issues with toasts - Enable `--enable-unsafe-extension-debugging` as the extension cannot be reloaded during test without it - Enable `enableExtensionTargets` in order for popups to show up in window handles. - Allowlist Chrome GCM check-in endpoint - Defer calls to `runtime.reload()`/`stateHooks.reloadExtension()` on Chrome to prevent ChromeDriver crashes - Use a timestamp further in the future for a Snaps test - Retry phishing detection clicks to prevent timing issues - Wait for disconnect to finish in dapp tests ## **Changelog** <!-- If this PR is not End-User-Facing and should not show up in the CHANGELOG, you can choose to either: 1. Write `CHANGELOG entry: null` 2. Label with `no-changelog` If this PR is End-User-Facing, please write a short User-Facing description in the past tense like: `CHANGELOG entry: Added a new tab for users to see their NFTs` `CHANGELOG entry: Fixed a bug that was causing some NFTs to flicker` (This helps the Release Engineer do their job more quickly and accurately) --> CHANGELOG entry: null <!-- CURSOR_SUMMARY --> --- > [!NOTE] > **Low Risk** > Changes are confined to E2E WebDriver configuration, test helpers, and test-only Lavamoat scuttling exceptions, with no production user-facing behavior changes. > > **Overview** > Updates Selenium Chrome E2E to **Chrome 137** and adjusts driver/options so extension reloads, popups, and headless layout work reliably on the new version: **`--enable-unsafe-extension-debugging`**, **`enableExtensionTargets`**, larger headless window height, and skipping fixed **`--window-size`** when headless. > > **ChromeDriver stability:** extension reload helpers now **`setTimeout(..., 100)`** before **`runtime.reload()`** / **`stateHooks.reloadExtension()`** on Chrome, with an extra delay in state-persistence helpers. > > **Test harness fixes:** Lavamoat test scuttling adds **`Window`** to e2e globals; onboarding privacy allowlist adds **`android.clients.google.com`**; phishing **Proceed anyway** gets retries and optional **`waitForNavigation`**; dapp disconnect waits for connect enabled; Snaps background event schedule uses **+30s**; deposit spec asserts **10%** preset. > > **Risk:** Low — test-only wiring plus a test-build Lavamoat exception. > > <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit 618f1c6. Bugbot is set up for automated code reviews on this repo. Configure [here](https://www.cursor.com/dashboard/bugbot).</sup> <!-- /CURSOR_SUMMARY -->
1 parent 216e863 commit 904fb44

11 files changed

Lines changed: 57 additions & 10 deletions

File tree

‎development/webpack/utils/plugins/LavamoatPlugin/index.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,9 @@ const getScuttleGlobalThisExceptions = (args: Args) => [
9898
// under scuttling the detection itself throws unless excepted.
9999
'requestIdleCallback',
100100
// globals used by e2e
101-
...(args.test ? ['ret_nodes', 'browser', 'chrome', 'indexedDB'] : []),
101+
...(args.test
102+
? ['ret_nodes', 'browser', 'chrome', 'indexedDB', 'Window']
103+
: []),
102104
];
103105

104106
type IsolatedHtmlEntries = {

‎test/e2e/dist/first-install.spec.ts‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,11 @@ describe('First install', function () {
2323
await startOnboardingPage.checkLoginPageIsLoaded();
2424
}
2525

26-
await driver.executeScript('window.stateHooks.reloadExtension()');
26+
await driver.executeScript(
27+
process.env.SELENIUM_BROWSER === Browser.CHROME
28+
? `setTimeout(() => window.stateHooks.reloadExtension(), 100)`
29+
: `window.stateHooks.reloadExtension()`,
30+
);
2731

2832
// Wait for extension to reload, signified by the onboarding tab closing
2933
await driver.waitUntilXWindowHandles(1);

‎test/e2e/page-objects/pages/security/phishing-warning-page.ts‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { retry } from '../../../../../development/lib/retry';
12
import { Driver } from '../../../webdriver/driver';
23

34
/**
@@ -86,8 +87,17 @@ class PhishingWarningPage {
8687
}
8788
}
8889

89-
async clickProceedAnywayButton(): Promise<void> {
90+
async clickProceedAnywayButton({
91+
waitForNavigation = true,
92+
}: { waitForNavigation?: boolean } = {}): Promise<void> {
9093
console.log('Clicking proceed anyway button on phishing warning page');
94+
if (waitForNavigation) {
95+
// Retry in case the phishing page hasn't fully loaded yet by the time we click it.
96+
await retry({ retries: 3, delay: 1000 }, async () =>
97+
this.driver.clickElementAndWaitToDisappear(this.proceedAnywayButton),
98+
);
99+
return;
100+
}
91101
await this.driver.clickElement(this.proceedAnywayButton);
92102
}
93103

‎test/e2e/page-objects/pages/test-dapp.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -984,6 +984,9 @@ class TestDapp {
984984
async disconnectAccount(publicAddress: string) {
985985
console.log('Disconnect account from test dapp');
986986
await this.driver.clickElement(this.revokePermissionButton);
987+
await this.driver.waitForSelector(this.connectAccountButton, {
988+
state: 'enabled',
989+
});
987990
await this.driver.refresh();
988991
await this.checkPageIsLoaded();
989992
await this.checkConnectedAccounts(publicAddress, false);

‎test/e2e/snaps/test-snap-background-events.spec.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ describe('Test Snap Background Events', function () {
147147
{ expectedMessage: 'Reconnect to Background Events Snap' },
148148
);
149149

150-
const futureDate = new Date(Date.now() + 5000).toISOString();
150+
const futureDate = new Date(Date.now() + 30000).toISOString();
151151

152152
await testSnaps.fillMessage('backgroundEventDateInput', futureDate);
153153

‎test/e2e/tests/confirmations/metamask-pay/money-account-deposit.spec.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ describe('Money Account Deposit', function (this: Suite) {
4646
await selectPayToken(driver, confirmation, CHAIN_IDS.MAINNET, 'USDC');
4747
await confirmation.checkPayWithBalance(`($${USDC_BALANCE_HUMAN}.00)`);
4848

49+
await confirmation.clickPercentage(10);
50+
await confirmation.checkAmount('10');
51+
4952
await confirmation.clickPercentage(25);
5053
await confirmation.checkAmount('25');
5154

‎test/e2e/tests/phishing-controller/phishing-detection.spec.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,9 @@ describe('Phishing Detection', function (this: Suite) {
207207
// we need to wait for this selector to mitigate a race condition on the phishing page site
208208
// see more here https://github.com/MetaMask/phishing-warning/pull/173
209209
await phishingWarningPage.checkPageIsLoaded();
210-
await phishingWarningPage.clickProceedAnywayButton();
210+
await phishingWarningPage.clickProceedAnywayButton({
211+
waitForNavigation: false,
212+
});
211213

212214
// We don't really know what we're going to see at this blocked site, so a waitAtLeast guard of 1000ms is the best choice
213215
await new HomePage(driver).checkPageIsNotLoaded();

‎test/e2e/tests/privacy/onboarding-allowlist.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
"duringOnboarding": [
1212
"accounts.api.cx.metamask.io",
1313
"accounts.google.com",
14+
"android.clients.google.com",
1415
"chainid.network",
1516
"firefox.settings.services.mozilla.com",
1617
"metamask.github.io",

‎test/e2e/tests/state-persistence/helpers.ts‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import assert from 'node:assert/strict';
22
import { STORAGE_KEY_PREFIX } from '@metamask/storage-service';
3+
import { Browser } from 'selenium-webdriver';
34
import { WINDOW_TITLES } from '../../constants';
45
import HomePage from '../../page-objects/pages/home/homepage';
56
import { Driver, PAGES } from '../../webdriver/driver';
@@ -96,9 +97,16 @@ export const reloadExtension = async (driver: Driver): Promise<void> => {
9697
await driver.switchToWindow(extensionWindow);
9798
await pausePersistence(driver);
9899
await driver.executeScript(
99-
`(globalThis.browser ?? globalThis.chrome).runtime.reload()`,
100+
process.env.SELENIUM_BROWSER === Browser.CHROME
101+
? `setTimeout(() => (globalThis.browser ?? globalThis.chrome).runtime.reload(), 100)`
102+
: `(globalThis.browser ?? globalThis.chrome).runtime.reload()`,
100103
);
101104

105+
// Ensure we do not race the script above.
106+
if (process.env.SELENIUM_BROWSER === Browser.CHROME) {
107+
await driver.delay(100);
108+
}
109+
102110
await driver.switchToWindow(blankWindow);
103111

104112
// get a new tab ready to use (required for Firefox)

‎test/e2e/tests/tokens/import-custom-token-with-custom-network.spec.ts‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import type { Mockttp } from 'mockttp';
22
import { utils as ethersUtils } from 'ethers';
3+
import { Browser } from 'selenium-webdriver';
34
import { withFixtures } from '../../helpers';
45
import { login } from '../../page-objects/flows/login.flow';
56
import { completeImportSRPOnboardingFlow } from '../../page-objects/flows/onboarding.flow';
@@ -314,7 +315,9 @@ async function reloadExtension(driver: Driver): Promise<void> {
314315

315316
await driver.switchToWindow(extensionWindow);
316317
await driver.executeScript(
317-
`(globalThis.browser ?? globalThis.chrome).runtime.reload()`,
318+
process.env.SELENIUM_BROWSER === Browser.CHROME
319+
? `setTimeout(() => (globalThis.browser ?? globalThis.chrome).runtime.reload(), 100)`
320+
: `(globalThis.browser ?? globalThis.chrome).runtime.reload()`,
318321
);
319322

320323
await driver.switchToWindow(blankWindow);

0 commit comments

Comments
 (0)