Skip to content

Commit 5971f45

Browse files
authored
fix: flaky test Multichain API Call wallet_createSession (#31603)
<!-- 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** This spec fails, as after the MM dialog is closed, we perform actions in the multichain test dapp (sending window requests). The problem is that when we do this, we are still in the "context" of the dialog window, which was closed. This causes the browser to sometimes hang, and then the spec fails with a timeout, and cannot terminate properly. We should make sure the dialog is closed after we confirm/cancel the popup, and then switch into an existing window (multi chain test dapp) to perform the subsequent window api calls [![Open in GitHub Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/MetaMask/metamask-extension/pull/31603?quickstart=1) ## **Related issues** Fixes: ci failure: https://app.circleci.com/pipelines/github/MetaMask/metamask-extension/131730/workflows/65eb770f-9142-44b2-a757-0dd44b4a9ec2/jobs/4651782/tests#failed-test-0 ## **Manual testing steps** 1. check ci flask e2e job ![Screenshot from 2025-04-04 15-06-59](https://github.com/user-attachments/assets/5cce394c-c7eb-4b5f-93bc-bd28a58a95ed) ## **Screenshots/Recordings** <!-- If applicable, add screenshots and/or recordings to visualize the before and after of your change. --> ### **Before** <!-- [screenshots/recordings] --> ### **After** <!-- [screenshots/recordings] --> ## **Pre-merge author checklist** - [x] I've followed [MetaMask Contributor Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask Extension Coding Standards](https://github.com/MetaMask/metamask-extension/blob/main/.github/guidelines/CODING_GUIDELINES.md). - [x] I've completed the PR template to the best of my ability - [x] I’ve included tests if applicable - [ ] I’ve documented my code using [JSDoc](https://jsdoc.app/) format if applicable - [ ] I’ve applied the right labels on the PR (see [labeling guidelines](https://github.com/MetaMask/metamask-extension/blob/main/.github/guidelines/LABELING_GUIDELINES.md)). Not required for external contributors. ## **Pre-merge reviewer checklist** - [ ] I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed). - [ ] I confirm that this PR addresses all acceptance criteria described in the ticket it closes and includes the necessary testing evidence such as recordings and or screenshots.
1 parent f08855a commit 5971f45

File tree

1 file changed

+32
-6
lines changed

1 file changed

+32
-6
lines changed

test/e2e/flask/multichain-api/wallet_createSession.spec.ts

+32-6
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,13 @@ describeBrowserOnly(Browser.CHROME, 'Multichain API', function () {
4444
...scopesToIgnore,
4545
]);
4646

47-
await driver.clickElement({ text: 'Connect', tag: 'button' });
48-
47+
await driver.clickElementAndWaitForWindowToClose({
48+
text: 'Connect',
49+
tag: 'button',
50+
});
51+
await driver.switchToWindowWithTitle(
52+
WINDOW_TITLES.MultichainTestDApp,
53+
);
4954
const getSessionResult = await testDapp.getSession();
5055

5156
for (const scope of scopesToIgnore) {
@@ -90,7 +95,13 @@ describeBrowserOnly(Browser.CHROME, 'Multichain API', function () {
9095
[SECOND_ACCOUNT_IN_WALLET, ACCOUNT_NOT_IN_WALLET],
9196
);
9297

93-
await driver.clickElement({ text: 'Connect', tag: 'button' });
98+
await driver.clickElementAndWaitForWindowToClose({
99+
text: 'Connect',
100+
tag: 'button',
101+
});
102+
await driver.switchToWindowWithTitle(
103+
WINDOW_TITLES.MultichainTestDApp,
104+
);
94105

95106
const getSessionResult = await testDapp.getSession();
96107
/**
@@ -202,7 +213,13 @@ describeBrowserOnly(Browser.CHROME, 'Multichain API', function () {
202213
await permissionsTab.click();
203214
await updateNetworkCheckboxes(driver, ['Localhost 8545']);
204215

205-
await driver.clickElement({ text: 'Connect', tag: 'button' });
216+
await driver.clickElementAndWaitForWindowToClose({
217+
text: 'Connect',
218+
tag: 'button',
219+
});
220+
await driver.switchToWindowWithTitle(
221+
WINDOW_TITLES.MultichainTestDApp,
222+
);
206223

207224
const getSessionResult = await testDapp.getSession();
208225

@@ -282,7 +299,10 @@ describeBrowserOnly(Browser.CHROME, 'Multichain API', function () {
282299

283300
await addAccountInWalletAndAuthorize(driver);
284301

285-
await driver.clickElement({ text: 'Connect', tag: 'button' });
302+
await driver.clickElementAndWaitForWindowToClose({
303+
text: 'Connect',
304+
tag: 'button',
305+
});
286306
await driver.switchToWindowWithTitle(
287307
WINDOW_TITLES.MultichainTestDApp,
288308
);
@@ -392,7 +412,13 @@ describeBrowserOnly(Browser.CHROME, 'Multichain API', function () {
392412
await driver.clickElement(`input[name="${scope}"]`),
393413
);
394414
await testDapp.initCreateSessionScopes(NEW_SCOPES, [TREZOR_ACCOUNT]);
395-
await driver.clickElement({ text: 'Connect', tag: 'button' });
415+
await driver.clickElementAndWaitForWindowToClose({
416+
text: 'Connect',
417+
tag: 'button',
418+
});
419+
await driver.switchToWindowWithTitle(
420+
WINDOW_TITLES.MultichainTestDApp,
421+
);
396422
await driver.delay(largeDelayMs);
397423

398424
const newgetSessionResult = await testDapp.getSession();

0 commit comments

Comments
 (0)