Skip to content

Commit 2e2edb5

Browse files
authored
test: [POM] Migrate create btc account e2e tests to TS and Page Object Model (#28437)
## **Description** - Migrate create btc account e2e tests to TS and Page Object Model [![Open in GitHub Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/MetaMask/metamask-extension/pull/27155?quickstart=1) ## **Related issues** Fixes: #28542 ## **Manual testing steps** Check code readability, make sure tests pass. ## **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/develop/.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/develop/.github/guidelines/LABELING_GUIDELINES.md)). Not required for external contributors. ## **Pre-merge reviewer checklist** - [x] I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed). - [x] 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 0bf00e6 commit 2e2edb5

11 files changed

+255
-277
lines changed

test/e2e/flask/btc/common-btc.ts

+10-25
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Mockttp } from 'mockttp';
22
import FixtureBuilder from '../../fixture-builder';
3-
import { withFixtures, unlockWallet } from '../../helpers';
3+
import { withFixtures } from '../../helpers';
44
import {
55
DEFAULT_BTC_ACCOUNT,
66
DEFAULT_BTC_BALANCE,
@@ -11,7 +11,9 @@ import {
1111
} from '../../constants';
1212
import { MultichainNetworks } from '../../../../shared/constants/multichain/networks';
1313
import { Driver } from '../../webdriver/driver';
14-
import messages from '../../../../app/_locales/en/messages.json';
14+
import { loginWithBalanceValidation } from '../../page-objects/flows/login.flow';
15+
import AccountListPage from '../../page-objects/pages/account-list-page';
16+
import HeaderNavbar from '../../page-objects/pages/header-navbar';
1517

1618
const QUICKNODE_URL_REGEX = /^https:\/\/.*\.btc.*\.quiknode\.pro(\/|$)/u;
1719

@@ -21,27 +23,6 @@ export enum SendFlowPlaceHolders {
2123
LOADING = 'Preparing transaction',
2224
}
2325

24-
export async function createBtcAccount(driver: Driver) {
25-
await driver.clickElement('[data-testid="account-menu-icon"]');
26-
await driver.clickElement(
27-
'[data-testid="multichain-account-menu-popover-action-button"]',
28-
);
29-
await driver.clickElement({
30-
text: messages.addNewBitcoinAccount.message,
31-
tag: 'button',
32-
});
33-
await driver.clickElementAndWaitToDisappear(
34-
{
35-
text: 'Add account',
36-
tag: 'button',
37-
},
38-
// Longer timeout than usual, this reduces the flakiness
39-
// around Bitcoin account creation (mainly required for
40-
// Firefox)
41-
5000,
42-
);
43-
}
44-
4526
export function btcToSats(btc: number): number {
4627
// Watchout, we're not using BigNumber(s) here (but that's ok for test purposes)
4728
return btc * SATS_IN_1_BTC;
@@ -231,8 +212,12 @@ export async function withBtcAccountSnap(
231212
],
232213
},
233214
async ({ driver, mockServer }: { driver: Driver; mockServer: Mockttp }) => {
234-
await unlockWallet(driver);
235-
await createBtcAccount(driver);
215+
await loginWithBalanceValidation(driver);
216+
// create one BTC account
217+
await new HeaderNavbar(driver).openAccountMenu();
218+
const accountListPage = new AccountListPage(driver);
219+
await accountListPage.check_pageIsLoaded();
220+
await accountListPage.addNewBtcAccount();
236221
await test(driver, mockServer);
237222
},
238223
);

test/e2e/flask/btc/create-btc-account.spec.ts

+109-125
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,22 @@
11
import { strict as assert } from 'assert';
22
import { Suite } from 'mocha';
3-
import messages from '../../../../app/_locales/en/messages.json';
4-
5-
import {
6-
WALLET_PASSWORD,
7-
completeSRPRevealQuiz,
8-
getSelectedAccountAddress,
9-
openSRPRevealQuiz,
10-
removeSelectedAccount,
11-
tapAndHoldToRevealSRP,
12-
} from '../../helpers';
13-
import { createBtcAccount, withBtcAccountSnap } from './common-btc';
3+
import { WALLET_PASSWORD } from '../../helpers';
4+
import AccountListPage from '../../page-objects/pages/account-list-page';
5+
import HeaderNavbar from '../../page-objects/pages/header-navbar';
6+
import LoginPage from '../../page-objects/pages/login-page';
7+
import PrivacySettings from '../../page-objects/pages/settings/privacy-settings';
8+
import ResetPasswordPage from '../../page-objects/pages/reset-password-page';
9+
import SettingsPage from '../../page-objects/pages/settings/settings-page';
10+
import { withBtcAccountSnap } from './common-btc';
1411

1512
describe('Create BTC Account', function (this: Suite) {
1613
it('create BTC account from the menu', async function () {
1714
await withBtcAccountSnap(
1815
{ title: this.test?.fullTitle() },
1916
async (driver) => {
20-
await driver.findElement({
21-
css: '[data-testid="account-menu-icon"]',
22-
text: 'Bitcoin Account',
23-
});
17+
const headerNavbar = new HeaderNavbar(driver);
18+
await headerNavbar.check_pageIsLoaded();
19+
await headerNavbar.check_accountLabel('Bitcoin Account');
2420
},
2521
);
2622
});
@@ -29,27 +25,23 @@ describe('Create BTC Account', function (this: Suite) {
2925
await withBtcAccountSnap(
3026
{ title: this.test?.fullTitle() },
3127
async (driver) => {
32-
await driver.delay(500);
33-
await driver.clickElement('[data-testid="account-menu-icon"]');
34-
await driver.clickElement(
35-
'[data-testid="multichain-account-menu-popover-action-button"]',
36-
);
37-
38-
const createButton = await driver.findElement({
39-
text: messages.addNewBitcoinAccount.message,
40-
tag: 'button',
28+
// check that we have one BTC account
29+
const headerNavbar = new HeaderNavbar(driver);
30+
await headerNavbar.check_pageIsLoaded();
31+
await headerNavbar.check_accountLabel('Bitcoin Account');
32+
33+
// check user cannot create second BTC account
34+
await headerNavbar.openAccountMenu();
35+
const accountListPage = new AccountListPage(driver);
36+
await accountListPage.check_pageIsLoaded();
37+
await accountListPage.addNewBtcAccount({
38+
btcAccountCreationEnabled: false,
4139
});
42-
assert.equal(await createButton.isEnabled(), false);
4340

44-
// modal will still be here
45-
await driver.clickElement('.mm-box button[aria-label="Close"]');
46-
47-
// check the number of accounts. it should only be 2.
48-
await driver.clickElement('[data-testid="account-menu-icon"]');
49-
const menuItems = await driver.findElements(
50-
'.multichain-account-list-item',
51-
);
52-
assert.equal(menuItems.length, 2);
41+
// check the number of available accounts is 2
42+
await headerNavbar.openAccountMenu();
43+
await accountListPage.check_pageIsLoaded();
44+
await accountListPage.check_numberOfAvailableAccounts(2);
5345
},
5446
);
5547
});
@@ -58,29 +50,22 @@ describe('Create BTC Account', function (this: Suite) {
5850
await withBtcAccountSnap(
5951
{ title: this.test?.fullTitle() },
6052
async (driver) => {
61-
await driver.findElement({
62-
css: '[data-testid="account-menu-icon"]',
63-
text: 'Bitcoin Account',
64-
});
65-
66-
await driver.clickElement('[data-testid="account-menu-icon"]');
67-
await driver.clickElement(
68-
'.multichain-account-list-item--selected [data-testid="account-list-item-menu-button"]',
69-
);
70-
await driver.clickElement('[data-testid="account-list-menu-remove"]');
71-
await driver.clickElement({ text: 'Nevermind', tag: 'button' });
72-
73-
await driver.findElement({
74-
css: '[data-testid="account-menu-icon"]',
75-
text: 'Bitcoin Account',
76-
});
77-
78-
// check the number of accounts. it should only be 2.
79-
await driver.clickElement('[data-testid="account-menu-icon"]');
80-
const menuItems = await driver.findElements(
81-
'.multichain-account-list-item',
82-
);
83-
assert.equal(menuItems.length, 2);
53+
// check that we have one BTC account
54+
const headerNavbar = new HeaderNavbar(driver);
55+
await headerNavbar.check_pageIsLoaded();
56+
await headerNavbar.check_accountLabel('Bitcoin Account');
57+
58+
// check user can cancel the removal of the BTC account
59+
await headerNavbar.openAccountMenu();
60+
const accountListPage = new AccountListPage(driver);
61+
await accountListPage.check_pageIsLoaded();
62+
await accountListPage.removeAccount('Bitcoin Account', false);
63+
await headerNavbar.check_accountLabel('Bitcoin Account');
64+
65+
// check the number of accounts. it should be 2.
66+
await headerNavbar.openAccountMenu();
67+
await accountListPage.check_pageIsLoaded();
68+
await accountListPage.check_numberOfAvailableAccounts(2);
8469
},
8570
);
8671
});
@@ -89,22 +74,33 @@ describe('Create BTC Account', function (this: Suite) {
8974
await withBtcAccountSnap(
9075
{ title: this.test?.fullTitle() },
9176
async (driver) => {
92-
await driver.findElement({
93-
css: '[data-testid="account-menu-icon"]',
94-
text: 'Bitcoin Account',
95-
});
96-
97-
const accountAddress = await getSelectedAccountAddress(driver);
98-
await removeSelectedAccount(driver);
99-
100-
// Recreate account
101-
await createBtcAccount(driver);
102-
await driver.findElement({
103-
css: '[data-testid="account-menu-icon"]',
104-
text: 'Bitcoin Account',
105-
});
77+
// check that we have one BTC account
78+
const headerNavbar = new HeaderNavbar(driver);
79+
await headerNavbar.check_pageIsLoaded();
80+
await headerNavbar.check_accountLabel('Bitcoin Account');
81+
82+
// get the address of the BTC account and remove it
83+
await headerNavbar.openAccountMenu();
84+
const accountListPage = new AccountListPage(driver);
85+
await accountListPage.check_pageIsLoaded();
86+
const accountAddress = await accountListPage.getAccountAddress(
87+
'Bitcoin Account',
88+
);
89+
await headerNavbar.openAccountMenu();
90+
await accountListPage.removeAccount('Bitcoin Account');
91+
92+
// Recreate account and check that the address is the same
93+
await headerNavbar.openAccountMenu();
94+
await accountListPage.check_pageIsLoaded();
95+
await accountListPage.addNewBtcAccount();
96+
await headerNavbar.check_accountLabel('Bitcoin Account');
97+
98+
await headerNavbar.openAccountMenu();
99+
await accountListPage.check_pageIsLoaded();
100+
const recreatedAccountAddress = await accountListPage.getAccountAddress(
101+
'Bitcoin Account',
102+
);
106103

107-
const recreatedAccountAddress = await getSelectedAccountAddress(driver);
108104
assert(accountAddress === recreatedAccountAddress);
109105
},
110106
);
@@ -114,62 +110,50 @@ describe('Create BTC Account', function (this: Suite) {
114110
await withBtcAccountSnap(
115111
{ title: this.test?.fullTitle() },
116112
async (driver) => {
117-
await driver.findElement({
118-
css: '[data-testid="account-menu-icon"]',
119-
text: 'Bitcoin Account',
120-
});
121-
122-
const accountAddress = await getSelectedAccountAddress(driver);
123-
124-
await openSRPRevealQuiz(driver);
125-
await completeSRPRevealQuiz(driver);
126-
await driver.fill('[data-testid="input-password"]', WALLET_PASSWORD);
127-
await driver.press('[data-testid="input-password"]', driver.Key.ENTER);
128-
await tapAndHoldToRevealSRP(driver);
129-
const seedPhrase = await (
130-
await driver.findElement('[data-testid="srp_text"]')
131-
).getText();
132-
133-
// Reset wallet
134-
await driver.clickElement(
135-
'[data-testid="account-options-menu-button"]',
136-
);
137-
await driver.clickElement({
138-
css: '[data-testid="global-menu-lock"]',
139-
text: 'Lock MetaMask',
140-
});
141-
142-
await driver.clickElement({
143-
text: 'Forgot password?',
144-
tag: 'a',
145-
});
146-
147-
await driver.pasteIntoField(
148-
'[data-testid="import-srp__srp-word-0"]',
149-
seedPhrase,
113+
// check that we have one BTC account
114+
const headerNavbar = new HeaderNavbar(driver);
115+
await headerNavbar.check_pageIsLoaded();
116+
await headerNavbar.check_accountLabel('Bitcoin Account');
117+
118+
await headerNavbar.openAccountMenu();
119+
const accountListPage = new AccountListPage(driver);
120+
await accountListPage.check_pageIsLoaded();
121+
const accountAddress = await accountListPage.getAccountAddress(
122+
'Bitcoin Account',
150123
);
151124

152-
await driver.fill(
153-
'[data-testid="create-vault-password"]',
154-
WALLET_PASSWORD,
125+
// go to privacy settings page and get the SRP
126+
await headerNavbar.openSettingsPage();
127+
const settingsPage = new SettingsPage(driver);
128+
await settingsPage.check_pageIsLoaded();
129+
await settingsPage.goToPrivacySettings();
130+
131+
const privacySettings = new PrivacySettings(driver);
132+
await privacySettings.check_pageIsLoaded();
133+
await privacySettings.openRevealSrpQuiz();
134+
await privacySettings.completeRevealSrpQuiz();
135+
await privacySettings.fillPasswordToRevealSrp(WALLET_PASSWORD);
136+
const seedPhrase = await privacySettings.getSrpInRevealSrpDialog();
137+
138+
// lock metamask and reset wallet by clicking forgot password button
139+
await headerNavbar.lockMetaMask();
140+
await new LoginPage(driver).gotoResetPasswordPage();
141+
const resetPasswordPage = new ResetPasswordPage(driver);
142+
await resetPasswordPage.check_pageIsLoaded();
143+
await resetPasswordPage.resetPassword(seedPhrase, WALLET_PASSWORD);
144+
145+
// create a BTC account and check that the address is the same
146+
await headerNavbar.check_pageIsLoaded();
147+
await headerNavbar.openAccountMenu();
148+
await accountListPage.check_pageIsLoaded();
149+
await accountListPage.addNewBtcAccount();
150+
await headerNavbar.check_accountLabel('Bitcoin Account');
151+
152+
await headerNavbar.openAccountMenu();
153+
await accountListPage.check_pageIsLoaded();
154+
const recreatedAccountAddress = await accountListPage.getAccountAddress(
155+
'Bitcoin Account',
155156
);
156-
await driver.fill(
157-
'[data-testid="create-vault-confirm-password"]',
158-
WALLET_PASSWORD,
159-
);
160-
161-
await driver.clickElement({
162-
text: 'Restore',
163-
tag: 'button',
164-
});
165-
166-
await createBtcAccount(driver);
167-
await driver.findElement({
168-
css: '[data-testid="account-menu-icon"]',
169-
text: 'Bitcoin Account',
170-
});
171-
172-
const recreatedAccountAddress = await getSelectedAccountAddress(driver);
173157
assert(accountAddress === recreatedAccountAddress);
174158
},
175159
);

0 commit comments

Comments
 (0)