Skip to content

Commit 7278cdd

Browse files
test(e2e/tron): refactor account cluster E2E tests to better follow the guidelines (#46114)
## **Description** Completes the `account` cluster E2E refactor so it follows the repo's E2E/POM guidelines, after reviewing the sibling Tron PRs (#46113, #46115–#46118). Recreates the account-derivation portion of #45708 without the shared-Chrome-session infrastructure (see WPN-1881). - Moves the spec to `test/e2e/tests/account/tron/account-derivation.spec.ts`. - Extracts the chain-neutral per-index address assertions into `test/e2e/page-objects/flows/account-list.flow.ts` and the discovery fixtures into `test/e2e/tests/account/tron/utils/`. - Moves the QR/explorer modal selectors and methods from `address-list-page` to `address-modal`, and replaces find-then-assert waits with selector-based waits. - Drops the redundant BIP44 Stage 2 feature-flag override now that production enables those flags, keeping `tronTestnetsEnabled` for the Tron testnets spec. Verification: `yarn lint:changed:fix`, ESLint, `yarn lint:tsc`, and `yarn build:test` pass. `account-derivation.spec.ts` on Chrome: 5 passing, 1 pending (the pre-existing skipped QR test). The quick-copy test passes on Firefox as well. `is-present-tron.spec.ts`: 2 passing. ## **Changelog** CHANGELOG entry: null ## **Related issues** Part of [WPN-1881](https://consensyssoftware.atlassian.net/browse/WPN-1881). Recreates #45708 without session sharing. Sibling PRs: #46113, #46115, #46116, #46117, #46118. <!-- ## **Manual testing steps** No user-facing change. The E2E coverage is exercised by the automated suite listed in the description above. --> <!-- ## **Screenshots/Recordings** Not applicable: E2E test refactor with no user-facing UI change. --> ## **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. [WPN-1881]: https://consensyssoftware.atlassian.net/browse/WPN-1881?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ
1 parent c1f365d commit 7278cdd

7 files changed

Lines changed: 264 additions & 234 deletions

File tree

‎test/e2e/page-objects/flows/account-list.flow.ts‎

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,3 +72,84 @@ export const switchToAccount = async (
7272
await accountListPage.switchToAccount(accountName);
7373
await homePage.headerNavbar.checkAccountLabel(accountName);
7474
};
75+
76+
type AssertAddressAtIndexOptions = {
77+
index: number;
78+
networkName: string;
79+
expectedAddress: string;
80+
};
81+
82+
/**
83+
* Asserts the derived address for the account at `index` (0-based) on the
84+
* given network: opens the account's multichain menu, enters the address list,
85+
* verifies the shortened address is shown for the network row, and copies it
86+
* to the clipboard.
87+
*
88+
* @param driver - The WebDriver instance.
89+
* @param options - Assertion options.
90+
* @param options.index - Zero-based account index.
91+
* @param options.networkName - Network row to assert.
92+
* @param options.expectedAddress - Full address expected for the account.
93+
*/
94+
export async function assertAddressAtIndex(
95+
driver: Driver,
96+
{ index, networkName, expectedAddress }: AssertAddressAtIndexOptions,
97+
): Promise<void> {
98+
const accountListPage = new AccountListPage(driver);
99+
const accountAddressListPage = new AccountAddressListPage(driver);
100+
const accountLabel = `Account ${index + 1}`;
101+
102+
await accountListPage.openMultichainAccountMenu({ accountLabel });
103+
await accountListPage.clickMultichainAccountMenuItem('Addresses');
104+
await accountAddressListPage.checkPageIsLoaded();
105+
await accountAddressListPage.checkNetworkAddressIsDisplayedForNetwork({
106+
networkName,
107+
networkAddress: shortenAddress(expectedAddress),
108+
});
109+
await accountAddressListPage.clickCopyButtonForNetworkAndAssertClipboard({
110+
networkName,
111+
expectedAddress,
112+
});
113+
await accountAddressListPage.goBack();
114+
}
115+
116+
type AssertNetworkAddressesForAccountsOptions = {
117+
total: number;
118+
networkName: string;
119+
expectedAddresses: readonly string[];
120+
};
121+
122+
/**
123+
* Asserts the derived addresses for the first `total` HD accounts.
124+
*
125+
* @param driver - The WebDriver instance.
126+
* @param options - Assertion options.
127+
* @param options.total - Number of accounts to assert, starting at index 0.
128+
* @param options.networkName - Network row to assert.
129+
* @param options.expectedAddresses - Expected addresses by account index.
130+
*/
131+
export async function assertNetworkAddressesForAccounts(
132+
driver: Driver,
133+
{
134+
total,
135+
networkName,
136+
expectedAddresses,
137+
}: AssertNetworkAddressesForAccountsOptions,
138+
): Promise<void> {
139+
const homePage = new HomePage(driver);
140+
const accountListPage = new AccountListPage(driver);
141+
142+
await homePage.headerNavbar.openAccountMenu();
143+
await accountListPage.checkPageIsLoaded();
144+
await accountListPage.waitUntilSyncingIsCompleted();
145+
146+
for (let index = 0; index < total; index += 1) {
147+
await assertAddressAtIndex(driver, {
148+
index,
149+
networkName,
150+
expectedAddress: expectedAddresses[index],
151+
});
152+
}
153+
154+
await accountListPage.closeMultichainAccountsPage();
155+
}

‎test/e2e/page-objects/pages/accounts/address-list-page.ts‎

Lines changed: 24 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,6 @@ import { quoteXPathText } from '../../../../helpers/quoteXPathText';
1515
* @see ui/pages/multichain-accounts/multichain-account-address-list-page/multichain-account-address-list-page.tsx
1616
*/
1717
class AccountAddressListPage {
18-
private readonly accountAddress =
19-
'[data-testid="multichain-address-row-address"]';
20-
2118
private readonly addressCopiedMessage = {
2219
css: '[data-testid="multichain-address-row-address"]',
2320
text: 'Address copied',
@@ -31,8 +28,8 @@ class AccountAddressListPage {
3128
private readonly backButton =
3229
'[data-testid="multichain-account-address-list-page-back-button"]';
3330

34-
private readonly copyButton =
35-
'[data-testid="multichain-address-row-copy-button"]';
31+
private readonly copyButtonXpath =
32+
"//*[@data-testid='multichain-address-row-copy-button']";
3633

3734
private driver: Driver;
3835

@@ -42,17 +39,12 @@ class AccountAddressListPage {
4239
private readonly qrButton =
4340
'[data-testid="multichain-address-row-qr-button"]';
4441

45-
private readonly qrModalAddress = '[data-testid="account-address"]';
46-
47-
private readonly qrModalCopyButton =
48-
'[data-testid="address-qr-code-modal-copy-button"]';
42+
private readonly qrButtonXpath =
43+
"//*[@data-testid='multichain-address-row-qr-button']";
4944

5045
private readonly shortenedAddress =
5146
'[data-testid="multichain-address-row-address"]';
5247

53-
private readonly viewOnExplorerButton =
54-
'[data-testid="view-address-on-etherscan"]';
55-
5648
constructor(driver: Driver) {
5749
this.driver = driver;
5850
}
@@ -114,24 +106,6 @@ class AccountAddressListPage {
114106
console.log('Address list modal is loaded');
115107
}
116108

117-
async checkQrPopupShowsAddress(expectedAddress: string): Promise<void> {
118-
console.log(`Check QR popup shows address "${expectedAddress}"`);
119-
await this.driver.waitForSelector(this.qrModalAddress);
120-
await this.driver.waitUntil(
121-
async () => {
122-
const addressElement = await this.driver.findElement(
123-
this.qrModalAddress,
124-
);
125-
const displayedAddress = (await addressElement.getText()).replace(
126-
/\s+/gu,
127-
'',
128-
);
129-
return displayedAddress === expectedAddress;
130-
},
131-
{ interval: 100, timeout: this.driver.timeout },
132-
);
133-
}
134-
135109
async checkQuickCopyAddressIsDisplayedForNetwork({
136110
networkName,
137111
networkAddress,
@@ -142,16 +116,13 @@ class AccountAddressListPage {
142116
console.log(
143117
`Check quick-copy popover shows "${networkAddress}" for "${networkName}"`,
144118
);
145-
await this.driver.waitUntil(
146-
async () => {
147-
const row = await this.driver.findElement(
148-
this.quickCopyRowByNetworkName(networkName),
149-
);
150-
const rowText = await row.getText();
151-
return rowText.includes(networkAddress);
152-
},
153-
{ interval: 500, timeout: this.driver.timeout },
154-
);
119+
const rowXpath = this.quickCopyRowByNetworkName(networkName).xpath;
120+
await this.driver.waitForSelector({
121+
xpath: rowXpath.replace(
122+
/\]$/u,
123+
` and contains(normalize-space(.), ${quoteXPathText(networkAddress)})]`,
124+
),
125+
});
155126
}
156127

157128
async checkQuickCopyPopoverIsLoaded(): Promise<void> {
@@ -170,30 +141,17 @@ class AccountAddressListPage {
170141
console.log('Quick-copy address popover is loaded');
171142
}
172143

173-
async checkViewOnTronscanButton(): Promise<void> {
174-
console.log('Verify View on Tronscan button is present');
175-
await this.driver.waitForSelector({
176-
css: this.viewOnExplorerButton,
177-
text: 'View on Tronscan',
178-
});
179-
}
180-
181144
async clickCopyButton(addressIndex: number = 0): Promise<void> {
182-
const copyButtonsList = await this.driver.findElements(this.copyButton);
183-
const copyButton = copyButtonsList[addressIndex];
184-
await copyButton.click();
145+
await this.driver.clickElement({
146+
xpath: `(${this.copyButtonXpath})[${addressIndex + 1}]`,
147+
});
185148
}
186149

187150
async clickCopyButtonForNetwork(networkName: string): Promise<void> {
188151
console.log(`Click copy button for network "${networkName}"`);
189-
const row = await this.driver.findElement(
190-
this.addressListRowByNetworkName(networkName),
191-
);
192-
const copyButton = await this.driver.findNestedElement(
193-
row,
194-
this.copyButton,
195-
);
196-
await copyButton.click();
152+
await this.driver.clickElement({
153+
xpath: `${this.addressListRowByNetworkName(networkName).xpath}${this.copyButtonXpath}`,
154+
});
197155
}
198156

199157
async clickCopyButtonForNetworkAndAssertClipboard({
@@ -208,25 +166,16 @@ class AccountAddressListPage {
208166
}
209167

210168
async clickQRbutton(addressIndex: number = 0): Promise<void> {
211-
const qrButtonsList = await this.driver.findElements(this.qrButton);
212-
const qrButton = qrButtonsList[addressIndex];
213-
await qrButton.click();
169+
await this.driver.clickElement({
170+
xpath: `(${this.qrButtonXpath})[${addressIndex + 1}]`,
171+
});
214172
}
215173

216174
async clickQRbuttonForNetwork(networkName: string): Promise<void> {
217175
console.log(`Click QR button for network "${networkName}"`);
218-
const row = await this.driver.findElement(
219-
this.addressListRowByNetworkName(networkName),
220-
);
221-
const qrButton = await this.driver.findNestedElement(row, this.qrButton);
222-
await qrButton.click();
223-
}
224-
225-
async clickQrCopyAddressLink(expectedAddress: string): Promise<void> {
226-
console.log('Click copy address button in QR popup');
227-
await this.driver.waitForSelector(this.qrModalCopyButton);
228-
await this.driver.clickElement(this.qrModalCopyButton);
229-
await this.driver.waitForClipboardContent(expectedAddress);
176+
await this.driver.clickElement({
177+
xpath: `${this.addressListRowByNetworkName(networkName).xpath}${this.qrButtonXpath}`,
178+
});
230179
}
231180

232181
async clickQuickCopyButtonForNetwork({
@@ -237,24 +186,10 @@ class AccountAddressListPage {
237186
expectedAddress: string;
238187
}): Promise<void> {
239188
console.log(`Click quick-copy row for network "${networkName}"`);
240-
const row = await this.driver.findElement(
241-
this.quickCopyRowByNetworkName(networkName),
242-
);
243-
await row.click();
189+
await this.driver.clickElement(this.quickCopyRowByNetworkName(networkName));
244190
await this.driver.waitForClipboardContent(expectedAddress);
245191
}
246192

247-
async getTruncatedAccountAddress(addressIndex: number = 0): Promise<string> {
248-
console.log('Get truncated account address');
249-
const addressElements = await this.driver.findElements(this.accountAddress);
250-
if (addressIndex < 0 || addressIndex >= addressElements.length) {
251-
throw new Error('Invalid account row index');
252-
}
253-
const addressElement = addressElements[addressIndex];
254-
const address = await addressElement.getText();
255-
return address;
256-
}
257-
258193
async goBack(): Promise<void> {
259194
await this.driver.clickElementAndWaitToDisappear(this.backButton);
260195
}

‎test/e2e/page-objects/pages/accounts/address-modal.ts‎

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { Driver } from '../../../webdriver/driver';
2+
import { quoteXPathText } from '../../../../helpers/quoteXPathText';
23

34
/**
45
* Single-address QR overlay: full address and view-on-explorer.
@@ -23,6 +24,9 @@ class AccountAddressModal {
2324
private readonly parentSelector =
2425
'[data-testid="parent-selector-address-qr-code-modal"]';
2526

27+
private readonly qrModalCopyButton =
28+
'[data-testid="address-qr-code-modal-copy-button"]';
29+
2630
private readonly viewOnEtherscanLink =
2731
'[data-testid="view-address-on-etherscan"]';
2832

@@ -49,6 +53,18 @@ class AccountAddressModal {
4953
console.log('Account address modal is loaded');
5054
}
5155

56+
/**
57+
* Verify the displayed address matches the expected one
58+
*
59+
* @param expectedAddress - The address expected in the modal
60+
*/
61+
async checkQrPopupShowsAddress(expectedAddress: string): Promise<void> {
62+
console.log(`Check QR popup shows address "${expectedAddress}"`);
63+
await this.driver.waitForSelector({
64+
xpath: `//*[@data-testid='account-address'][translate(normalize-space(.), ' ', '') = ${quoteXPathText(expectedAddress)}]`,
65+
});
66+
}
67+
5268
/**
5369
* Verify the View on Etherscan button is present
5470
*/
@@ -57,6 +73,23 @@ class AccountAddressModal {
5773
await this.driver.findElement(this.viewOnEtherscanLink);
5874
}
5975

76+
/**
77+
* Verify the View on Tronscan button is present
78+
*/
79+
async checkViewOnTronscanButton(): Promise<void> {
80+
console.log('Verify View on Tronscan button is present');
81+
await this.driver.waitForSelector({
82+
css: this.viewOnEtherscanLink,
83+
text: 'View on Tronscan',
84+
});
85+
}
86+
87+
async clickQrCopyAddressLink(expectedAddress: string): Promise<void> {
88+
console.log('Click copy address button in QR popup');
89+
await this.driver.clickElement(this.qrModalCopyButton);
90+
await this.driver.waitForClipboardContent(expectedAddress);
91+
}
92+
6093
/**
6194
* Get the account address from the modal
6295
*/

0 commit comments

Comments
 (0)