From 188e55aeb5f27fcbf5bae1a2df7aec638f5d5e70 Mon Sep 17 00:00:00 2001 From: Curtis Date: Tue, 1 Oct 2024 19:02:42 -0400 Subject: [PATCH] test:stablize swaps --- e2e/pages/TokenOverview.js | 10 ++++ e2e/pages/swaps/SwapView.js | 28 ++++++++-- e2e/resources/blacklistURLs.json | 3 +- e2e/resources/networks.e2e.js | 2 +- .../quarantine/swap-token-chart.failing.js | 2 +- .../swaps/swap-action-regression.spec.js | 2 +- e2e/specs/swaps/swap-action-smoke.spec.js | 6 +- e2e/specs/wallet/send-ERC-token.spec.js | 56 ++++++++++--------- 8 files changed, 70 insertions(+), 39 deletions(-) diff --git a/e2e/pages/TokenOverview.js b/e2e/pages/TokenOverview.js index 433b8ad3aa2..0003e2378fd 100644 --- a/e2e/pages/TokenOverview.js +++ b/e2e/pages/TokenOverview.js @@ -30,6 +30,16 @@ export default class TokenOverview { static async scrollOnScreen() { await TestHelpers.swipe(TOKEN_PRICE, 'up', 'fast', 0.6); } + static async scrollToTokenAcitivity() { + // await TestHelpers.scrollTo(TOKEN_PRICE, 'up', 'fast', 0.6); + // await TestHelpers.scrollTo(TOKEN_PRICE, 'up', 'fast', 0.6); + // await TestHelpers.swipe('Chainlink Token activity', 'up', 'fast', 0.6); + + await waitFor(element(by.text('ChainLink Token activity'))) + .toBeVisible() + .whileElement(by.id('scroll-2')) + .scroll(50, 'down'); + } static async tapBackButton() { await TestHelpers.waitAndTap(ImportTokenViewSelectorsIDs.BACK_BUTTON); diff --git a/e2e/pages/swaps/SwapView.js b/e2e/pages/swaps/SwapView.js index 46abf95cb5b..97177b76b54 100644 --- a/e2e/pages/swaps/SwapView.js +++ b/e2e/pages/swaps/SwapView.js @@ -5,16 +5,15 @@ import { import Matchers from '../../utils/Matchers'; import Gestures from '../../utils/Gestures'; +import TestHelpers from '../../helpers.js'; class SwapView { get quoteSummary() { return Matchers.getElementByID(SwapsViewSelectors.QUOTE_SUMMARY); } - get gasFee() { return Matchers.getElementByID(SwapsViewSelectors.GAS_FEE); } - get fetchingQuotes() { return Matchers.getElementByText(SwapViewSelectorsTexts.FETCHING_QUOTES); } @@ -34,12 +33,27 @@ class SwapView { return title; } + async scrollToBottomOfView(tokenName) { + const token = Matchers.getElementByText(tokenName); + await Gestures.swipe(token, 'up', 'fast', 0.8); + } + // Function to check if the button is enabled + async isButtonEnabled(element) { + const attributes = await element.getAttributes(); + return attributes.enabled === true; // Check if enabled is true + } + async swipeToSwap() { const percentage = device.getPlatform() === 'ios' ? 0.72 : 0.95; + const swapsSliderElement = await this.swipeToSwapButton; + const delay = 500; // Delay in milliseconds + + // Wait until the button is enabled before performing swipe actions + while (!(await this.isButtonEnabled(swapsSliderElement))) { + await TestHelpers.delay(delay); // Wait for the specified delay + } - // Swipe could happen at the same time when gas fees are falshing - // and that's when the swipe button becomes disabled - // that's the need to retry + // Once enabled, perform the swipe actions await Gestures.swipe(this.swipeToSwapButton, 'right', 'fast', percentage); await Gestures.swipe(this.swipeToSwapButton, 'right', 'fast', percentage); } @@ -50,9 +64,11 @@ class SwapView { ); } - async tapIUnderstandPriceWarning() { + async tapIUnderstandPriceWarning(tokenName) { try { await Gestures.waitAndTap(this.iUnderstandLabel, 5000); + await TestHelpers.delay(1000); // Wait for the specified delay + await this.scrollToBottomOfView(tokenName); } catch (e) { // eslint-disable-next-line no-console console.log(`Price warning not displayed: ${e}`); diff --git a/e2e/resources/blacklistURLs.json b/e2e/resources/blacklistURLs.json index cfa117ffc65..c26a2f85661 100644 --- a/e2e/resources/blacklistURLs.json +++ b/e2e/resources/blacklistURLs.json @@ -14,6 +14,7 @@ ".*phishing-detection.cx.metamask.io/.*", ".*eth.llamarpc.com/.*", ".*token-api.metaswap.codefi.network/.*", - ".*gas.api.cx.metamask.io/networks/*" + ".*gas.api.cx.metamask.io/networks/*", + ".*rpc.vnet.tenderly.co/.*" ] } diff --git a/e2e/resources/networks.e2e.js b/e2e/resources/networks.e2e.js index a348bded2e6..5a3c3ad2c55 100644 --- a/e2e/resources/networks.e2e.js +++ b/e2e/resources/networks.e2e.js @@ -97,7 +97,7 @@ const CustomNetworks = { providerConfig: { type: 'rpc', chainId: '0x1', - rpcUrl: `https://rpc.tenderly.co/fork/bbfe5a2e-2426-4512-a5f8-46ce85fe9ad6`, + rpcUrl: `https://virtual.mainnet.rpc.tenderly.co/d9221841-84aa-4e7f-a481-43eb0ae1f997`, nickname: 'Tenderly', ticker: 'ETH', }, diff --git a/e2e/specs/quarantine/swap-token-chart.failing.js b/e2e/specs/quarantine/swap-token-chart.failing.js index a3ef99be5e6..7a4c32e8b02 100644 --- a/e2e/specs/quarantine/swap-token-chart.failing.js +++ b/e2e/specs/quarantine/swap-token-chart.failing.js @@ -73,7 +73,7 @@ describe(Regression('Swap from Token view'), () => { await Assertions.checkIfVisible(SwapView.fetchingQuotes); await Assertions.checkIfVisible(SwapView.quoteSummary); await Assertions.checkIfVisible(SwapView.gasFee); - await SwapView.tapIUnderstandPriceWarning(); + await SwapView.tapIUnderstandPriceWarning(sourceTokenSymbol); await SwapView.swipeToSwap(); try { await Assertions.checkIfVisible( diff --git a/e2e/specs/swaps/swap-action-regression.spec.js b/e2e/specs/swaps/swap-action-regression.spec.js index 65d6e366313..4ee9d48fa03 100644 --- a/e2e/specs/swaps/swap-action-regression.spec.js +++ b/e2e/specs/swaps/swap-action-regression.spec.js @@ -92,7 +92,7 @@ describe(Regression('Multiple Swaps from Actions'), () => { await Assertions.checkIfVisible(SwapView.fetchingQuotes); await Assertions.checkIfVisible(SwapView.quoteSummary); await Assertions.checkIfVisible(SwapView.gasFee); - await SwapView.tapIUnderstandPriceWarning(); + await SwapView.tapIUnderstandPriceWarning(sourceTokenSymbol); await SwapView.swipeToSwap(); try { await Assertions.checkIfVisible( diff --git a/e2e/specs/swaps/swap-action-smoke.spec.js b/e2e/specs/swaps/swap-action-smoke.spec.js index ac383d4cf11..f8a129035e4 100644 --- a/e2e/specs/swaps/swap-action-smoke.spec.js +++ b/e2e/specs/swaps/swap-action-smoke.spec.js @@ -48,8 +48,8 @@ describe(SmokeSwaps('Swap from Actions'), () => { it.each` quantity | sourceTokenSymbol | destTokenSymbol - ${'.05'} | ${'ETH'} | ${'USDT'} - ${'100'} | ${'USDT'} | ${'ETH'} + ${'2'} | ${'ETH'} | ${'USDT'} + ${'1'} | ${'USDT'} | ${'ETH'} `( "should Swap $quantity '$sourceTokenSymbol' to '$destTokenSymbol'", async ({ quantity, sourceTokenSymbol, destTokenSymbol }) => { @@ -91,7 +91,7 @@ describe(SmokeSwaps('Swap from Actions'), () => { await Assertions.checkIfVisible(SwapView.fetchingQuotes); await Assertions.checkIfVisible(SwapView.quoteSummary); await Assertions.checkIfVisible(SwapView.gasFee); - await SwapView.tapIUnderstandPriceWarning(); + await SwapView.tapIUnderstandPriceWarning(sourceTokenSymbol); await SwapView.swipeToSwap(); try { await Assertions.checkIfVisible( diff --git a/e2e/specs/wallet/send-ERC-token.spec.js b/e2e/specs/wallet/send-ERC-token.spec.js index 86d3a494ab3..4c9de56a56b 100644 --- a/e2e/specs/wallet/send-ERC-token.spec.js +++ b/e2e/specs/wallet/send-ERC-token.spec.js @@ -2,45 +2,50 @@ import { SmokeCore } from '../../tags'; import TestHelpers from '../../helpers'; import WalletView from '../../pages/wallet/WalletView'; -import NetworkEducationModal from '../../pages/modals/NetworkEducationModal'; import AmountView from '../../pages/Send/AmountView'; import SendView from '../../pages/Send/SendView'; -import { importWalletWithRecoveryPhrase } from '../../viewHelper'; import TransactionConfirmationView from '../../pages/Send/TransactionConfirmView'; -import NetworkListModal from '../../pages/modals/NetworkListModal'; +import { loginToApp } from '../../viewHelper'; import TokenOverview from '../../pages/TokenOverview'; import ConfirmAddAssetView from '../../pages/wallet/ImportTokenFlow/ConfirmAddAsset'; import ImportTokensView from '../../pages/wallet/ImportTokenFlow/ImportTokensView'; import Assertions from '../../utils/Assertions'; import { CustomNetworks } from '../../resources/networks.e2e'; +import FixtureBuilder from '../../fixtures/fixture-builder'; +import { + loadFixture, + startFixtureServer, + stopFixtureServer, +} from '../../fixtures/fixture-helper'; +import FixtureServer from '../../fixtures/fixture-server'; +import { getFixturesServerPort } from '../../fixtures/utils'; -const TOKEN_ADDRESS = '0x779877A7B0D9E8603169DdbD7836e478b4624789'; +const TOKEN_ADDRESS = '0x514910771AF9Ca656af840dff83E8264EcF986CA'; const SEND_ADDRESS = '0xebe6CcB6B55e1d094d9c58980Bc10Fed69932cAb'; +const fixtureServer = new FixtureServer(); + describe(SmokeCore('Send ERC Token'), () => { beforeAll(async () => { - jest.setTimeout(150000); - await device.launchApp(); + await TestHelpers.reverseServerPort(); + const fixture = new FixtureBuilder() + .withNetworkController(CustomNetworks.Tenderly) + .build(); + await startFixtureServer(fixtureServer); + await loadFixture(fixtureServer, { fixture }); + await device.launchApp({ + permissions: { notifications: 'YES' }, + launchArgs: { fixtureServerPort: `${getFixturesServerPort()}` }, + }); + await loginToApp(); }); - it('should import wallet and go to the wallet view', async () => { - await importWalletWithRecoveryPhrase(); + afterAll(async () => { + await stopFixtureServer(fixtureServer); }); - it('should add Sepolia testnet to my networks list', async () => { - await WalletView.tapNetworksButtonOnNavBar(); - await TestHelpers.delay(2000); - await NetworkListModal.tapTestNetworkSwitch(); - await Assertions.checkIfToggleIsOn(NetworkListModal.testNetToggle); - await NetworkListModal.changeNetworkTo( - CustomNetworks.Sepolia.providerConfig.nickname, - ); - }); - - it('should dismiss network education modal', async () => { - await Assertions.checkIfVisible(NetworkEducationModal.container); - await NetworkEducationModal.tapGotItButton(); - await Assertions.checkIfNotVisible(NetworkEducationModal.container); + beforeEach(async () => { + jest.setTimeout(150000); }); it('should Import custom token', async () => { @@ -59,17 +64,16 @@ describe(SmokeCore('Send ERC Token'), () => { it('should send token to address via asset overview screen', async () => { await WalletView.tapOnToken('ChainLink Token'); await TestHelpers.delay(3500); - await TokenOverview.scrollOnScreen(); + await TokenOverview.scrollToTokenAcitivity(); await TestHelpers.delay(3500); await TokenOverview.tapSendButton(); await SendView.inputAddress(SEND_ADDRESS); await TestHelpers.delay(1000); await SendView.tapNextButton(); - await AmountView.typeInTransactionAmount('0.000001'); + await AmountView.typeInTransactionAmount('0.001'); await TestHelpers.delay(5000); await AmountView.tapNextButton(); - await Assertions.checkIfTextIsDisplayed('< 0.00001 LINK'); + await Assertions.checkIfTextIsDisplayed('< 0.001 LINK'); await TransactionConfirmationView.tapConfirmButton(); - // await Assertions.checkIfTextIsDisplayed('Transaction submitted'); removing this assertion for now }); });