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

feat: refactor e2e wallet rendered helper function #25352

Merged
merged 2 commits into from
Jun 21, 2024
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
5 changes: 2 additions & 3 deletions test/e2e/accounts/account-custom-name.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Suite } from 'mocha';
import {
unlockWallet,
withFixtures,
waitForAccountRendered,
locateAccountBalanceDOM,
findAnotherAccountFromAccountList,
} from '../helpers';
import FixtureBuilder from '../fixture-builder';
Expand All @@ -20,7 +20,6 @@ describe('Account Custom Name Persistence', function (this: Suite) {
},
async ({ driver }: { driver: Driver }) => {
await unlockWallet(driver);

// Change account label for existing account
await driver.clickElement(
'[data-testid="account-options-menu-button"]',
Expand All @@ -47,7 +46,7 @@ describe('Account Custom Name Persistence', function (this: Suite) {
);
await driver.fill('[placeholder="Account 2"]', anotherAccountLabel);
await driver.clickElement({ text: 'Create', tag: 'button' });
await waitForAccountRendered(driver);
await locateAccountBalanceDOM(driver);

// Verify initial custom account label after freshly added account was active
const accountOneSelector = await findAnotherAccountFromAccountList(
Expand Down
21 changes: 10 additions & 11 deletions test/e2e/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -861,20 +861,20 @@ const TEST_SEED_PHRASE_TWO =

// Usually happens when onboarded to make sure the state is retrieved from metamaskState properly, or after txn is made
const locateAccountBalanceDOM = async (driver, ganacheServer) => {
const balance = await ganacheServer.getBalance();

await driver.waitForSelector({
css: '[data-testid="eth-overview__primary-currency"]',
text: `${balance} ETH`,
});
const balanceSelector = '[data-testid="eth-overview__primary-currency"]';
if (ganacheServer) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are situations there the account is not having the balance allocated. eg: we create 2nd account. So to re-use the selector logic, I combined this with waitForAccountRendered downstairs

const balance = await ganacheServer.getBalance();
await driver.waitForSelector({
css: balanceSelector,
text: `${balance} ETH`,
});
} else {
await driver.findElement(balanceSelector);
}
};

const WALLET_PASSWORD = 'correct horse battery staple';

async function waitForAccountRendered(driver) {
await driver.findElement('[data-testid="eth-overview__primary-currency"]');
}

/**
* Unlock the wallet with the default password.
* This method is intended to replace driver.navigate and should not be called after driver.navigate.
Expand Down Expand Up @@ -1151,7 +1151,6 @@ module.exports = {
unlockWallet,
logInWithBalanceValidation,
locateAccountBalanceDOM,
waitForAccountRendered,
generateGanacheOptions,
WALLET_PASSWORD,
WINDOW_TITLES,
Expand Down
21 changes: 11 additions & 10 deletions test/e2e/tests/account/add-account.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ const {
completeImportSRPOnboardingFlow,
sendTransaction,
findAnotherAccountFromAccountList,
waitForAccountRendered,
locateAccountBalanceDOM,
logInWithBalanceValidation,
regularDelayMs,
unlockWallet,
WALLET_PASSWORD,
Expand Down Expand Up @@ -57,7 +58,7 @@ describe('Add account', function () {
ganacheOptions,
title: this.test.fullTitle(),
},
async ({ driver }) => {
async ({ driver, ganacheServer }) => {
await driver.navigate();

// On boarding with 1st account
Expand All @@ -67,8 +68,8 @@ describe('Add account', function () {
WALLET_PASSWORD,
);

// Check address of 1st account
await waitForAccountRendered(driver);
// Check address of 1st accoun
await locateAccountBalanceDOM(driver, ganacheServer);
await driver.findElement('[data-testid="app-header-copy-button"]');

// Create 2nd account
Expand All @@ -83,7 +84,7 @@ describe('Add account', function () {
await driver.clickElement({ text: 'Create', tag: 'button' });

// Check address of 2nd account
await waitForAccountRendered(driver);
await locateAccountBalanceDOM(driver);
await driver.findElement('[data-testid="app-header-copy-button"]');

// Log into the account with balance(account 1)
Expand All @@ -94,7 +95,7 @@ describe('Add account', function () {
1,
'Account 1',
);
await waitForAccountRendered(driver);
await locateAccountBalanceDOM(driver);
await driver.clickElement(accountOneSelector);
await sendTransaction(driver, secondAccount, '2.8');

Expand Down Expand Up @@ -127,7 +128,7 @@ describe('Add account', function () {

// Land in 1st account home page
await driver.findElement('.home__main-view');
await waitForAccountRendered(driver);
await locateAccountBalanceDOM(driver);

// Check address of 1st account
await driver.findElement('[data-testid="app-header-copy-button"]');
Expand Down Expand Up @@ -155,7 +156,7 @@ describe('Add account', function () {
title: this.test.fullTitle(),
},
async ({ driver }) => {
await unlockWallet(driver);
await logInWithBalanceValidation(driver);

await driver.clickElement('[data-testid="account-menu-icon"]');
await driver.clickElement(
Expand All @@ -168,7 +169,7 @@ describe('Add account', function () {
await driver.clickElement({ text: 'Create', tag: 'button' });

// Wait for 2nd account to be created
await waitForAccountRendered(driver);
await locateAccountBalanceDOM(driver);
await driver.findElement({
css: '[data-testid="account-menu-icon"]',
text: '2nd account',
Expand Down Expand Up @@ -201,7 +202,7 @@ describe('Add account', function () {
);

// Wait for 3rd account to be created
await waitForAccountRendered(driver);
await locateAccountBalanceDOM(driver);
await driver.findElement({
css: '[data-testid="account-menu-icon"]',
text: 'Account 3',
Expand Down
10 changes: 5 additions & 5 deletions test/e2e/tests/account/import-flow.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ const {
completeImportSRPOnboardingFlowWordByWord,
openActionMenuAndStartSendFlow,
unlockWallet,
logInWithBalanceValidation,
locateAccountBalanceDOM,
WALLET_PASSWORD,
waitForAccountRendered,
} = require('../../helpers');
const FixtureBuilder = require('../../fixture-builder');
const { emptyHtmlPage } = require('../../mock-e2e');
Expand Down Expand Up @@ -287,9 +288,8 @@ describe('Import flow @no-mmi', function () {
ganacheOptions,
title: this.test.fullTitle(),
},
async ({ driver }) => {
await unlockWallet(driver);
await waitForAccountRendered(driver);
async ({ driver, ganacheServer }) => {
await logInWithBalanceValidation(driver, ganacheServer);
// Imports an account with JSON file
await driver.clickElement('[data-testid="account-menu-icon"]');
await driver.clickElement(
Expand All @@ -316,7 +316,7 @@ describe('Import flow @no-mmi', function () {
'[data-testid="import-account-confirm-button"]',
);

await waitForAccountRendered(driver);
await locateAccountBalanceDOM(driver, ganacheServer);
// New imported account has correct name and label
await driver.findClickableElement({
css: '[data-testid="account-menu-icon"]',
Expand Down
39 changes: 20 additions & 19 deletions test/e2e/tests/metrics/dapp-viewed.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ const {
unlockWallet,
getEventPayloads,
openDapp,
waitForAccountRendered,
logInWithBalanceValidation,
WINDOW_TITLES,
defaultGanacheOptions,
} = require('../../helpers');
const FixtureBuilder = require('../../fixture-builder');
const {
Expand Down Expand Up @@ -40,7 +41,6 @@ async function mockPermissionApprovedEndpoint(mockServer) {
}

async function createTwoAccounts(driver) {
await waitForAccountRendered(driver);
await driver.clickElement('[data-testid="account-menu-icon"]');
await driver.clickElement(
'[data-testid="multichain-account-menu-popover-action-button"]',
Expand Down Expand Up @@ -107,10 +107,10 @@ describe('Dapp viewed Event @no-mmi', function () {
.build(),
title: this.test.fullTitle(),
testSpecificMock: mockSegment,
ganacheOptions: defaultGanacheOptions,
},
async ({ driver, mockedEndpoint: mockedEndpoints }) => {
await unlockWallet(driver);

async ({ driver, mockedEndpoint: mockedEndpoints, ganacheServer }) => {
await logInWithBalanceValidation(driver, ganacheServer);
await connectToDapp(driver);
await waitForDappConnected(driver);
const events = await getEventPayloads(driver, mockedEndpoints);
Expand Down Expand Up @@ -142,10 +142,10 @@ describe('Dapp viewed Event @no-mmi', function () {
.build(),
title: this.test.fullTitle(),
testSpecificMock: mockSegment,
ganacheOptions: defaultGanacheOptions,
},
async ({ driver, mockedEndpoint: mockedEndpoints }) => {
await unlockWallet(driver);
await waitForAccountRendered(driver);
async ({ driver, mockedEndpoint: mockedEndpoints, ganacheServer }) => {
await logInWithBalanceValidation(driver, ganacheServer);
await connectToDapp(driver);
await waitForDappConnected(driver);
// open dapp in a new page
Expand Down Expand Up @@ -180,10 +180,10 @@ describe('Dapp viewed Event @no-mmi', function () {
.build(),
title: this.test.fullTitle(),
testSpecificMock: mockSegment,
ganacheOptions: defaultGanacheOptions,
},
async ({ driver, mockedEndpoint: mockedEndpoints }) => {
await unlockWallet(driver);
await waitForAccountRendered(driver);
async ({ driver, mockedEndpoint: mockedEndpoints, ganacheServer }) => {
await logInWithBalanceValidation(driver, ganacheServer);
await connectToDapp(driver);
await waitForDappConnected(driver);
// refresh dapp
Expand Down Expand Up @@ -223,10 +223,10 @@ describe('Dapp viewed Event @no-mmi', function () {
.build(),
title: this.test.fullTitle(),
testSpecificMock: mockSegment,
ganacheOptions: defaultGanacheOptions,
},
async ({ driver, mockedEndpoint: mockedEndpoints }) => {
await unlockWallet(driver);
await waitForAccountRendered(driver);
async ({ driver, mockedEndpoint: mockedEndpoints, ganacheServer }) => {
await logInWithBalanceValidation(driver, ganacheServer);
await connectToDapp(driver);
await waitForDappConnected(driver);
// open dapp in a new page
Expand Down Expand Up @@ -259,10 +259,11 @@ describe('Dapp viewed Event @no-mmi', function () {
})
.build(),
title: this.test.fullTitle(),
ganacheOptions: defaultGanacheOptions,
testSpecificMock: mockSegment,
},
async ({ driver, mockedEndpoint: mockedEndpoints }) => {
await unlockWallet(driver);
async ({ driver, mockedEndpoint: mockedEndpoints, ganacheServer }) => {
await logInWithBalanceValidation(driver, ganacheServer);
// create 2nd account
await createTwoAccounts(driver);
// Connect to dapp with two accounts
Expand Down Expand Up @@ -314,10 +315,10 @@ describe('Dapp viewed Event @no-mmi', function () {
.build(),
title: this.test.fullTitle(),
testSpecificMock: mockSegment,
ganacheOptions: defaultGanacheOptions,
},
async ({ driver, mockedEndpoint: mockedEndpoints }) => {
await unlockWallet(driver);
await waitForAccountRendered(driver);
async ({ driver, mockedEndpoint: mockedEndpoints, ganacheServer }) => {
await logInWithBalanceValidation(driver, ganacheServer);
await connectToDapp(driver);
await waitForDappConnected(driver);

Expand Down
8 changes: 3 additions & 5 deletions test/e2e/tests/metrics/unlock-wallet.spec.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
const { strict: assert } = require('assert');
const {
withFixtures,
unlockWallet,
waitForAccountRendered,
logInWithBalanceValidation,
defaultGanacheOptions,
getEventPayloads,
} = require('../../helpers');
Expand Down Expand Up @@ -36,9 +35,8 @@ describe('Unlock wallet', function () {
title: this.test.fullTitle(),
testSpecificMock: mockSegment,
},
async ({ driver, mockedEndpoint }) => {
await unlockWallet(driver);
await waitForAccountRendered(driver);
async ({ driver, mockedEndpoint, ganacheServer }) => {
await logInWithBalanceValidation(driver, ganacheServer);
const events = await getEventPayloads(driver, mockedEndpoint);
const sortedEvents = sortEventsByTime(events);
await assert.equal(sortedEvents.length, 3);
Expand Down
20 changes: 11 additions & 9 deletions test/e2e/tests/multichain/connection-page.spec.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
const { strict: assert } = require('assert');
const {
withFixtures,
unlockWallet,
WINDOW_TITLES,
waitForAccountRendered,
connectToDapp,
logInWithBalanceValidation,
locateAccountBalanceDOM,
defaultGanacheOptions,
} = require('../../helpers');
const FixtureBuilder = require('../../fixture-builder');

Expand All @@ -18,10 +19,10 @@ describe('Connections page', function () {
dapp: true,
fixtures: new FixtureBuilder().build(),
title: this.test.fullTitle(),
ganacheOptions: defaultGanacheOptions,
},
async ({ driver }) => {
await unlockWallet(driver);
await waitForAccountRendered(driver);
async ({ driver, ganacheServer }) => {
await logInWithBalanceValidation(driver, ganacheServer);
await connectToDapp(driver);

// It should render connected status for button if dapp is connected
Expand Down Expand Up @@ -91,16 +92,17 @@ describe('Connections page', function () {
},
);
});

it('should connect more accounts when already connected to a dapp', async function () {
await withFixtures(
{
dapp: true,
fixtures: new FixtureBuilder().build(),
title: this.test.fullTitle(),
ganacheOptions: defaultGanacheOptions,
},
async ({ driver }) => {
await unlockWallet(driver);
await waitForAccountRendered(driver);
async ({ driver, ganacheServer }) => {
await logInWithBalanceValidation(driver, ganacheServer);
await connectToDapp(driver);

const account = await driver.findElement('#accounts');
Expand Down Expand Up @@ -135,7 +137,7 @@ describe('Connections page', function () {
);
await driver.fill('[placeholder="Account 3"]', accountLabel3);
await driver.clickElement({ text: 'Create', tag: 'button' });
await waitForAccountRendered(driver);
await locateAccountBalanceDOM(driver);
await driver.clickElement(
'[data-testid ="account-options-menu-button"]',
);
Expand Down
Loading