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

fix: flaky anti-pattern getText + assert 2 #28043

Merged
merged 3 commits into from
Oct 24, 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
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { strict: assert } = require('assert');
const { By } = require('selenium-webdriver');
const FixtureBuilder = require('../../fixture-builder');
const {
withFixtures,
Expand All @@ -10,7 +10,6 @@ const {
WINDOW_TITLES,
defaultGanacheOptions,
largeDelayMs,
switchToNotificationWindow,
} = require('../../helpers');
const { PAGES } = require('../../webdriver/driver');

Expand Down Expand Up @@ -59,7 +58,7 @@ describe('Request Queuing for Multiple Dapps and Txs on same networks', function

await driver.delay(regularDelayMs);

await switchToNotificationWindow(driver);
await driver.switchToWindowWithTitle(WINDOW_TITLES.Dialog);

await driver.clickElement({
text: 'Connect',
Expand Down Expand Up @@ -98,7 +97,7 @@ describe('Request Queuing for Multiple Dapps and Txs on same networks', function

await driver.delay(regularDelayMs);

await switchToNotificationWindow(driver, 4);
await driver.switchToWindowWithTitle(WINDOW_TITLES.Dialog);

await driver.clickElement({
text: 'Connect',
Expand Down Expand Up @@ -134,16 +133,12 @@ describe('Request Queuing for Multiple Dapps and Txs on same networks', function
await driver.clickElement('#sendButton');
await driver.clickElement('#sendButton');

await switchToNotificationWindow(driver, 4);
await driver.switchToWindowWithTitle(WINDOW_TITLES.Dialog);

let navigationElement = await driver.findElement(
'.confirm-page-container-navigation',
await driver.waitForSelector(
By.xpath("//div[normalize-space(.)='1 of 2']"),
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice job!

);

let navigationText = await navigationElement.getText();

assert.equal(navigationText.includes('1 of 2'), true);

// Check correct network on confirm tx.
await driver.findElement({
css: '[data-testid="network-display"]',
Expand All @@ -162,14 +157,10 @@ describe('Request Queuing for Multiple Dapps and Txs on same networks', function
await driver.delay(largeDelayMs);
await driver.switchToWindowWithTitle(WINDOW_TITLES.Dialog);

navigationElement = await driver.findElement(
'.confirm-page-container-navigation',
await driver.waitForSelector(
By.xpath("//div[normalize-space(.)='1 of 2']"),
);

navigationText = await navigationElement.getText();

assert.equal(navigationText.includes('1 of 2'), true);

// Check correct network on confirm tx.
await driver.findElement({
css: '[data-testid="network-display"]',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ const {
DAPP_URL,
regularDelayMs,
WINDOW_TITLES,
switchToNotificationWindow,
defaultGanacheOptions,
} = require('../../helpers');

Expand Down Expand Up @@ -45,31 +44,25 @@ describe('Request Queue WatchAsset -> SwitchChain -> WatchAsset', function () {

// Create Token
await driver.clickElement({ text: 'Create Token', tag: 'button' });
await switchToNotificationWindow(driver);
await driver.findClickableElement({ text: 'Confirm', tag: 'button' });
await driver.switchToWindowWithTitle(WINDOW_TITLES.Dialog);
await driver.clickElement({ text: 'Confirm', tag: 'button' });

// Wait for token address to populate in dapp
await driver.switchToWindowWithTitle(WINDOW_TITLES.TestDApp);
await driver.wait(async () => {
const tokenAddressesElement = await driver.findElement(
'#tokenAddresses',
);
const tokenAddresses = await tokenAddressesElement.getText();
return tokenAddresses !== '';
}, 10000);
await driver.waitForSelector({
css: '#tokenAddresses',
text: '0x581c3C1A2A4EBDE2A0Df29B5cf4c116E42945947',
});

// Watch Asset 1st call
await driver.clickElement({
text: 'Add Token(s) to Wallet',
tag: 'button',
});

await driver.waitUntilXWindowHandles(3);
await driver.switchToWindowWithTitle(WINDOW_TITLES.TestDApp);

// Switch Ethereum Chain
await driver.findClickableElement('#switchEthereumChain');
await driver.clickElement('#switchEthereumChain');

await driver.switchToWindowWithTitle(WINDOW_TITLES.TestDApp);
Expand All @@ -83,7 +76,7 @@ describe('Request Queue WatchAsset -> SwitchChain -> WatchAsset', function () {
// Wait for token to show in list of tokens to watch
await driver.delay(regularDelayMs);

await switchToNotificationWindow(driver);
await driver.switchToWindowWithTitle(WINDOW_TITLES.Dialog);

const multipleSuggestedtokens = await driver.findElements(
'.confirm-add-suggested-token__token-list-item',
Expand All @@ -92,7 +85,7 @@ describe('Request Queue WatchAsset -> SwitchChain -> WatchAsset', function () {
// Confirm only 1 token is present in suggested token list
assert.equal(multipleSuggestedtokens.length, 1);

await switchToNotificationWindow(driver);
await driver.switchToWindowWithTitle(WINDOW_TITLES.Dialog);

await driver.waitUntilXWindowHandles(2);

Expand Down
21 changes: 12 additions & 9 deletions test/e2e/tests/responsive-ui/metamask-responsive-ui.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,10 @@ describe('MetaMask Responsive UI', function () {
await driver.clickElement('[data-testid="pin-extension-done"]');
await driver.assertElementNotPresent('.loading-overlay__spinner');
// assert balance
const balance = await driver.findElement(
'[data-testid="eth-overview__primary-currency"]',
);
assert.ok(/^0\sETH$/u.test(await balance.getText()));
await driver.waitForSelector({
css: '[data-testid="eth-overview__primary-currency"]',
text: '0',
});
},
);
});
Expand All @@ -93,11 +93,14 @@ describe('MetaMask Responsive UI', function () {
await driver.navigate();

// Import Secret Recovery Phrase
const restoreSeedLink = await driver.findClickableElement(
'.unlock-page__link',
);
assert.equal(await restoreSeedLink.getText(), 'Forgot password?');
await restoreSeedLink.click();
await driver.waitForSelector({
tag: 'span',
text: 'Localhost 8545',
});
await driver.clickElement({
css: '.unlock-page__link',
text: 'Forgot password?',
});

await driver.pasteIntoField(
'[data-testid="import-srp__srp-word-0"]',
Expand Down
13 changes: 4 additions & 9 deletions test/e2e/tests/settings/about-metamask-ui-validation.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,16 +68,11 @@ describe('Setting - About MetaMask : @no-mmi', function (this: Suite) {
);

// verify the version number of the MetaMask
const metaMaskVersion = await driver.findElement(
selectors.metaMaskVersion,
);
const getVersionNumber = await metaMaskVersion.getText();
const { version } = packageJson;
assert.equal(
getVersionNumber,
version,
'Meta Mask version is incorrect in the about view section',
);
await driver.waitForSelector({
css: selectors.metaMaskVersion,
text: version,
});

// Validating the header text
const isHeaderTextPresent = await driver.isElementPresent(
Expand Down
29 changes: 9 additions & 20 deletions test/e2e/tests/settings/address-book.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,11 @@ describe('Address Book', function () {

await driver.clickElement({ css: 'button', text: 'Contacts' });

const recipientTitle = await driver.findElement(
'.address-list-item__label',
);
await driver.waitForSelector({
css: '.address-list-item__label',
text: 'Test Name 1',
});

const recipientRowTitleString = await recipientTitle.getText();
assert.equal(recipientRowTitleString, 'Test Name 1');
await driver.clickElement('.address-list-item__label');

await driver.fill('input[placeholder="0"]', '2');
Expand Down Expand Up @@ -111,25 +110,15 @@ describe('Address Book', function () {

await driver.clickElement('[data-testid="page-container-footer-next"]');

const recipientUsername = await driver.findElement({
await driver.waitForSelector({
text: 'Test Name Edit',
css: '.address-list-item__label',
});

assert.equal(
await recipientUsername.getText(),
'Test Name Edit',
'Username is not edited correctly',
);

const recipientAddress = await driver.findElement(
'[data-testid="address-list-item-address"]',
);
assert.equal(
await recipientAddress.getText(),
shortenAddress('0x74cE91B75935D6Bedc27eE002DeFa566c5946f74'),
'Recipient address is not edited correctly',
);
await driver.waitForSelector({
css: '[data-testid="address-list-item-address"]',
text: shortenAddress('0x74cE91B75935D6Bedc27eE002DeFa566c5946f74'),
});
},
);
});
Expand Down