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

test: Allow token balance to populate after swap #28744

Merged
merged 9 commits into from
Dec 2, 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
17 changes: 16 additions & 1 deletion test/e2e/playwright/shared/pageObjects/wallet-page.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { type Locator, type Page } from '@playwright/test';

export class WalletPage {
private page: Page;
readonly page: Page;

readonly importTokensButton: Locator;

Expand All @@ -21,6 +21,8 @@ export class WalletPage {

readonly importAccountConfirmBtn: Locator;

readonly tokenBalance: Locator;

constructor(page: Page) {
this.page = page;
this.swapButton = this.page.getByTestId('token-overview-button-swap');
Expand All @@ -29,6 +31,9 @@ export class WalletPage {
this.importAccountButton = this.page.getByText('Import account');
this.importButton = this.page.getByText('Import (');
this.tokenTab = this.page.getByTestId('account-overview__asset-tab');
this.tokenBalance = this.page.getByTestId(
'multichain-token-list-item-value',
);
this.addAccountButton = this.page.getByTestId(
'multichain-account-menu-popover-action-button',
);
Expand All @@ -54,6 +59,8 @@ export class WalletPage {
await this.importAccountButton.click();
await this.page.fill('#private-key-box', accountPK);
await this.importAccountConfirmBtn.click();
await this.page.waitForTimeout(2000);
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this mandatory? is not possible to change it for a locator?

return await this.accountMenu.textContent();
}

async selectTokenWallet() {
Expand All @@ -68,4 +75,12 @@ export class WalletPage {
async selectActivityList() {
await this.activityListTab.click();
}

async getTokenBalance() {
return await this.tokenBalance.first().textContent();
}

async waitforTokenBalance(balance: string) {
await this.page.waitForSelector(`text=/${balance}/`, { timeout: 60000 });
}
}
8 changes: 6 additions & 2 deletions test/e2e/playwright/swap/specs/swap.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ethers } from 'ethers';
import { test } from '@playwright/test';
import { test, expect } from '@playwright/test';
import log from 'loglevel';

import { ChromeExtensionPage } from '../../shared/pageObjects/extension-page';
Expand Down Expand Up @@ -73,7 +73,9 @@ test.beforeAll(
walletPage = new WalletPage(page);

await networkController.addCustomNetwork(Tenderly.Mainnet);
await walletPage.importAccount(wallet.privateKey);
const accountName = await walletPage.importAccount(wallet.privateKey);
expect(accountName).toEqual('Account 2');
await walletPage.waitforTokenBalance('1 ETH');
},
);

Expand All @@ -82,6 +84,8 @@ testSet.forEach((options) => {
await walletPage.selectTokenWallet();
await networkController.selectNetwork(options.network);
await walletPage.selectSwapAction();
// Allow balance label to populate
await walletPage.page.waitForTimeout(3000);
Copy link
Contributor

@chloeYue chloeYue Dec 2, 2024

Choose a reason for hiding this comment

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

Do we have a dynamic way to wait for the balance label to populate?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Unfortunately not in this case like I did above. If I click and open the control and wait to populate it will never populate it will always stay zero.

const quoteEntered = await swapPage.enterQuote({
from: options.source,
to: options.destination,
Expand Down
Loading