mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-11-22 01:47:00 +01:00
Reduce e2e test flakiness (#19507)
Three e2e tests have been updated to fix a possible race condition causing intermittent e2e test failures. In each of the updated tests, the test checks the current network. The check is performed as a two-step process: locate the current network element, then check the text to ensure it's correct. This fails when the test driver finds the element before it re-renders. If the test runs too quickly, it compares the text before the switch is shown on screen, and the test fails. Instead the tests use the element locator to describe what they want. This tells the test driver to keep looking until the conditions are met, ensuring the test doesn't fail unless the network switch takes longer than the default timeout (which should not happen). This is a good example of why we should avoid using assertions on elements in e2e tests. Express your assertions as locators instead to make the test more resilient in the case where the test runs before the next render.
This commit is contained in:
parent
f5b158dda6
commit
96c00df6f0
@ -55,10 +55,10 @@ describe('Chain Interactions', function () {
|
||||
await driver.switchToWindow(extension);
|
||||
|
||||
// verify networks
|
||||
const networkDisplay = await driver.findElement(
|
||||
'[data-testid="network-display"] p',
|
||||
);
|
||||
assert.equal(await networkDisplay.getText(), 'Localhost 8545');
|
||||
await driver.findElement({
|
||||
css: '[data-testid="network-display"]',
|
||||
text: 'Localhost 8545',
|
||||
});
|
||||
|
||||
await driver.clickElement('[data-testid="network-display"]');
|
||||
const ganacheChain = await driver.findElements({
|
||||
@ -103,10 +103,10 @@ describe('Chain Interactions', function () {
|
||||
await driver.switchToWindow(extension);
|
||||
|
||||
// verify current network
|
||||
const networkDisplay = await driver.findElement(
|
||||
'[data-testid="network-display"] p',
|
||||
);
|
||||
assert.equal(await networkDisplay.getText(), `Localhost ${port}`);
|
||||
await driver.findElement({
|
||||
css: '[data-testid="network-display"]',
|
||||
text: `Localhost ${port}`,
|
||||
});
|
||||
},
|
||||
);
|
||||
});
|
||||
|
@ -301,10 +301,10 @@ describe('MetaMask onboarding', function () {
|
||||
assert.equal(networkNotification, true);
|
||||
|
||||
// Check localhost 8546 is selected and its balance value is correct
|
||||
const networkDisplay = await driver.findElement(
|
||||
'[data-testid="network-display"] p',
|
||||
);
|
||||
assert.equal(await networkDisplay.getText(), networkName);
|
||||
await driver.findElement({
|
||||
css: '[data-testid="network-display"]',
|
||||
text: networkName,
|
||||
});
|
||||
|
||||
await assertAccountBalanceForDOM(driver, secondaryGanacheServer);
|
||||
},
|
||||
|
Loading…
Reference in New Issue
Block a user