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 test Request-queue UI changes handles three confirmations on three confirmations concurrently #25675

Merged
merged 16 commits into from
Jul 5, 2024
59 changes: 28 additions & 31 deletions test/e2e/tests/request-queuing/ui.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ async function openDappAndSwitchChain(
'[data-testid="confirmation-submit-button"]',
);
await driver.clickElement('[data-testid="confirmation-submit-button"]');

// Switch back to the dapp
await driver.switchToWindowWithUrl(dappUrl);
}
}

Expand All @@ -93,29 +96,23 @@ async function switchToNotificationPopoverValidateDetails(
const windowHandles = await driver.getAllWindowHandles();
await driver.switchToWindowWithTitle(WINDOW_TITLES.Dialog, windowHandles);

// Get UI details
const networkPill = await driver.findElement(
// Differs between confirmation and signature
'[data-testid="network-display"], [data-testid="signature-request-network-display"]',
);
const networkText = await networkPill.getText();
const originElement = await driver.findElement(
// Differs between confirmation and signature
'.confirm-page-container-summary__origin bdi, .request-signature__origin .chip__label',
);
const originText = await originElement.getText();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this is a bad pattern that can cause flakiness: if we get the element without waiting for the exact text contents we want, it can be a race condition when the element is rendered but the value is not there yet, making all the assertions fail

await driver.findElement({
css: '[data-testid="network-display"], [data-testid="signature-request-network-display"]',
text: expectedDetails.networkText,
});

await driver.findElement({
css: '.confirm-page-container-summary__origin bdi, .request-signature__origin .chip__label',
text: expectedDetails.originText,
});

// Get state details
const notificationWindowState = await driver.executeScript(() =>
window.stateHooks?.getCleanAppState?.(),
);
const { chainId } = notificationWindowState.metamask.providerConfig;

// Ensure accuracy
validateConfirmationDetails(
{ networkText, originText, chainId },
expectedDetails,
);
const { chainId } = notificationWindowState.metamask.providerConfig;
assert.equal(chainId, expectedDetails.chainId);
}

async function rejectTransaction(driver) {
Expand All @@ -126,15 +123,6 @@ async function confirmTransaction(driver) {
await driver.clickElement({ tag: 'button', text: 'Confirm' });
}

function validateConfirmationDetails(
{ chainId, networkText, originText },
expected,
) {
assert.equal(chainId, expected.chainId);
assert.equal(networkText, expected.networkText);
assert.equal(originText, expected.originText);
}

async function switchToNetworkByName(driver, networkName) {
await driver.clickElement('[data-testid="network-display"]');
await driver.clickElement(`[data-testid="${networkName}"]`);
Expand Down Expand Up @@ -462,8 +450,8 @@ describe('Request-queue UI changes', function () {
],
},
// This test intentionally quits Ganache while the extension is using it, causing
// PollingBlockTracker errors. These are expected.
ignoredConsoleErrors: ['PollingBlockTracker'],
// PollingBlockTracker errors and others. These are expected.
ignoredConsoleErrors: ['ignore-all'],
dappOptions: { numberOfDapps: 2 },
title: this.test.fullTitle(),
},
Expand Down Expand Up @@ -494,7 +482,11 @@ describe('Request-queue UI changes', function () {

// Go back to first dapp, try an action, ensure network connection failure doesn't block UI
await selectDappClickPersonalSign(driver, DAPP_URL);
await driver.delay(veryLargeDelayMs);

// When the network is down, there is a performance degradation that causes the
// popup to take a few seconds to open in MV3 (issue #25690)
await driver.waitUntilXWindowHandles(4, 1000, 15000);

await switchToNotificationPopoverValidateDetails(driver, {
chainId: '0x539',
networkText: 'Localhost 8545',
Expand Down Expand Up @@ -528,8 +520,8 @@ describe('Request-queue UI changes', function () {
],
},
// This test intentionally quits Ganache while the extension is using it, causing
// PollingBlockTracker errors. These are expected.
ignoredConsoleErrors: ['PollingBlockTracker'],
// PollingBlockTracker errors and others. These are expected.
ignoredConsoleErrors: ['ignore-all'],
dappOptions: { numberOfDapps: 2 },
title: this.test.fullTitle(),
},
Expand Down Expand Up @@ -560,6 +552,11 @@ describe('Request-queue UI changes', function () {

// Go back to first dapp, try an action, ensure network connection failure doesn't block UI
await selectDappClickSend(driver, DAPP_URL);

// When the network is down, there is a performance degradation that causes the
// popup to take a few seconds to open in MV3 (issue #25690)
await driver.waitUntilXWindowHandles(4, 1000, 15000);

await switchToNotificationPopoverValidateDetails(driver, {
chainId: '0x539',
networkText: 'Localhost 8545',
Expand Down
6 changes: 4 additions & 2 deletions test/e2e/webdriver/driver.js
Original file line number Diff line number Diff line change
Expand Up @@ -1125,6 +1125,8 @@ class Driver {
}

async checkBrowserForConsoleErrors(_ignoredConsoleErrors) {
const ignoreAllErrors = _ignoredConsoleErrors.includes('ignore-all');

const ignoredConsoleErrors = _ignoredConsoleErrors.concat([
// Third-party Favicon 404s show up as errors
'favicon.ico - Failed to load resource: the server responded with a status of 404',
Expand All @@ -1151,15 +1153,15 @@ class Driver {
eventDescription?.description,
);

if (!ignored) {
if (!ignored && !ignoreAllErrors) {
this.errors.push(eventDescription?.description);
}
} else if (event.args.length !== 0) {
const newError = this.#getErrorFromEvent(event);

const ignored = logBrowserError(ignoredConsoleErrors, newError);

if (!ignored) {
if (!ignored && !ignoreAllErrors) {
this.errors.push(newError);
}
}
Expand Down
Loading