Skip to content

Commit 81d6285

Browse files
Akaryatrhseaona
andauthored
fix: flaky ledger e2e tests (#35888)
## **Description** Fix flaky e2e tests on Ledger flows [![Open in GitHub Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/MetaMask/metamask-extension/pull/35888?quickstart=1) ## **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 ## **Related issues** Fixes: ## **Manual testing steps** Local testing - run `yarn && yarn start:test` in one terminal tab and wait for build end - run `yarn test:e2e:single test/e2e/tests/hardware-wallets/ledger/ledger-swap.spec.ts` on another terminal tab Otherwise check this PR CI. ## **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 - [x] I’ve documented my code using [JSDoc](https://jsdoc.app/) format if applicable - [x] 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. <!-- CURSOR_SUMMARY --> --- > [!NOTE] > Unskips and stabilizes the Ledger ETH→DAI swap e2e by disabling Smart Transactions, adding a brief delay, updating wait logic, and switching swap API mocks to bridge endpoints. > > - **E2E Tests (Ledger swap)**: > - Unskips `swaps ETH to DAI` in `test/e2e/tests/hardware-wallets/ledger/ledger-swap.spec.ts`. > - Disables Smart Transactions via fixtures (`withPreferencesControllerSmartTransactionsOptedOut`) and manifest flag (`testing.disableSmartTransactionsOverride`); removes UI steps to toggle it. > - Adds a 5s delay before submitting swap to mitigate re-render flakiness; minor tab-switch simplification. > - **Page Object**: > - `test/e2e/page-objects/pages/swap/swap-page.ts`: replace polling loop in `swapProcessingMessageCheck` with `waitForSelector` on `awaiting-swap-header`. > - **Mocks**: > - `test/e2e/tests/hardware-wallets/ledger/mocks.ts`: point network info, feature flags, and tokens endpoints from `swap.api` to `bridge.api`. > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit 1bba0fb. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY --> --------- Co-authored-by: seaona <[email protected]>
1 parent af41680 commit 81d6285

File tree

3 files changed

+18
-37
lines changed

3 files changed

+18
-37
lines changed

test/e2e/page-objects/pages/swap/swap-page.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -170,13 +170,10 @@ class SwapPage {
170170
}
171171

172172
async swapProcessingMessageCheck(message: string): Promise<void> {
173-
await this.driver.wait(async () => {
174-
const confirmedTxs = await this.driver.findElements({
175-
css: this.transactionHeader,
176-
text: message,
177-
});
178-
return confirmedTxs.length === 1;
179-
}, 10000);
173+
await this.driver.waitForSelector({
174+
css: this.transactionHeader,
175+
text: message,
176+
});
180177
}
181178

182179
async checkSwapButtonIsEnabled(): Promise<void> {

test/e2e/tests/hardware-wallets/ledger/ledger-swap.spec.ts

Lines changed: 11 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,29 @@ import { Browser } from 'selenium-webdriver';
22
import FixtureBuilder from '../../../fixture-builder';
33
import { WINDOW_TITLES, withFixtures } from '../../../helpers';
44
import { loginWithBalanceValidation } from '../../../page-objects/flows/login.flow';
5-
import HeaderNavbar from '../../../page-objects/pages/header-navbar';
6-
import SettingsPage from '../../../page-objects/pages/settings/settings-page';
75
import { checkActivityTransaction } from '../../swaps/shared';
8-
96
import HomePage from '../../../page-objects/pages/home/homepage';
10-
import AdvancedSettings from '../../../page-objects/pages/settings/advanced-settings';
117
import SwapPage from '../../../page-objects/pages/swap/swap-page';
12-
138
import { KNOWN_PUBLIC_KEY_ADDRESSES } from '../../../../stub/keyring-bridge';
149
import { mockLedgerTransactionRequests } from './mocks';
1510

1611
const isFirefox = process.env.SELENIUM_BROWSER === Browser.FIREFOX;
1712

1813
describe('Ledger Swap', function () {
1914
// eslint-disable-next-line mocha/no-skipped-tests
20-
it.skip('swaps ETH to DAI', async function () {
15+
it('swaps ETH to DAI', async function () {
2116
await withFixtures(
2217
{
23-
fixtures: new FixtureBuilder().withLedgerAccount().build(),
18+
fixtures: new FixtureBuilder()
19+
.withPreferencesControllerSmartTransactionsOptedOut()
20+
.withLedgerAccount()
21+
.build(),
2422
localNodeOptions: {
2523
loadState: './test/e2e/seeder/network-states/with50Dai.json',
2624
},
25+
manifestFlags: {
26+
testing: { disableSmartTransactionsOverride: true },
27+
},
2728
title: this.test?.fullTitle(),
2829
testSpecificMock: mockLedgerTransactionRequests,
2930
},
@@ -36,20 +37,6 @@ describe('Ledger Swap', function () {
3637
await loginWithBalanceValidation(driver, undefined, undefined, '20');
3738

3839
const homePage = new HomePage(driver);
39-
40-
// disable smart transactions
41-
const headerNavbar = new HeaderNavbar(driver);
42-
await headerNavbar.checkPageIsLoaded();
43-
await headerNavbar.openSettingsPage();
44-
const settingsPage = new SettingsPage(driver);
45-
46-
await settingsPage.checkPageIsLoaded();
47-
await settingsPage.clickAdvancedTab();
48-
const advancedSettingsPage = new AdvancedSettings(driver);
49-
await advancedSettingsPage.checkPageIsLoaded();
50-
await advancedSettingsPage.toggleSmartTransactions();
51-
await settingsPage.closeSettingsPage();
52-
5340
await homePage.checkIfSwapButtonIsClickable();
5441

5542
await homePage.startSwapFlow();
@@ -75,17 +62,14 @@ describe('Ledger Swap', function () {
7562

7663
await swapPage.enterSwapAmount('2');
7764
await swapPage.selectDestinationToken('DAI');
78-
await swapPage.dismissManualTokenWarning();
7965

66+
await swapPage.dismissManualTokenWarning();
8067
await swapPage.checkSwapButtonIsEnabled();
68+
// To mitigate flakiness where the Swap page is re-rendered after submitting the swap (#36501)
69+
await driver.delay(5000);
8170
await swapPage.submitSwap();
82-
8371
await swapPage.waitForTransactionToComplete();
8472

85-
await driver.switchToWindowWithTitle(
86-
WINDOW_TITLES.ExtensionInFullScreenView,
87-
);
88-
8973
await homePage.checkPageIsLoaded();
9074
// check activity list
9175
await homePage.goToActivityList();

test/e2e/tests/hardware-wallets/ledger/mocks.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ export async function mockLedgerTransactionRequests(mockServer: MockttpServer) {
182182
// Mock network information for swap API
183183
async function mockSwapNetworkInfo(mockServer: MockttpServer) {
184184
return await mockServer
185-
.forGet('https://swap.api.cx.metamask.io/networks/1')
185+
.forGet('https://bridge.api.cx.metamask.io/networks/1')
186186
.thenCallback(() => ({
187187
statusCode: 200,
188188
json: {
@@ -312,7 +312,7 @@ async function mockLedgerIframeBridge(mockServer: MockttpServer) {
312312
// Mock swap feature flags API
313313
async function mockSwapFeatureFlags(mockServer: MockttpServer) {
314314
return await mockServer
315-
.forGet('https://swap.api.cx.metamask.io/featureFlags')
315+
.forGet('https://bridge.api.cx.metamask.io/featureFlags')
316316
.thenCallback(() => ({
317317
statusCode: 200,
318318
json: {
@@ -337,7 +337,7 @@ async function mockSwapFeatureFlags(mockServer: MockttpServer) {
337337
// Mock swap tokens API
338338
async function mockSwapTokens(mockServer: MockttpServer) {
339339
return await mockServer
340-
.forGet('https://swap.api.cx.metamask.io/networks/1/tokens')
340+
.forGet('https://bridge.api.cx.metamask.io/networks/1/tokens')
341341
.thenCallback(() => ({
342342
statusCode: 200,
343343
json: [

0 commit comments

Comments
 (0)