Skip to content

Commit

Permalink
chore
Browse files Browse the repository at this point in the history
  • Loading branch information
LuizAsFight committed Oct 31, 2024
1 parent e723d81 commit 16fee37
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 18 deletions.
21 changes: 20 additions & 1 deletion packages/playwright-utils/src/playwright-utils/button.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { Page } from '@playwright/test';
import type { Locator, Page } from '@playwright/test';
import { expect } from '../fixtures';

export function getButtonByText(
page: Page,
Expand All @@ -7,3 +8,21 @@ export function getButtonByText(
) {
return page.locator('button').getByText(selector, { exact });
}

export function expectButtonToBeEnabled(
button: Locator,
locatorOptions: {
message?: string;
timeout?: number;
intervals?: number[];
} = {}
) {
const { message, timeout, intervals } = locatorOptions;
return expect
.poll(async () => await button.isEnabled(), {
timeout: timeout ?? 7000,
intervals: intervals ?? [1000, 2000, 3000, 4000, 5000, 6000, 7000],
message: message ?? 'Button is not enabled',
})
.toBeTruthy();
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { expect } from '../fixtures';
import { FUEL_MNEMONIC, FUEL_WALLET_PASSWORD } from '../mocks';
import { shortAddress } from '../utils';

import { getButtonByText } from './button';
import { expectButtonToBeEnabled, getButtonByText } from './button';
import { getByAriaLabel } from './locator';
import { hasText } from './text';

Expand Down Expand Up @@ -268,32 +268,23 @@ export class FuelWalletTestHelper {
const addNetworkButton = getByAriaLabel(this.walletPage, 'Add network');
await addNetworkButton.click();

await expect
.poll(
() =>
hasText(this.walletPage, 'Cancel')
.then(() => true)
.catch(() => false),
{ timeout: 3000 }
)
.toBeTruthy();

const urlInput = getByAriaLabel(this.walletPage, 'Network url');
await urlInput.fill(providerUrl);
const chainIdLocator = getByAriaLabel(this.walletPage, 'Chain ID');
await chainIdLocator.fill(chainId.toString());

await getByAriaLabel(this.walletPage, 'Test connection').click();
const testConnectionButton = getByAriaLabel(
this.walletPage,
'Test connection'
);
await expectButtonToBeEnabled(testConnectionButton);
await testConnectionButton.click();

const addNewNetworkButton = getByAriaLabel(
this.walletPage,
'Add new network'
);
await expect
.poll(async () => await addNewNetworkButton.isEnabled(), {
timeout: 7000,
})
.toBeTruthy();
await expectButtonToBeEnabled(addNewNetworkButton);
await addNewNetworkButton.click();
}

Expand Down

0 comments on commit 16fee37

Please sign in to comment.