From ae1520db53e8281a79f7f6d257441bb6632e41b0 Mon Sep 17 00:00:00 2001 From: Alejandro Garcia Anglada Date: Tue, 17 Dec 2024 17:59:17 +0100 Subject: [PATCH 1/3] fix: remove network picker from non evm accounts (#29247) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## **Description** Removes the new network picker from the non-EVM accounts token list [![Open in GitHub Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/MetaMask/metamask-extension/pull/29247?quickstart=1) ## **Related issues** Fixes: ## **Manual testing steps** 1. Enable the Solana account via Settings > Experimental > Enable Solana account 2. Create a Solana account from the account-list menu ## **Screenshots/Recordings** ### **Before** Screenshot 2024-12-16 at 20 53 34 ### **After** Screenshot 2024-12-16 at 21 02 08 ## **Pre-merge author checklist** - [x] I've followed [MetaMask Contributor Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask Extension Coding Standards](https://github.com/MetaMask/metamask-extension/blob/main/.github/guidelines/CODING_GUIDELINES.md). - [x] I've completed the PR template to the best of my ability - [ ] I’ve included tests if applicable - [ ] I’ve documented my code using [JSDoc](https://jsdoc.app/) format if applicable - [x] I’ve applied the right labels on the PR (see [labeling guidelines](https://github.com/MetaMask/metamask-extension/blob/main/.github/guidelines/LABELING_GUIDELINES.md)). Not required for external contributors. ## **Pre-merge reviewer checklist** - [x] I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed). - [ ] I confirm that this PR addresses all acceptance criteria described in the ticket it closes and includes the necessary testing evidence such as recordings and or screenshots. --- .../asset-list-control-bar.tsx | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/ui/components/app/assets/asset-list/asset-list-control-bar/asset-list-control-bar.tsx b/ui/components/app/assets/asset-list/asset-list-control-bar/asset-list-control-bar.tsx index 348fd82fbdaa..c61815a9ab0a 100644 --- a/ui/components/app/assets/asset-list/asset-list-control-bar/asset-list-control-bar.tsx +++ b/ui/components/app/assets/asset-list/asset-list-control-bar/asset-list-control-bar.tsx @@ -3,6 +3,7 @@ import { useDispatch, useSelector } from 'react-redux'; import { getCurrentNetwork, getIsTokenNetworkFilterEqualCurrentNetwork, + getSelectedInternalAccount, getTokenNetworkFilter, } from '../../../../../selectors'; import { getNetworkConfigurationsByChainId } from '../../../../../../shared/modules/selectors/networks'; @@ -49,6 +50,8 @@ import { showImportTokensModal, } from '../../../../../store/actions'; import Tooltip from '../../../../ui/tooltip'; +import { useMultichainSelector } from '../../../../../hooks/useMultichainSelector'; +import { getMultichainNetwork } from '../../../../../selectors/multichain'; type AssetListControlBarProps = { showTokensLinks?: boolean; @@ -72,6 +75,9 @@ const AssetListControlBar = ({ showTokensLinks }: AssetListControlBarProps) => { const [isNetworkFilterPopoverOpen, setIsNetworkFilterPopoverOpen] = useState(false); + const account = useSelector(getSelectedInternalAccount); + const { isEvmNetwork } = useMultichainSelector(getMultichainNetwork, account); + const isTestNetwork = useMemo(() => { return (TEST_CHAINS as string[]).includes(currentNetwork.chainId); }, [currentNetwork.chainId, TEST_CHAINS]); @@ -166,12 +172,13 @@ const AssetListControlBar = ({ showTokensLinks }: AssetListControlBarProps) => { - {process.env.PORTFOLIO_VIEW && ( + {/* TODO: Remove isEvmNetwork check when we are ready to show the network filter in all networks including non-EVM */} + {process.env.PORTFOLIO_VIEW && isEvmNetwork ? ( { ? currentNetwork?.nickname ?? t('currentNetwork') : t('popularNetworks')} - )} + ) : null} Date: Tue, 17 Dec 2024 18:02:27 +0100 Subject: [PATCH 2/3] test: [POM] Create base classes and methods for bitcoin e2e tests (#29235) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## **Description** - Create a Bitcoin home page class and methods. The locators on homepage for Bitcoin accounts are different from the locators for other accounts. I think the best way to implement this is to create a `BitcoinHomepage` class that extends from `Homepage`. This approach will be flexible and easier to implement when we have new modifications for Bitcoin account functionalities. - Migrate bitcoin account e2e tests to TS and Page Object Model ``` test/e2e/flask/btc/btc-account-overview.spec.ts test/e2e/flask/btc/btc-dapp-connection.spec.ts test/e2e/flask/btc/btc-experimental-settings.spec.ts ``` [![Open in GitHub Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/MetaMask/metamask-extension/pull/27155?quickstart=1) ## **Related issues** ## **Manual testing steps** Check code readability, make sure tests pass. ## **Screenshots/Recordings** ### **Before** ### **After** ## **Pre-merge author checklist** - [x] I've followed [MetaMask Contributor Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask Extension Coding Standards](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/CODING_GUIDELINES.md). - [x] I've completed the PR template to the best of my ability - [x] I’ve included tests if applicable - [x] I’ve documented my code using [JSDoc](https://jsdoc.app/) format if applicable - [x] I’ve applied the right labels on the PR (see [labeling guidelines](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/LABELING_GUIDELINES.md)). Not required for external contributors. ## **Pre-merge reviewer checklist** - [x] I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed). - [x] I confirm that this PR addresses all acceptance criteria described in the ticket it closes and includes the necessary testing evidence such as recordings and or screenshots. --------- Co-authored-by: seaona <54408225+seaona@users.noreply.github.com> --- .../flask/btc/btc-account-overview.spec.ts | 63 ++-------- .../e2e/flask/btc/btc-dapp-connection.spec.ts | 19 +-- .../btc/btc-experimental-settings.spec.ts | 54 ++++----- .../page-objects/pages/account-list-page.ts | 16 +++ test/e2e/page-objects/pages/header-navbar.ts | 2 +- .../pages/home/bitcoin-homepage.ts | 112 ++++++++++++++++++ test/e2e/page-objects/pages/home/homepage.ts | 9 +- .../pages/settings/experimental-settings.ts | 13 ++ test/e2e/page-objects/pages/test-dapp.ts | 39 ++++-- ...account-signatures-and-disconnects.spec.ts | 4 +- .../multichain/all-permissions-page.spec.ts | 4 +- .../tokens/custom-token-send-transfer.spec.js | 48 +++----- test/e2e/webdriver/driver.js | 14 ++- 13 files changed, 253 insertions(+), 144 deletions(-) create mode 100644 test/e2e/page-objects/pages/home/bitcoin-homepage.ts diff --git a/test/e2e/flask/btc/btc-account-overview.spec.ts b/test/e2e/flask/btc/btc-account-overview.spec.ts index 418c9d736078..93ff6ef07ad3 100644 --- a/test/e2e/flask/btc/btc-account-overview.spec.ts +++ b/test/e2e/flask/btc/btc-account-overview.spec.ts @@ -1,63 +1,24 @@ +import { strict as assert } from 'assert'; import { Suite } from 'mocha'; import { DEFAULT_BTC_BALANCE } from '../../constants'; +import BitcoinHomepage from '../../page-objects/pages/home/bitcoin-homepage'; import { withBtcAccountSnap } from './common-btc'; describe('BTC Account - Overview', function (this: Suite) { - it('has portfolio button enabled for BTC accounts', async function () { + it('has balance displayed and has portfolio button enabled for BTC accounts', async function () { await withBtcAccountSnap( { title: this.test?.fullTitle() }, async (driver) => { - await driver.findElement({ - css: '[data-testid="account-menu-icon"]', - text: 'Bitcoin Account', - }); - - await driver.waitForSelector({ - text: 'Send', - tag: 'button', - css: '[data-testid="coin-overview-send"]', - }); - - await driver.waitForSelector({ - text: 'Swap', - tag: 'button', - css: '[disabled]', - }); - - await driver.waitForSelector({ - text: 'Bridge', - tag: 'button', - css: '[disabled]', - }); - - // buy sell button - await driver.findClickableElement('[data-testid="coin-overview-buy"]'); - - // receive button - await driver.findClickableElement( - '[data-testid="coin-overview-receive"]', + const homePage = new BitcoinHomepage(driver); + await homePage.check_pageIsLoaded(); + await homePage.headerNavbar.check_accountLabel('Bitcoin Account'); + await homePage.check_isExpectedBitcoinBalanceDisplayed( + DEFAULT_BTC_BALANCE, ); - }, - ); - }); - - it('has balance', async function () { - await withBtcAccountSnap( - { title: this.test?.fullTitle() }, - async (driver) => { - await driver.waitForSelector({ - testId: 'account-value-and-suffix', - text: `${DEFAULT_BTC_BALANCE}`, - }); - await driver.waitForSelector({ - css: '.currency-display-component__suffix', - text: 'BTC', - }); - - await driver.waitForSelector({ - tag: 'p', - text: `${DEFAULT_BTC_BALANCE} BTC`, - }); + assert.equal(await homePage.check_isBridgeButtonEnabled(), false); + assert.equal(await homePage.check_isSwapButtonEnabled(), false); + assert.equal(await homePage.check_isBuySellButtonEnabled(), true); + assert.equal(await homePage.check_isReceiveButtonEnabled(), true); }, ); }); diff --git a/test/e2e/flask/btc/btc-dapp-connection.spec.ts b/test/e2e/flask/btc/btc-dapp-connection.spec.ts index 2eb33a4b7d74..2a9b413f60b0 100644 --- a/test/e2e/flask/btc/btc-dapp-connection.spec.ts +++ b/test/e2e/flask/btc/btc-dapp-connection.spec.ts @@ -1,5 +1,6 @@ import { Suite } from 'mocha'; -import { openDapp, WINDOW_TITLES } from '../../helpers'; +import BitcoinHomepage from '../../page-objects/pages/home/bitcoin-homepage'; +import TestDapp from '../../page-objects/pages/test-dapp'; import { withBtcAccountSnap } from './common-btc'; describe('BTC Account - Dapp Connection', function (this: Suite) { @@ -7,14 +8,16 @@ describe('BTC Account - Dapp Connection', function (this: Suite) { await withBtcAccountSnap( { title: this.test?.fullTitle() }, async (driver) => { - await openDapp(driver); - await driver.clickElement('#connectButton'); - await driver.waitUntilXWindowHandles(3); - await driver.switchToWindowWithTitle(WINDOW_TITLES.Dialog); + const homePage = new BitcoinHomepage(driver); + await homePage.check_pageIsLoaded(); + await homePage.headerNavbar.check_accountLabel('Bitcoin Account'); - await driver.assertElementNotPresent( - '[data-testid="choose-account-list-1"]', - ); + const testDapp = new TestDapp(driver); + await testDapp.openTestDappPage(); + await testDapp.check_pageIsLoaded(); + await testDapp.connectAccount({ + connectAccountButtonEnabled: false, + }); }, ); }); diff --git a/test/e2e/flask/btc/btc-experimental-settings.spec.ts b/test/e2e/flask/btc/btc-experimental-settings.spec.ts index 45bc7d0d1701..10a183bf87bb 100644 --- a/test/e2e/flask/btc/btc-experimental-settings.spec.ts +++ b/test/e2e/flask/btc/btc-experimental-settings.spec.ts @@ -1,47 +1,45 @@ import { Suite } from 'mocha'; - -import messages from '../../../../app/_locales/en/messages.json'; import FixtureBuilder from '../../fixture-builder'; -import { - defaultGanacheOptions, - unlockWallet, - withFixtures, -} from '../../helpers'; +import { withFixtures } from '../../helpers'; import { Driver } from '../../webdriver/driver'; +import AccountListPage from '../../page-objects/pages/account-list-page'; +import ExperimentalSettings from '../../page-objects/pages/settings/experimental-settings'; +import HomePage from '../../page-objects/pages/home/homepage'; +import HeaderNavbar from '../../page-objects/pages/header-navbar'; +import SettingsPage from '../../page-objects/pages/settings/settings-page'; +import { loginWithBalanceValidation } from '../../page-objects/flows/login.flow'; describe('BTC Experimental Settings', function (this: Suite) { it('will show `Add a new Bitcoin account (Beta)` option when setting is enabled', async function () { await withFixtures( { fixtures: new FixtureBuilder().build(), - ganacheOptions: defaultGanacheOptions, title: this.test?.fullTitle(), }, async ({ driver }: { driver: Driver }) => { - await unlockWallet(driver); - await driver.clickElement( - '[data-testid="account-options-menu-button"]', - ); - await driver.clickElement({ text: 'Settings', tag: 'div' }); - await driver.clickElement({ text: 'Experimental', tag: 'div' }); + await loginWithBalanceValidation(driver); - await driver.waitForSelector({ - text: messages.bitcoinSupportToggleTitle.message, - tag: 'span', - }); + // go to experimental settings page and enable add new Bitcoin account toggle + const homePage = new HomePage(driver); + await homePage.check_pageIsLoaded(); + await homePage.check_expectedBalanceIsDisplayed(); - await driver.clickElement('[data-testid="bitcoin-support-toggle-div"]'); + await new HeaderNavbar(driver).openSettingsPage(); + const settingsPage = new SettingsPage(driver); + await settingsPage.check_pageIsLoaded(); + await settingsPage.goToExperimentalSettings(); - await driver.clickElement('button[aria-label="Close"]'); + const experimentalSettings = new ExperimentalSettings(driver); + await experimentalSettings.check_pageIsLoaded(); + await experimentalSettings.toggleBitcoinAccount(); + await settingsPage.closeSettingsPage(); - await driver.clickElement('[data-testid="account-menu-icon"]'); - await driver.clickElement( - '[data-testid="multichain-account-menu-popover-action-button"]', - ); - await driver.waitForSelector({ - text: messages.addNewBitcoinAccount.message, - tag: 'button', - }); + // check add new Bitcoin account button is displayed + await homePage.check_pageIsLoaded(); + await new HeaderNavbar(driver).openAccountMenu(); + const accountListPage = new AccountListPage(driver); + await accountListPage.check_pageIsLoaded(); + await accountListPage.check_addBitcoinAccountAvailable(true); }, ); }); diff --git a/test/e2e/page-objects/pages/account-list-page.ts b/test/e2e/page-objects/pages/account-list-page.ts index 981955eb19cd..50eb70ce553c 100644 --- a/test/e2e/page-objects/pages/account-list-page.ts +++ b/test/e2e/page-objects/pages/account-list-page.ts @@ -374,6 +374,22 @@ class AccountListPage { }); } + async check_addBitcoinAccountAvailable( + expectedAvailability: boolean, + ): Promise { + console.log( + `Check add bitcoin account button is ${ + expectedAvailability ? 'displayed ' : 'not displayed' + }`, + ); + await this.openAddAccountModal(); + if (expectedAvailability) { + await this.driver.waitForSelector(this.addBtcAccountButton); + } else { + await this.driver.assertElementNotPresent(this.addBtcAccountButton); + } + } + async openAccountOptionsMenu(): Promise { console.log(`Open account option menu`); await this.driver.waitForSelector(this.accountListItem); diff --git a/test/e2e/page-objects/pages/header-navbar.ts b/test/e2e/page-objects/pages/header-navbar.ts index 65d4cbd48358..df45ecd0277d 100644 --- a/test/e2e/page-objects/pages/header-navbar.ts +++ b/test/e2e/page-objects/pages/header-navbar.ts @@ -1,7 +1,7 @@ import { Driver } from '../../webdriver/driver'; class HeaderNavbar { - private driver: Driver; + protected driver: Driver; private readonly accountMenuButton = '[data-testid="account-menu-icon"]'; diff --git a/test/e2e/page-objects/pages/home/bitcoin-homepage.ts b/test/e2e/page-objects/pages/home/bitcoin-homepage.ts new file mode 100644 index 000000000000..19b235636405 --- /dev/null +++ b/test/e2e/page-objects/pages/home/bitcoin-homepage.ts @@ -0,0 +1,112 @@ +import HomePage from './homepage'; + +class BitcoinHomepage extends HomePage { + protected readonly balance = + '[data-testid="coin-overview__primary-currency"]'; + + private readonly bridgeButton = { + text: 'Bridge', + tag: 'button', + }; + + private readonly buySellButton = '[data-testid="coin-overview-buy"]'; + + private readonly receiveButton = '[data-testid="coin-overview-receive"]'; + + protected readonly sendButton = '[data-testid="coin-overview-send"]'; + + private readonly swapButton = { + text: 'Swap', + tag: 'button', + }; + + async check_pageIsLoaded(): Promise { + try { + await this.driver.waitForMultipleSelectors([ + this.sendButton, + this.buySellButton, + this.receiveButton, + ]); + } catch (e) { + console.log('Timeout while waiting for bitcoin homepage to be loaded', e); + throw e; + } + console.log('Bitcoin homepage is loaded'); + } + + /** + * Checks if the bridge button is enabled on bitcoin account homepage. + * + */ + async check_isBridgeButtonEnabled(): Promise { + try { + await this.driver.findClickableElement(this.bridgeButton, 1000); + } catch (e) { + console.log('Bridge button not enabled', e); + return false; + } + console.log('Bridge button is enabled'); + return true; + } + + /** + * Checks if the buy/sell button is enabled on bitcoin account homepage. + */ + async check_isBuySellButtonEnabled(): Promise { + try { + await this.driver.findClickableElement(this.buySellButton, 1000); + } catch (e) { + console.log('Buy/Sell button not enabled', e); + return false; + } + console.log('Buy/Sell button is enabled'); + return true; + } + + /** + * Checks if the expected bitcoin balance is displayed on homepage. + * + * @param expectedBalance - The expected bitcoin balance to be displayed. Defaults to '0'. + */ + async check_isExpectedBitcoinBalanceDisplayed( + expectedBalance: number = 0, + ): Promise { + console.log( + `Check if expected bitcoin balance is displayed: ${expectedBalance} BTC`, + ); + await this.driver.waitForSelector({ + css: this.balance, + text: `${expectedBalance}BTC`, + }); + } + + /** + * Checks if the receive button is enabled on bitcoin account homepage. + */ + async check_isReceiveButtonEnabled(): Promise { + try { + await this.driver.findClickableElement(this.receiveButton, 1000); + } catch (e) { + console.log('Receive button not enabled', e); + return false; + } + console.log('Receive button is enabled'); + return true; + } + + /** + * Checks if the swap button is enabled on bitcoin account homepage. + */ + async check_isSwapButtonEnabled(): Promise { + try { + await this.driver.findClickableElement(this.swapButton, 1000); + } catch (e) { + console.log('Swap button not enabled', e); + return false; + } + console.log('Swap button is enabled'); + return true; + } +} + +export default BitcoinHomepage; diff --git a/test/e2e/page-objects/pages/home/homepage.ts b/test/e2e/page-objects/pages/home/homepage.ts index 6b3f7c9f2a87..1da2349752cb 100644 --- a/test/e2e/page-objects/pages/home/homepage.ts +++ b/test/e2e/page-objects/pages/home/homepage.ts @@ -4,7 +4,7 @@ import { getCleanAppState } from '../../../helpers'; import HeaderNavbar from '../header-navbar'; class HomePage { - private driver: Driver; + protected driver: Driver; public headerNavbar: HeaderNavbar; @@ -12,7 +12,8 @@ class HomePage { testId: 'account-overview__activity-tab', }; - private readonly balance = '[data-testid="eth-overview__primary-currency"]'; + protected readonly balance: string = + '[data-testid="eth-overview__primary-currency"]'; private readonly basicFunctionalityOffWarningMessage = { text: 'Basic functionality is off', @@ -46,9 +47,7 @@ class HomePage { testId: 'refreshList', }; - private readonly sendButton = { - testId: 'eth-overview-send', - }; + protected readonly sendButton: string = '[data-testid="eth-overview-send"]'; private readonly tokensTab = { testId: 'account-overview__asset-tab', diff --git a/test/e2e/page-objects/pages/settings/experimental-settings.ts b/test/e2e/page-objects/pages/settings/experimental-settings.ts index c3f81d99bf23..f551db6d47c5 100644 --- a/test/e2e/page-objects/pages/settings/experimental-settings.ts +++ b/test/e2e/page-objects/pages/settings/experimental-settings.ts @@ -1,4 +1,5 @@ import { Driver } from '../../../webdriver/driver'; +import messages from '../../../../../app/_locales/en/messages.json'; class ExperimentalSettings { private readonly driver: Driver; @@ -7,6 +8,9 @@ class ExperimentalSettings { private readonly addAccountSnapToggle = '[data-testid="add-account-snap-toggle-div"]'; + private readonly addBitcoinAccountToggle = + '[data-testid="bitcoin-support-toggle-div"]'; + private readonly experimentalPageTitle = { text: 'Experimental', tag: 'h4', @@ -35,6 +39,15 @@ class ExperimentalSettings { console.log('Experimental Settings page is loaded'); } + async toggleBitcoinAccount(): Promise { + console.log('Toggle Add new Bitcoin account on experimental setting page'); + await this.driver.waitForSelector({ + text: messages.bitcoinSupportToggleTitle.message, + tag: 'span', + }); + await this.driver.clickElement(this.addBitcoinAccountToggle); + } + async toggleAddAccountSnap(): Promise { console.log('Toggle Add Account Snap on experimental setting page'); await this.driver.clickElement(this.addAccountSnapToggle); diff --git a/test/e2e/page-objects/pages/test-dapp.ts b/test/e2e/page-objects/pages/test-dapp.ts index ef5aca0c6bf7..4eff00462351 100644 --- a/test/e2e/page-objects/pages/test-dapp.ts +++ b/test/e2e/page-objects/pages/test-dapp.ts @@ -276,23 +276,40 @@ class TestDapp { /** * Connect account to test dapp. * - * @param publicAddress - The public address to connect to test dapp. + * @param options - Options for connecting account to test dapp. + * @param [options.connectAccountButtonEnabled] - Indicates if the connect account button should be enabled. + * @param options.publicAddress - The public address to connect to test dapp. */ - async connectAccount(publicAddress: string) { + async connectAccount({ + connectAccountButtonEnabled = true, + publicAddress, + }: { + connectAccountButtonEnabled?: boolean; + publicAddress?: string; + }) { console.log('Connect account to test dapp'); await this.driver.clickElement(this.connectAccountButton); await this.driver.switchToWindowWithTitle(WINDOW_TITLES.Dialog); await this.driver.waitForSelector(this.connectMetaMaskMessage); + if (connectAccountButtonEnabled) { + await this.driver.clickElementAndWaitForWindowToClose( + this.confirmDialogButton, + ); + } else { + const confirmConnectDialogButton = await this.driver.findElement( + this.confirmDialogButton, + ); + assert.equal(await confirmConnectDialogButton.isEnabled(), false); + } - await this.driver.clickElementAndWaitForWindowToClose( - this.confirmDialogButton, - ); - await this.driver.switchToWindowWithTitle(WINDOW_TITLES.TestDApp); - await this.driver.waitForSelector({ - css: this.connectedAccount, - text: publicAddress.toLowerCase(), - }); - await this.driver.waitForSelector(this.localhostNetworkMessage); + if (publicAddress) { + await this.driver.switchToWindowWithTitle(WINDOW_TITLES.TestDApp); + await this.driver.waitForSelector({ + css: this.connectedAccount, + text: publicAddress.toLowerCase(), + }); + await this.driver.waitForSelector(this.localhostNetworkMessage); + } } async createDepositTransaction() { diff --git a/test/e2e/tests/account/snap-account-signatures-and-disconnects.spec.ts b/test/e2e/tests/account/snap-account-signatures-and-disconnects.spec.ts index 7e355302212a..d3c177ff7fdd 100644 --- a/test/e2e/tests/account/snap-account-signatures-and-disconnects.spec.ts +++ b/test/e2e/tests/account/snap-account-signatures-and-disconnects.spec.ts @@ -56,7 +56,9 @@ describe('Snap Account Signatures and Disconnects @no-mmi', function (this: Suit // Disconnect from Test Dapp and reconnect to Test Dapp await testDapp.disconnectAccount(newPublicKey); - await testDapp.connectAccount(newPublicKey); + await testDapp.connectAccount({ + publicAddress: newPublicKey, + }); // SignTypedDataV4 with Test Dapp await signTypedDataV4WithSnapAccount(driver, newPublicKey, false, true); diff --git a/test/e2e/tests/multichain/all-permissions-page.spec.ts b/test/e2e/tests/multichain/all-permissions-page.spec.ts index 756bae735f15..eca4052fdbf7 100644 --- a/test/e2e/tests/multichain/all-permissions-page.spec.ts +++ b/test/e2e/tests/multichain/all-permissions-page.spec.ts @@ -21,7 +21,9 @@ describe('Permissions Page', function () { await loginWithoutBalanceValidation(driver); const testDapp = new TestDapp(driver); await testDapp.openTestDappPage(); - await testDapp.connectAccount(DEFAULT_FIXTURE_ACCOUNT); + await testDapp.connectAccount({ + publicAddress: DEFAULT_FIXTURE_ACCOUNT, + }); // switch to extension window and check the site permissions await driver.switchToWindowWithTitle( diff --git a/test/e2e/tests/tokens/custom-token-send-transfer.spec.js b/test/e2e/tests/tokens/custom-token-send-transfer.spec.js index 3774af82ae1c..16ba368e16ce 100644 --- a/test/e2e/tests/tokens/custom-token-send-transfer.spec.js +++ b/test/e2e/tests/tokens/custom-token-send-transfer.spec.js @@ -158,14 +158,10 @@ describe('Transfer custom tokens @no-mmi', function () { // check token amount is correct after transaction await clickNestedButton(driver, 'Tokens'); - const tokenAmount = await driver.findElement( - { - css: '[data-testid="multichain-token-list-item-value"]', - text: '8.5 TST', - }, - { timeout: 10000 }, - ); - assert.ok(tokenAmount, 'Token amount is not correct'); + await driver.waitForSelector({ + css: '[data-testid="multichain-token-list-item-value"]', + text: '8.5 TST', + }); }, ); }); @@ -223,14 +219,10 @@ describe('Transfer custom tokens @no-mmi', function () { // check token amount is correct after transaction await clickNestedButton(driver, 'Tokens'); - const tokenAmount = await driver.findElement( - { - css: '[data-testid="multichain-token-list-item-value"]', - text: '8.5 TST', - }, - { timeout: 10000 }, - ); - assert.ok(tokenAmount, 'Token amount is not correct'); + await driver.waitForSelector({ + css: '[data-testid="multichain-token-list-item-value"]', + text: '8.5 TST', + }); }, ); }); @@ -346,14 +338,10 @@ describe('Transfer custom tokens @no-mmi', function () { // check token amount is correct after transaction await clickNestedButton(driver, 'Tokens'); - const tokenAmount = await driver.findElement( - { - css: '[data-testid="multichain-token-list-item-value"]', - text: '8.5 TST', - }, - { timeout: 10000 }, - ); - assert.ok(tokenAmount, 'Token amount is not correct'); + await driver.waitForSelector({ + css: '[data-testid="multichain-token-list-item-value"]', + text: '8.5 TST', + }); }, ); }); @@ -410,14 +398,10 @@ describe('Transfer custom tokens @no-mmi', function () { // check token amount is correct after transaction await clickNestedButton(driver, 'Tokens'); - const tokenAmount = await driver.findElement( - { - css: '[data-testid="multichain-token-list-item-value"]', - text: '8.5 TST', - }, - { timeout: 10000 }, - ); - assert.ok(tokenAmount, 'Token amount is not correct'); + await driver.waitForSelector({ + css: '[data-testid="multichain-token-list-item-value"]', + text: '8.5 TST', + }); }, ); }); diff --git a/test/e2e/webdriver/driver.js b/test/e2e/webdriver/driver.js index b0a335eb0d64..c16ef3999490 100644 --- a/test/e2e/webdriver/driver.js +++ b/test/e2e/webdriver/driver.js @@ -499,13 +499,14 @@ class Driver { * and returns a reference to the first matching element. * * @param {string | object} rawLocator - Element locator + * @param {number} timeout - Timeout in milliseconds * @returns {Promise} A promise that resolves to the found element. */ - async findElement(rawLocator) { + async findElement(rawLocator, timeout = this.timeout) { const locator = this.buildLocator(rawLocator); const element = await this.driver.wait( until.elementLocated(locator), - this.timeout, + timeout, ); return wrapElementWithAPI(element, this); } @@ -540,13 +541,14 @@ class Driver { * Finds a clickable element on the page using the given locator. * * @param {string | object} rawLocator - Element locator + * @param {number} timeout - Timeout in milliseconds * @returns {Promise} A promise that resolves to the found clickable element. */ - async findClickableElement(rawLocator) { - const element = await this.findElement(rawLocator); + async findClickableElement(rawLocator, timeout = this.timeout) { + const element = await this.findElement(rawLocator, timeout); await Promise.all([ - this.driver.wait(until.elementIsVisible(element), this.timeout), - this.driver.wait(until.elementIsEnabled(element), this.timeout), + this.driver.wait(until.elementIsVisible(element), timeout), + this.driver.wait(until.elementIsEnabled(element), timeout), ]); return wrapElementWithAPI(element, this); } From 241c9d8b9ac386c6b9a5d934bb17ff3fe7872f17 Mon Sep 17 00:00:00 2001 From: micaelae <100321200+micaelae@users.noreply.github.com> Date: Tue, 17 Dec 2024 10:19:15 -0800 Subject: [PATCH 3/3] fix: sentry e2e test for bridge tokens loading status (#29285) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## **Description** Fixes sentry tests for bridge token loading status in Firefox [![Open in GitHub Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/MetaMask/metamask-extension/pull/29285?quickstart=1) ## **Related issues** Fixes: ## **Manual testing steps** 1. Go to this page... 2. 3. ## **Screenshots/Recordings** ### **Before** ### **After** ## **Pre-merge author checklist** - [X] I've followed [MetaMask Contributor Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask Extension Coding Standards](https://github.com/MetaMask/metamask-extension/blob/main/.github/guidelines/CODING_GUIDELINES.md). - [X] I've completed the PR template to the best of my ability - [X] I’ve included tests if applicable - [X] I’ve documented my code using [JSDoc](https://jsdoc.app/) format if applicable - [X] I’ve applied the right labels on the PR (see [labeling guidelines](https://github.com/MetaMask/metamask-extension/blob/main/.github/guidelines/LABELING_GUIDELINES.md)). Not required for external contributors. ## **Pre-merge reviewer checklist** - [ ] I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed). - [ ] I confirm that this PR addresses all acceptance criteria described in the ticket it closes and includes the necessary testing evidence such as recordings and or screenshots. --- app/scripts/constants/sentry-state.ts | 4 ++-- .../errors-after-init-opt-in-background-state.json | 2 -- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/app/scripts/constants/sentry-state.ts b/app/scripts/constants/sentry-state.ts index 68926c02dc89..ab53ffb3f22d 100644 --- a/app/scripts/constants/sentry-state.ts +++ b/app/scripts/constants/sentry-state.ts @@ -104,10 +104,10 @@ export const SENTRY_BACKGROUND_STATE = { }, destTokens: {}, destTopAssets: [], - destTokensLoadingStatus: false, + destTokensLoadingStatus: true, srcTokens: {}, srcTopAssets: [], - srcTokensLoadingStatus: false, + srcTokensLoadingStatus: true, quoteRequest: { walletAddress: false, srcTokenAddress: true, diff --git a/test/e2e/tests/metrics/state-snapshots/errors-after-init-opt-in-background-state.json b/test/e2e/tests/metrics/state-snapshots/errors-after-init-opt-in-background-state.json index b00f37993b78..cae1a6ae8951 100644 --- a/test/e2e/tests/metrics/state-snapshots/errors-after-init-opt-in-background-state.json +++ b/test/e2e/tests/metrics/state-snapshots/errors-after-init-opt-in-background-state.json @@ -76,8 +76,6 @@ "srcTokens": {}, "srcTopAssets": {}, "destTokens": {}, - "destTokensLoadingStatus": "undefined", - "srcTokensLoadingStatus": "undefined", "destTopAssets": {}, "quoteRequest": { "srcTokenAddress": "0x0000000000000000000000000000000000000000",