Skip to content

Commit

Permalink
test: update widget connectWallet function
Browse files Browse the repository at this point in the history
  • Loading branch information
jake4take committed Jan 15, 2025
1 parent cf228c0 commit be8fd83
Showing 1 changed file with 46 additions and 37 deletions.
83 changes: 46 additions & 37 deletions packages/widgets/src/ethereum/ethereum.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,15 @@ import { test, Page, Locator } from '@playwright/test';
export class EthereumPage implements WidgetPage {
private readonly logger = new Logger(EthereumPage.name);
page: Page;
connectBtn: Locator;
stakeSubmitBtn: Locator;
termsCheckbox: Locator;

constructor(page: Page, private stakeConfig: StakeConfig) {
this.page = page;
this.connectBtn = this.page.getByTestId('connectBtn');
this.stakeSubmitBtn = this.page.getByTestId('stakeSubmitBtn');
this.termsCheckbox = this.page.locator('input[type=checkbox]');
}

async navigate() {
Expand All @@ -37,43 +43,46 @@ export class EthereumPage implements WidgetPage {
}

async connectWallet(walletPage: WalletPage) {
await test.step(
'Connect wallet ' + walletPage.config.COMMON.WALLET_NAME,
async () => {
await this.page.waitForTimeout(2000);
const isConnected =
(await this.page.getByTestId('connectBtn').count()) === 0;
if (!isConnected) {
await this.page.getByTestId('connectBtn').first().click();
await this.page.waitForTimeout(2000);
if ((await this.page.getByTestId('stakeSubmitBtn').count()) === 0) {
if (!(await this.page.isChecked('input[type=checkbox]')))
await this.page.click('input[type=checkbox]', { force: true });
if (walletPage.config.COMMON.SIMPLE_CONNECT) {
await this.page.click(
`button[type=button] :text('${walletPage.config.COMMON.CONNECT_BUTTON_NAME}')`,
);
} else {
const [connectWalletPage] = await Promise.all([
this.page.context().waitForEvent('page', { timeout: 5000 }),
this.page.dblclick(
`button[type=button] :text('${walletPage.config.COMMON.CONNECT_BUTTON_NAME}')`,
),
]);
await walletPage.connectWallet(connectWalletPage);
}
expect(
await this.page.waitForSelector('data-testid=stakeSubmitBtn'),
).not.toBeNaN();
await this.page.locator('data-testid=accountSectionHeader').click();
expect(
await this.page.textContent('div[data-testid="providerName"]'),
).toContain(walletPage.config.COMMON.CONNECTED_WALLET_NAME);
await this.page.locator('div[role="dialog"] button').nth(0).click();
}
}
},
);
await test.step(`Connect wallet ${walletPage.config.COMMON.WALLET_NAME}`, async () => {
await this.page.waitForTimeout(2000);
// If wallet connected -> return
if ((await this.connectBtn.count()) === 0) return;
await this.connectBtn.first().click();
await this.page.waitForTimeout(2000);
// If Stake submit button is displayed -> return
if ((await this.stakeSubmitBtn.count()) > 0) return;

if (!(await this.termsCheckbox.isChecked()))
await this.termsCheckbox.click({ force: true });

const walletButton = this.page
.getByRole('button')
.getByText(walletPage.config.COMMON.CONNECT_BUTTON_NAME, {
exact: true,
});

if (
(await walletButton.isEnabled({ timeout: 1000 })) &&
walletPage.config.COMMON.SIMPLE_CONNECT
) {
await walletButton.click();
} else {
const [connectWalletPage] = await Promise.all([
this.page.context().waitForEvent('page', { timeout: 5000 }),

Check failure on line 71 in packages/widgets/src/ethereum/ethereum.page.ts

View workflow job for this annotation

GitHub Actions / Testing

../../test/widgets/ethereum.spec.ts:53:7 › Ethereum › Trust connect

1) ../../test/widgets/ethereum.spec.ts:53:7 › Ethereum › Trust connect › Connect wallet trust ──── TimeoutError: browserContext.waitForEvent: Timeout 5000ms exceeded while waiting for event "page" at ../../../packages/widgets/src/ethereum/ethereum.page.ts:71 69 | } else { 70 | const [connectWalletPage] = await Promise.all([ > 71 | this.page.context().waitForEvent('page', { timeout: 5000 }), | ^ 72 | walletButton.dblclick(), 73 | ]); 74 | await walletPage.connectWallet(connectWalletPage); at /home/runner/work/wallets-testing-modules/wallets-testing-modules/packages/widgets/src/ethereum/ethereum.page.ts:71:31 at EthereumPage.connectWallet (/home/runner/work/wallets-testing-modules/wallets-testing-modules/packages/widgets/src/ethereum/ethereum.page.ts:46:5) at BrowserService.connectWallet (/home/runner/work/wallets-testing-modules/wallets-testing-modules/wallets-testing/browser/browser.service.ts:128:5) at /home/runner/work/wallets-testing-modules/wallets-testing-modules/wallets-testing/test/widgets/ethereum.spec.ts:58:5

Check failure on line 71 in packages/widgets/src/ethereum/ethereum.page.ts

View workflow job for this annotation

GitHub Actions / Testing

../../test/widgets/ethereum.spec.ts:53:7 › Ethereum › Trust connect

1) ../../test/widgets/ethereum.spec.ts:53:7 › Ethereum › Trust connect › Connect wallet trust ──── Retry #1 ─────────────────────────────────────────────────────────────────────────────────────── TimeoutError: browserContext.waitForEvent: Timeout 5000ms exceeded while waiting for event "page" at ../../../packages/widgets/src/ethereum/ethereum.page.ts:71 69 | } else { 70 | const [connectWalletPage] = await Promise.all([ > 71 | this.page.context().waitForEvent('page', { timeout: 5000 }), | ^ 72 | walletButton.dblclick(), 73 | ]); 74 | await walletPage.connectWallet(connectWalletPage); at /home/runner/work/wallets-testing-modules/wallets-testing-modules/packages/widgets/src/ethereum/ethereum.page.ts:71:31 at EthereumPage.connectWallet (/home/runner/work/wallets-testing-modules/wallets-testing-modules/packages/widgets/src/ethereum/ethereum.page.ts:46:5) at BrowserService.connectWallet (/home/runner/work/wallets-testing-modules/wallets-testing-modules/wallets-testing/browser/browser.service.ts:128:5) at /home/runner/work/wallets-testing-modules/wallets-testing-modules/wallets-testing/test/widgets/ethereum.spec.ts:58:5

Check failure on line 71 in packages/widgets/src/ethereum/ethereum.page.ts

View workflow job for this annotation

GitHub Actions / Testing

../../test/widgets/ethereum.spec.ts:53:7 › Ethereum › Trust connect

1) ../../test/widgets/ethereum.spec.ts:53:7 › Ethereum › Trust connect › Connect wallet trust ──── Retry #2 ─────────────────────────────────────────────────────────────────────────────────────── TimeoutError: browserContext.waitForEvent: Timeout 5000ms exceeded while waiting for event "page" at ../../../packages/widgets/src/ethereum/ethereum.page.ts:71 69 | } else { 70 | const [connectWalletPage] = await Promise.all([ > 71 | this.page.context().waitForEvent('page', { timeout: 5000 }), | ^ 72 | walletButton.dblclick(), 73 | ]); 74 | await walletPage.connectWallet(connectWalletPage); at /home/runner/work/wallets-testing-modules/wallets-testing-modules/packages/widgets/src/ethereum/ethereum.page.ts:71:31 at EthereumPage.connectWallet (/home/runner/work/wallets-testing-modules/wallets-testing-modules/packages/widgets/src/ethereum/ethereum.page.ts:46:5) at BrowserService.connectWallet (/home/runner/work/wallets-testing-modules/wallets-testing-modules/wallets-testing/browser/browser.service.ts:128:5) at /home/runner/work/wallets-testing-modules/wallets-testing-modules/wallets-testing/test/widgets/ethereum.spec.ts:58:5

Check failure on line 71 in packages/widgets/src/ethereum/ethereum.page.ts

View workflow job for this annotation

GitHub Actions / Testing

../../test/widgets/ethereum.spec.ts:53:7 › Ethereum › Trust connect

1) ../../test/widgets/ethereum.spec.ts:53:7 › Ethereum › Trust connect › Connect wallet trust ──── TimeoutError: browserContext.waitForEvent: Timeout 5000ms exceeded while waiting for event "page" at ../../../packages/widgets/src/ethereum/ethereum.page.ts:71 69 | } else { 70 | const [connectWalletPage] = await Promise.all([ > 71 | this.page.context().waitForEvent('page', { timeout: 5000 }), | ^ 72 | walletButton.dblclick(), 73 | ]); 74 | await walletPage.connectWallet(connectWalletPage); at /home/runner/work/wallets-testing-modules/wallets-testing-modules/packages/widgets/src/ethereum/ethereum.page.ts:71:31 at EthereumPage.connectWallet (/home/runner/work/wallets-testing-modules/wallets-testing-modules/packages/widgets/src/ethereum/ethereum.page.ts:46:5) at BrowserService.connectWallet (/home/runner/work/wallets-testing-modules/wallets-testing-modules/wallets-testing/browser/browser.service.ts:128:5) at /home/runner/work/wallets-testing-modules/wallets-testing-modules/wallets-testing/test/widgets/ethereum.spec.ts:58:5

Check failure on line 71 in packages/widgets/src/ethereum/ethereum.page.ts

View workflow job for this annotation

GitHub Actions / Testing

../../test/widgets/ethereum.spec.ts:53:7 › Ethereum › Trust connect

1) ../../test/widgets/ethereum.spec.ts:53:7 › Ethereum › Trust connect › Connect wallet trust ──── Retry #1 ─────────────────────────────────────────────────────────────────────────────────────── TimeoutError: browserContext.waitForEvent: Timeout 5000ms exceeded while waiting for event "page" at ../../../packages/widgets/src/ethereum/ethereum.page.ts:71 69 | } else { 70 | const [connectWalletPage] = await Promise.all([ > 71 | this.page.context().waitForEvent('page', { timeout: 5000 }), | ^ 72 | walletButton.dblclick(), 73 | ]); 74 | await walletPage.connectWallet(connectWalletPage); at /home/runner/work/wallets-testing-modules/wallets-testing-modules/packages/widgets/src/ethereum/ethereum.page.ts:71:31 at EthereumPage.connectWallet (/home/runner/work/wallets-testing-modules/wallets-testing-modules/packages/widgets/src/ethereum/ethereum.page.ts:46:5) at BrowserService.connectWallet (/home/runner/work/wallets-testing-modules/wallets-testing-modules/wallets-testing/browser/browser.service.ts:128:5) at /home/runner/work/wallets-testing-modules/wallets-testing-modules/wallets-testing/test/widgets/ethereum.spec.ts:58:5

Check failure on line 71 in packages/widgets/src/ethereum/ethereum.page.ts

View workflow job for this annotation

GitHub Actions / Testing

../../test/widgets/ethereum.spec.ts:53:7 › Ethereum › Trust connect

1) ../../test/widgets/ethereum.spec.ts:53:7 › Ethereum › Trust connect › Connect wallet trust ──── Retry #2 ─────────────────────────────────────────────────────────────────────────────────────── TimeoutError: browserContext.waitForEvent: Timeout 5000ms exceeded while waiting for event "page" at ../../../packages/widgets/src/ethereum/ethereum.page.ts:71 69 | } else { 70 | const [connectWalletPage] = await Promise.all([ > 71 | this.page.context().waitForEvent('page', { timeout: 5000 }), | ^ 72 | walletButton.dblclick(), 73 | ]); 74 | await walletPage.connectWallet(connectWalletPage); at /home/runner/work/wallets-testing-modules/wallets-testing-modules/packages/widgets/src/ethereum/ethereum.page.ts:71:31 at EthereumPage.connectWallet (/home/runner/work/wallets-testing-modules/wallets-testing-modules/packages/widgets/src/ethereum/ethereum.page.ts:46:5) at BrowserService.connectWallet (/home/runner/work/wallets-testing-modules/wallets-testing-modules/wallets-testing/browser/browser.service.ts:128:5) at /home/runner/work/wallets-testing-modules/wallets-testing-modules/wallets-testing/test/widgets/ethereum.spec.ts:58:5
walletButton.dblclick(),
]);
await walletPage.connectWallet(connectWalletPage);
}

expect(
await this.page.waitForSelector('data-testid=stakeSubmitBtn'),
).not.toBeNaN();
await this.page.locator('data-testid=accountSectionHeader').click();
expect(
await this.page.textContent('div[data-testid="providerName"]'),
).toContain(walletPage.config.COMMON.CONNECTED_WALLET_NAME);
await this.page.locator('div[role="dialog"] button').nth(0).click();
});
}

async doStaking(walletPage: WalletPage) {
Expand Down

0 comments on commit be8fd83

Please sign in to comment.