From f10775f55d7b5b60fe5a7b5e06824dad14f0cb6b Mon Sep 17 00:00:00 2001 From: Danica Shen Date: Tue, 20 Jun 2023 14:45:40 +0100 Subject: [PATCH] feature(19625): eliminate e2e flakyness for add-account and send-eth (#19645) * feature(19625): eliminate e2e flakyness for add-account and send-eth * feature(19625): remove await delay in send-eth --- test/e2e/helpers.js | 10 ++-- test/e2e/tests/add-account.spec.js | 80 ++++++++++++------------------ test/e2e/tests/send-eth.spec.js | 6 +-- 3 files changed, 38 insertions(+), 58 deletions(-) diff --git a/test/e2e/helpers.js b/test/e2e/helpers.js index 51d333062..e66f5fbda 100644 --- a/test/e2e/helpers.js +++ b/test/e2e/helpers.js @@ -500,10 +500,12 @@ const findAnotherAccountFromAccountList = async ( ) => { await driver.clickElement('[data-testid="account-menu-icon"]'); const accountMenuItemSelector = `.multichain-account-list-item:nth-child(${itemNumber})`; - const acctName = await driver.findElement( - `${accountMenuItemSelector} .multichain-account-list-item__account-name__button`, - ); - assert.equal(await acctName.getText(), accountName); + + await driver.findElement({ + css: `${accountMenuItemSelector} .multichain-account-list-item__account-name__button`, + text: accountName, + }); + return accountMenuItemSelector; }; diff --git a/test/e2e/tests/add-account.spec.js b/test/e2e/tests/add-account.spec.js index 5c04094a3..31131647d 100644 --- a/test/e2e/tests/add-account.spec.js +++ b/test/e2e/tests/add-account.spec.js @@ -8,6 +8,7 @@ const { waitForAccountRendered, convertToHexValue, regularDelayMs, + login, } = require('../helpers'); const FixtureBuilder = require('../fixture-builder'); @@ -37,8 +38,7 @@ describe('Add account', function () { }, async ({ driver }) => { await driver.navigate(); - await driver.fill('#password', 'correct horse battery staple'); - await driver.press('#password', driver.Key.ENTER); + await login(driver); await driver.clickElement('[data-testid="account-menu-icon"]'); await driver.clickElement( @@ -47,11 +47,10 @@ describe('Add account', function () { await driver.fill('[placeholder="Account 2"]', '2nd account'); await driver.clickElement({ text: 'Create', tag: 'button' }); - const accountName = await driver.waitForSelector({ + await driver.findElement({ css: '[data-testid="account-menu-icon"]', - text: '2nd', + text: '2nd account', }); - assert.equal(await accountName.getText(), '2nd account'); }, ); }); @@ -76,10 +75,10 @@ describe('Add account', function () { // Check address of 1st account await waitForAccountRendered(driver); - const firstAccountPublicAddress = await retrieveShortenAccountAddress( - driver, - ); - assert.equal(firstAccountPublicAddress, shortenAddress(firstAccount)); + await driver.findElement({ + css: '.multichain-address-copy-button', + text: shortenAddress(firstAccount), + }); // Create 2nd account await driver.clickElement('[data-testid="account-menu-icon"]'); @@ -91,13 +90,11 @@ describe('Add account', function () { await waitForAccountRendered(driver); // Check address of 2nd account - const secondAccountPublicAddress = await retrieveShortenAccountAddress( - driver, - ); - assert.strictEqual( - secondAccountPublicAddress, - shortenAddress(secondAccount), - ); + await waitForAccountRendered(driver); + await driver.findElement({ + css: '.multichain-address-copy-button', + text: shortenAddress(secondAccount), + }); // Log into the account with balance(account 1) // and transfer some balance to 2nd account @@ -143,12 +140,10 @@ describe('Add account', function () { await waitForAccountRendered(driver); // Check address of 1st account - const restoredFirstAccountPublicAddress = - await retrieveShortenAccountAddress(driver); - assert.equal( - restoredFirstAccountPublicAddress, - shortenAddress(firstAccount), - ); + await driver.findElement({ + css: '.multichain-address-copy-button', + text: shortenAddress(firstAccount), + }); // Check address of 2nd account const accountTwoSelector = await findAnotherAccountFromAccountList( @@ -158,17 +153,15 @@ describe('Add account', function () { ); await driver.clickElement(accountTwoSelector); - const restoredSecondAccountPublicAddress = - await retrieveShortenAccountAddress(driver); - assert.equal( - restoredSecondAccountPublicAddress, - shortenAddress(secondAccount), - ); + await driver.findElement({ + css: '.multichain-address-copy-button', + text: shortenAddress(secondAccount), + }); }, ); }); - it('It should be possible to remove an account imported with a private key, but should not be possible to remove an account generated from the SRP imported in onboarding', async function () { + it('should be possible to remove an account imported with a private key, but should not be possible to remove an account generated from the SRP imported in onboarding', async function () { const testPrivateKey = '14abe6f4aab7f9f626fe981c864d0adeb5685f289ac9270c27b8fd790b4235d6'; @@ -180,10 +173,7 @@ describe('Add account', function () { }, async ({ driver }) => { await driver.navigate(); - await driver.fill('#password', 'correct horse battery staple'); - await driver.press('#password', driver.Key.ENTER); - - await waitForAccountRendered(driver); + await login(driver); await driver.clickElement('[data-testid="account-menu-icon"]'); @@ -195,10 +185,10 @@ describe('Add account', function () { // Wait for 2nd account to be created await waitForAccountRendered(driver); - const secondAccountCreated = await driver.findElement( - '[data-testid="account-menu-icon"]', - ); - assert.equal(await secondAccountCreated.getText(), '2nd account'); + await driver.findElement({ + css: '[data-testid="account-menu-icon"]', + text: '2nd account', + }); await driver.clickElement('[data-testid="account-menu-icon"]'); @@ -226,10 +216,10 @@ describe('Add account', function () { // Wait for 3rd account to be created await waitForAccountRendered(driver); - const thirdAccountCreated = await driver.findElement( - '[data-testid="account-menu-icon"]', - ); - assert.equal(await thirdAccountCreated.getText(), 'Account 3'); + await driver.findElement({ + css: '[data-testid="account-menu-icon"]', + text: 'Account 3', + }); // User can delete 3rd account imported with a private key await driver.clickElement('[data-testid="account-menu-icon"]'); @@ -245,11 +235,3 @@ describe('Add account', function () { ); }); }); - -async function retrieveShortenAccountAddress(driver) { - // get the shorten public address for account - const accountDOM = await driver.waitForSelector( - '.multichain-address-copy-button', - ); - return await accountDOM.getText(); -} diff --git a/test/e2e/tests/send-eth.spec.js b/test/e2e/tests/send-eth.spec.js index 81a330085..64bdaace0 100644 --- a/test/e2e/tests/send-eth.spec.js +++ b/test/e2e/tests/send-eth.spec.js @@ -412,8 +412,7 @@ describe('Send ETH from inside MetaMask to a Multisig Address', function () { smartContract, ); await driver.navigate(); - await driver.fill('#password', 'correct horse battery staple'); - await driver.press('#password', driver.Key.ENTER); + await logInWithBalanceValidation(driver, ganacheServer); await driver.clickElement('[data-testid="eth-overview-send"]'); @@ -426,10 +425,7 @@ describe('Send ETH from inside MetaMask to a Multisig Address', function () { await inputAmount.fill('1'); // Continue to next screen - await driver.findClickableElement({ text: 'Next', tag: 'button' }); await driver.clickElement({ text: 'Next', tag: 'button' }); - - await driver.findClickableElement({ text: 'Confirm', tag: 'button' }); await driver.clickElement({ text: 'Confirm', tag: 'button' }); // Go back to home screen to check txn