From c6479734bbeaa0ce687268a0b68440321374494c Mon Sep 17 00:00:00 2001 From: ltthienn <132639843+ltthienn@users.noreply.github.com> Date: Thu, 17 Aug 2023 13:10:21 +0700 Subject: [PATCH] [QA-36] E2E - Add other EVM chains (#2131) --- .github/workflows/cypress.yml | 2 +- .github/workflows/schedule.yml | 6 +- cypress.config.ts | 8 +- cypress/e2e/pages/swap-page.po.cy.ts | 115 +++++++++-- cypress/e2e/selectors/constants.cy.ts | 97 +++++++++ cypress/e2e/selectors/selectors.cy.ts | 52 +++-- .../specs/arbitrum/intercept.e2e-spec.cy.ts | 58 ------ .../specs/arbitrum/swap-page.e2e-spec.cy.ts | 195 ------------------ cypress/e2e/specs/connect-wallet.e2e.cy.ts | 29 +++ .../ethereum/connect-wallet.e2e-spec.cy.ts | 43 ---- .../specs/ethereum/intercept.e2e-spec.cy.ts | 58 ------ .../specs/ethereum/swap-page.e2e-spec.cy.ts | 195 ------------------ cypress/e2e/specs/intercept.e2e.cy.ts | 57 +++++ .../specs/optimism/intercept.e2e-spec.cy.ts | 58 ------ .../specs/optimism/swap-page.e2e-spec.cy.ts | 195 ------------------ cypress/e2e/specs/swap-page.e2e.cy.ts | 165 +++++++++++++++ cypress/support/connectWalletCommands.ts | 7 +- cypress/support/selectTokenCommands.ts | 148 ++++++------- package.json | 4 +- 19 files changed, 562 insertions(+), 930 deletions(-) create mode 100644 cypress/e2e/selectors/constants.cy.ts delete mode 100644 cypress/e2e/specs/arbitrum/intercept.e2e-spec.cy.ts delete mode 100644 cypress/e2e/specs/arbitrum/swap-page.e2e-spec.cy.ts create mode 100644 cypress/e2e/specs/connect-wallet.e2e.cy.ts delete mode 100644 cypress/e2e/specs/ethereum/connect-wallet.e2e-spec.cy.ts delete mode 100644 cypress/e2e/specs/ethereum/intercept.e2e-spec.cy.ts delete mode 100644 cypress/e2e/specs/ethereum/swap-page.e2e-spec.cy.ts create mode 100644 cypress/e2e/specs/intercept.e2e.cy.ts delete mode 100644 cypress/e2e/specs/optimism/intercept.e2e-spec.cy.ts delete mode 100644 cypress/e2e/specs/optimism/swap-page.e2e-spec.cy.ts create mode 100644 cypress/e2e/specs/swap-page.e2e.cy.ts diff --git a/.github/workflows/cypress.yml b/.github/workflows/cypress.yml index 3dff9aea03..c72a026cf8 100644 --- a/.github/workflows/cypress.yml +++ b/.github/workflows/cypress.yml @@ -110,7 +110,7 @@ jobs: run: |+ #!/bin/bash yarn preview & - yarn test-e2e + yarn test-e2e -e grepTags=smoke,NETWORK=Ethereum env: DISPLAY: :0.0 diff --git a/.github/workflows/schedule.yml b/.github/workflows/schedule.yml index dca4577415..04862cd183 100644 --- a/.github/workflows/schedule.yml +++ b/.github/workflows/schedule.yml @@ -8,6 +8,10 @@ on: jobs: build: runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + network: ['Ethereum', 'Arbitrum','Optimism', 'Avalanche', 'BNB'] steps: - name: Trigger Code Checkout uses: actions/checkout@v3 @@ -42,7 +46,7 @@ jobs: - name: Run Cypress Test run: |+ #!/bin/bash - yarn test-schedule + yarn test-schedule -e grepTags=regression,NETWORK=${{ matrix.network }} env: DISPLAY: :0.0 diff --git a/cypress.config.ts b/cypress.config.ts index d1fc18862b..5da0b93d20 100644 --- a/cypress.config.ts +++ b/cypress.config.ts @@ -2,6 +2,7 @@ import synpressPlugins from '@synthetixio/synpress/plugins' import { defineConfig } from 'cypress' export default defineConfig({ + projectId: '4x4jf8', component: { devServer: { framework: 'create-react-app', @@ -12,11 +13,16 @@ export default defineConfig({ chromeWebSecurity: true, viewportWidth: 1920, viewportHeight: 1080, + env: { + grepFilterSpecs:true, + grepOmitFiltered:true + }, e2e: { setupNodeEvents(on, config) { + // eslint-disable-next-line @typescript-eslint/no-var-requires require('@cypress/grep/src/plugin')(config) synpressPlugins(on, config) }, - specPattern: 'cypress/e2e/**/*-spec.cy.ts', + specPattern: 'cypress/e2e/specs/*.e2e.cy.ts' }, }) diff --git a/cypress/e2e/pages/swap-page.po.cy.ts b/cypress/e2e/pages/swap-page.po.cy.ts index 6a83a27d74..6da235890b 100644 --- a/cypress/e2e/pages/swap-page.po.cy.ts +++ b/cypress/e2e/pages/swap-page.po.cy.ts @@ -1,23 +1,102 @@ -export enum tag { - smoke = 'smoke', - regression = 'regression', +import { NetworkLocators, SwapPageLocators, TokenCatalogLocators, WalletLocators } from "../selectors/selectors.cy" + +export interface myCallbackType { + (myArgument: T): void } -export function getText(selector: string, callback: any) { - const text = cy.get(selector).invoke('text') - text.then($text => { - callback($text) - }) +export const SwapPage = { + open(url: string) { + cy.visit('/' + url) + cy.url().should('include', url) + cy.closeTutorialPopup() + }, + + selectTokenIn(): TokenCatalog { + cy.selectTokenIn() + return new TokenCatalog() + }, + selectTokenOut(): TokenCatalog { + cy.selectTokenOut() + return new TokenCatalog() + }, + + getCurrentTokenIn(text: myCallbackType) { + cy.getContent(SwapPageLocators.dropdownTokenIn, text) + }, + + getCurrentTokenOut(text: myCallbackType) { + cy.getContent(SwapPageLocators.dropdownTokenOut, text) + }, + + connectWallet() { + cy.get(WalletLocators.btnConnectWallet).should('be.visible').click() + cy.connectWallet() + }, + + getStatusConnectedWallet() { + cy.get(WalletLocators.statusConnected, { timeout: 10000 }).should('be.visible') + } } -export function getTokenList(selector: string, callback: any) { - let arr: string[] = [] - const listToken = cy.get(selector) - listToken - .each(item => { - arr.push(item.text()) - }) - .then(() => { - callback(arr) - }) +export class Network { + selectNetwork(network: string) { + cy.get(NetworkLocators.btnSelectNetwork, { timeout: 30000 }).should('be.visible').click() + cy.get(NetworkLocators.btnNetwork).contains(network).click({ force: true }) + } } + +export class TokenCatalog { + searchToken(value: string) { + cy.searchToken(value) + } + + selectImportTab() { + cy.selectImportTab() + } + + selectFavoriteToken(tokenSymbol: string) { + cy.selectFavoriteToken(tokenSymbol) + } + + selectTokenBySymbol(tokenSymbol: string) { + this.searchToken(tokenSymbol) + cy.selectTokenBySymbol(tokenSymbol) + } + + addFavoriteToken(tokenSymbol: string) { + this.searchToken(tokenSymbol) + cy.wait(2000) + cy.addFavoriteToken() + } + + removeFavoriteToken(tokenSymbol: string) { + cy.removeFavoriteToken(tokenSymbol) + } + + importNewTokens(address: Array) { + address.forEach(element => { + SwapPage.selectTokenIn() + cy.importNewToken(element) + }) + } + + deleteImportedToken(value: string) { + cy.deleteImportedToken(value) + } + + clearAllImportedTokens() { + cy.clearAllImportedTokens() + } + + getFavoriteTokens(list: myCallbackType) { + cy.getList(TokenCatalogLocators.lblFavoriteToken, list) + } + + getWhitelistTokens(list: myCallbackType) { + cy.getList(TokenCatalogLocators.lblRowInWhiteList, list) + } + + getNoResultsFound(text: myCallbackType) { + cy.getContent(TokenCatalogLocators.lblNotFound, text) + } +} \ No newline at end of file diff --git a/cypress/e2e/selectors/constants.cy.ts b/cypress/e2e/selectors/constants.cy.ts new file mode 100644 index 0000000000..4376474012 --- /dev/null +++ b/cypress/e2e/selectors/constants.cy.ts @@ -0,0 +1,97 @@ +export const UNWHITELIST_SYMBOL_TOKENS = ['KNNC', 'KCCN'] +export const NORESULTS_TEXT = "No results found." +export const NOTOKENS_TEXT = "Select a token" +export const DEFAULT_NETWORK = "Ethereum" +export const NETWORK = Cypress.env('NETWORK') +export const DEFAULT_URL = `swap/${NETWORK}`.toLowerCase() + + +export enum TAG { + smoke = 'smoke', + regression = 'regression', +} + +export const TOKEN_SYMBOLS = { + 'Ethereum': ['BAND', 'DAI', 'USDT', 'USDC'], + 'Arbitrum': ['ANGLE', 'DAI', 'USDT', 'USDC.e'], + 'Optimism': ['BOB', 'DAI', 'USDT', 'USDC'], + 'Avalanche': ['AAVE.e', 'sAVAX', 'USDT.e', 'USDC.e'], + 'BNB': ['RICE', 'DAI', 'USDT', 'USDC'] +} + +export const UNWHITELIST_TOKENS = { + "Ethereum": + [ + { + symbol: 'SCOOBY', + address: '0xAd497eE6a70aCcC3Cbb5eB874e60d87593B86F2F', + }, + { + symbol: 'UNIBOT', + address: '0x25127685dc35d4dc96c7feac7370749d004c5040', + }, + { + symbol: 'BGB', + address: '0x19de6b897ed14a376dda0fe53a5420d2ac828a28', + }, + ], + "Arbitrum": [ + { + symbol: 'OHM', + address: '0xf0cb2dc0db5e6c66b9a70ac27b06b878da017028', + }, + { + symbol: 'GBL', + address: '0xe9a264e9d45ff72e1b4a85d77643cdbd4c950207', + }, + { + symbol: 'Y2K', + address: '0x65c936f008bc34fe819bce9fa5afd9dc2d49977f', + }, + ], + "Optimism": + [ + { + symbol: 'CHI', + address: '0xca0e54b636db823847b29f506bffee743f57729d', + }, + { + symbol: 'ACX', + address: '0xFf733b2A3557a7ed6697007ab5D11B79FdD1b76B', + }, + { + symbol: 'PSP', + address: '0xd3594e879b358f430e20f82bea61e83562d49d48', + }, + ], + "Avalanche": + [ + { + symbol: 'RADIO', + address: '0x02bfd11499847003de5f0f5aa081c43854d48815', + }, + { + symbol: 'EUROC', + address: '0xc891eb4cbdeff6e073e859e987815ed1505c2acd', + }, + { + symbol: 'MELD', + address: '0x333000333b26ee30214b4af6419d9ab07a450400', + }, + ], + "BNB": + [ + { + symbol: 'TUSD', + address: '0x40af3827f39d0eacbf4a168f8d4ee67c121d11c9', + }, + { + symbol: 'ARA', + address: '0x5542958fa9bd89c96cb86d1a6cb7a3e644a3d46e', + }, + { + symbol: 'FLASH', + address: '0xc3111096b3b46873393055dea14036ea603cfa95', + } + ], +} \ No newline at end of file diff --git a/cypress/e2e/selectors/selectors.cy.ts b/cypress/e2e/selectors/selectors.cy.ts index 9af33bdafa..e7af50485a 100644 --- a/cypress/e2e/selectors/selectors.cy.ts +++ b/cypress/e2e/selectors/selectors.cy.ts @@ -1,45 +1,41 @@ -export const token = { - tokenIn: '[data-testid=swap-currency-input] [data-testid=token-symbol-container]', - tokenOut: '[data-testid=swap-currency-output] [data-testid=token-symbol-container]', - inputToken: '[data-testid=token-search-input]', - favoriteToken: '[data-testid=favorite-token]', - iconRemoveToken: '[data-testid=close-btn]', - rowInWhiteList: '[data-testid=token-item]', +export const TokenCatalogLocators = { + dropdownTokenIn: '[data-testid=swap-currency-input] [data-testid=token-symbol-container]', + dropdownTokenOut: '[data-testid=swap-currency-output] [data-testid=token-symbol-container]', + txtToken: '[data-testid=token-search-input]', + lblFavoriteToken: '[data-testid=favorite-token]', + lblRowInWhiteList: '[data-testid=token-item]', + lblNotFound: '[data-testid=no-token-result]', iconFavorite: '[data-testid=button-favorite-token]', - iconDelete: '[data-testid=button-remove-import-token]', + iconRemoveImportedToken: '[data-testid=button-remove-import-token]', + iconRemoveFavoriteToken: '[data-testid=close-btn]', btnImport: '[data-testid=button-import-token]', btnUnderstand: '[data-testid=button-confirm-import-token]', - clearAll: '[data-testid=button-clear-all-import-token]', + btnClearAll: '[data-testid=button-clear-all-import-token]', + btnAllTab: '[data-testid=tab-all]', + btnImportTab: '[data-testid=tab-import]' } -export const homePage = { - skipTutorial: '[data-testid=button-skip-tutorial]', +export const SwapPageLocators = { + dropdownTokenIn: '[data-testid=swap-currency-input] [data-testid=token-symbol-container]', + dropdownTokenOut: '[data-testid=swap-currency-output] [data-testid=token-symbol-container]', + btnSkipTutorial: '[data-testid=button-skip-tutorial]', } -export const notification = { - notFound: '[data-testid=no-token-result]', -} - -export const tab = { - allTab: '[data-testid=tab-all]', - import: '[data-testid=tab-import]', -} - -export const wallet = { +export const WalletLocators = { btnConnectWallet: '[data-testid=button-connect-wallet]', btnMetaMask: '[data-testid=connect-METAMASK]', - checkboxAcceptTerm: '[data-testid=accept-term]', + chkAcceptTerm: '[data-testid=accept-term]', statusConnected: '[data-testid=web3-status-connected]', } -export const network = { +export const NetworkLocators = { btnSelectNetwork: '[data-testid=select-network]', btnNetwork: '[data-testid=network-button]', } -export const menu = { - earnMenu: '[data-testid=earn-menu]', - poolMenu: '[data-testid=pools-nav-link]', - myPoolMenu: '[data-testid=my-pools-nav-link]', - farmMenu: '[data-testid=farms-nav-link]', +export const HeaderLocators = { + dropdownEarn: '[data-testid=earn-menu]', + lblPools: '[data-testid=pools-nav-link]', + lblMyPools: '[data-testid=my-pools-nav-link]', + lblFarms: '[data-testid=farms-nav-link]', } diff --git a/cypress/e2e/specs/arbitrum/intercept.e2e-spec.cy.ts b/cypress/e2e/specs/arbitrum/intercept.e2e-spec.cy.ts deleted file mode 100644 index 010a76d894..0000000000 --- a/cypress/e2e/specs/arbitrum/intercept.e2e-spec.cy.ts +++ /dev/null @@ -1,58 +0,0 @@ -import { tag } from '../../pages/swap-page.po.cy' -import { homePage, menu, network } from '../../selectors/selectors.cy' - -const mainPage = 'swap/arbitrum' -describe('Intercept', { tags: tag.regression }, () => { - beforeEach(() => { - cy.visit('/' + mainPage) - cy.url().should('include', mainPage) - cy.clickButton(homePage.skipTutorial) - }) - describe('Swap', () => { - it('Should get route successfully', () => { - cy.intercept('GET', '**/routes?**').as('get-route') - cy.wait('@get-route', { timeout: 20000 }).its('response.statusCode').should('be.oneOf', [200, 404, 408]) - }) - }) - - describe('Pools', () => { - it('Should get pool, farm list successfully', () => { - cy.intercept('GET', '**/farm-pools?**').as('get-farm-list') - cy.intercept('GET', '**/pools?**').as('get-pool-list') - cy.intercept('GET', '**/block?**').as('get-block') - cy.get(menu.earnMenu).click({ force: true }) - cy.get(menu.poolMenu).click({ force: true }) - cy.wait('@get-farm-list', { timeout: 5000 }).its('response.statusCode').should('equal', 200) - cy.wait('@get-pool-list', { timeout: 5000 }).its('response.statusCode').should('equal', 200) - cy.wait('@get-block', { timeout: 5000 }).its('response.statusCode').should('equal', 200) - }) - }) - - describe('My Pools', () => { - it('Should get farm list successfully', () => { - cy.intercept('GET', '**/farm-pools?**').as('get-farm-list') - cy.get(menu.earnMenu).click({ force: true }) - cy.get(menu.myPoolMenu).click({ force: true }) - cy.wait('@get-farm-list', { timeout: 5000 }).its('response.statusCode').should('equal', 200) - }) - }) - - describe('Farms', () => { - it('Should get pool, farm list successfully', () => { - cy.intercept('GET', '**/farm-pools?**').as('get-farm-list') - cy.intercept('GET', '**/pools?**').as('get-pool-list') - cy.intercept('GET', '**/block?**').as('get-block') - cy.get(menu.earnMenu).click({ force: true }) - cy.get(menu.farmMenu).click({ force: true }) - cy.get('[data-testid=farm-block]') - .should(_ => {}) - .then($list => { - if ($list.length) { - cy.wait('@get-pool-list', { timeout: 5000 }).its('response.statusCode').should('equal', 200) - } - cy.wait('@get-farm-list', { timeout: 5000 }).its('response.statusCode').should('equal', 200) - cy.wait('@get-block', { timeout: 5000 }).its('response.statusCode').should('equal', 200) - }) - }) - }) -}) diff --git a/cypress/e2e/specs/arbitrum/swap-page.e2e-spec.cy.ts b/cypress/e2e/specs/arbitrum/swap-page.e2e-spec.cy.ts deleted file mode 100644 index 9d223919ee..0000000000 --- a/cypress/e2e/specs/arbitrum/swap-page.e2e-spec.cy.ts +++ /dev/null @@ -1,195 +0,0 @@ -import { homePage, tab, token } from '../../selectors/selectors.cy' - -const mainPage = 'swap/arbitrum' -const tokenSymbol = ['ARB', 'DAI', 'USDT', 'USDC.e'] -const unListedToken = ['KNNC', 'KCCN'] - -const unWhiteListedToken = { - OHM: { - name: 'OHM', - address: '0xf0cb2dc0db5e6c66b9a70ac27b06b878da017028', - }, - GBL: { - name: 'GBL', - address: '0xe9a264e9d45ff72e1b4a85d77643cdbd4c950207', - }, - Y2K: { - name: 'Y2K', - address: '0x65c936f008bc34fe819bce9fa5afd9dc2d49977f', - }, -} - -describe('Token Catalog', { tags: 'regression' }, () => { - beforeEach(() => { - cy.visit('/' + mainPage) - cy.url().should('include', mainPage) - cy.clickButton(homePage.skipTutorial) - }) - describe('Select token in favorite tokens list', () => { - it('Should be selected tokenIn in favorite tokens list successfully', () => { - cy.clickButton(token.tokenIn) - cy.selectTokenInFavoriteTokensList(token.favoriteToken, tokenSymbol[1]) - cy.verifySelectedToken(token.tokenIn, tokenSymbol[1]) - cy.verifyURL(tokenSymbol[1], '') - }) - - it('Should be selected tokenOut in favorite tokens list successfully', () => { - cy.clickButton(token.tokenOut) - cy.selectTokenInFavoriteTokensList(token.favoriteToken, tokenSymbol[1]) - cy.verifySelectedToken(token.tokenOut, tokenSymbol[1]) - cy.verifyURL('', tokenSymbol[1]) - }) - }) - - describe('Remove/add token with favorite tokens list', () => { - it('Should be removed tokenIn from favorite tokens list', () => { - cy.clickButton(token.tokenIn) - cy.verifyValueInList(token.favoriteToken, [tokenSymbol[3]], true) - cy.removeTokenInFavoriteTokensList(tokenSymbol[3]) - cy.verifyValueInList(token.favoriteToken, [tokenSymbol[3]], false) - cy.input(token.inputToken, tokenSymbol[3]) - cy.verifyIcon('false') - }) - - it('Should be added tokenIn to favorite tokens list', () => { - cy.clickButton(token.tokenIn) - cy.addTokenToFavoriteTokensList(tokenSymbol[0]) - cy.verifyIcon('true') - cy.verifyValueInList(token.favoriteToken, [tokenSymbol[0]], true) - }) - - it('Should be removed tokenOut from favorite tokens list', () => { - cy.clickButton(token.tokenOut) - cy.verifyValueInList(token.favoriteToken, [tokenSymbol[2]], true) - cy.removeTokenInFavoriteTokensList(tokenSymbol[2]) - cy.wait(2000) - cy.verifyValueInList(token.favoriteToken, [tokenSymbol[2]], false) - cy.input(token.inputToken, tokenSymbol[2]) - cy.verifyIcon('false') - }) - - it('Should be added tokenOut to favorite tokens list', () => { - cy.clickButton(token.tokenOut) - cy.addTokenToFavoriteTokensList(tokenSymbol[0]) - cy.wait(2000) - cy.verifyIcon('true') - cy.verifyValueInList(token.favoriteToken, [tokenSymbol[0]], true) - }) - }) - - describe('Select token by symbol', () => { - it('Should be selected tokenIn by symbol successfully', () => { - cy.clickButton(token.tokenIn) - cy.selectTokenBySymbol(token.inputToken, tokenSymbol[0]) - cy.verifySelectedToken(token.tokenIn, tokenSymbol[0]) - cy.verifyURL(tokenSymbol[0], '') - }) - - it('Should be selected tokenOut by symbol successfully', () => { - cy.clickButton(token.tokenOut) - cy.selectTokenBySymbol(token.inputToken, tokenSymbol[1]) - cy.verifySelectedToken(token.tokenOut, tokenSymbol[1]) - cy.verifyURL('', tokenSymbol[1]) - }) - - it('Should be unselected tokenIn not exist in whitelist', () => { - cy.clickButton(token.tokenIn) - cy.input(token.inputToken, unListedToken[0]) - cy.verifyNoResultFound() - }) - - it('Should be unselected tokenOut not exist in whitelist', () => { - cy.clickButton(token.tokenOut) - cy.input(token.inputToken, unListedToken[1]) - cy.verifyNoResultFound() - }) - }) - - describe('Import token', () => { - it('Should be imported tokenIn successfully', () => { - cy.importNewTokenByAddress(token.tokenIn, unWhiteListedToken.OHM.address) - cy.verifySelectedToken(token.tokenIn, unWhiteListedToken.OHM.name) - cy.clickButton(token.tokenIn) - cy.clickButton(tab.import) - cy.verifyValueInList(token.rowInWhiteList, [unWhiteListedToken.OHM.name], true) - }) - - it('Should be imported tokenOut successfully', () => { - cy.importNewTokenByAddress(token.tokenOut, unWhiteListedToken.GBL.address) - cy.verifySelectedToken(token.tokenOut, unWhiteListedToken.GBL.name) - cy.clickButton(token.tokenOut) - cy.clickButton(tab.import) - cy.verifyValueInList(token.rowInWhiteList, [unWhiteListedToken.GBL.name], true) - }) - }) - - describe('Delete token', () => { - it('Should be deleted the imported tokenIn successfully', () => { - cy.importNewTokenByAddress(token.tokenIn, unWhiteListedToken.OHM.address) - cy.clickButton(token.tokenIn) - cy.clickButton(tab.import) - cy.verifyValueInList(token.rowInWhiteList, [unWhiteListedToken.OHM.name], true) - cy.deleteImportedToken(unWhiteListedToken.OHM.address) - cy.verifyNoResultFound() - }) - - it('Should be deleted the imported tokenOut successfully', () => { - cy.importNewTokenByAddress(token.tokenOut, unWhiteListedToken.OHM.address) - cy.clickButton(token.tokenOut) - cy.clickButton(tab.import) - cy.verifyValueInList(token.rowInWhiteList, [unWhiteListedToken.OHM.name], true) - cy.deleteImportedToken(unWhiteListedToken.OHM.address) - cy.verifyNoResultFound() - }) - - it('Should be cleared all the imported tokenIn successfully', () => { - cy.importNewTokenByAddress(token.tokenIn, unWhiteListedToken.OHM.address) - cy.importNewTokenByAddress(token.tokenIn, unWhiteListedToken.GBL.address) - cy.importNewTokenByAddress(token.tokenIn, unWhiteListedToken.Y2K.address) - cy.clickButton(token.tokenIn) - cy.clickButton(tab.import) - cy.verifyValueInList( - token.rowInWhiteList, - [unWhiteListedToken.OHM.name, unWhiteListedToken.GBL.name, unWhiteListedToken.Y2K.name], - true, - ) - cy.clearAllImportedTokens() - cy.verifyNoResultFound() - }) - - it('Should be cleared all the imported tokenOut successfully', () => { - cy.importNewTokenByAddress(token.tokenOut, unWhiteListedToken.OHM.address) - cy.importNewTokenByAddress(token.tokenOut, unWhiteListedToken.GBL.address) - cy.importNewTokenByAddress(token.tokenOut, unWhiteListedToken.Y2K.address) - cy.clickButton(token.tokenOut) - cy.clickButton(tab.import) - cy.verifyValueInList( - token.rowInWhiteList, - [unWhiteListedToken.OHM.name, unWhiteListedToken.GBL.name, unWhiteListedToken.Y2K.name], - true, - ) - cy.clearAllImportedTokens() - cy.verifyNoResultFound() - }) - }) - - describe('E2E Token Catalog', () => { - it('Should be selected tokenIn and tokenOut to swap', () => { - //select tokenIn - cy.clickButton(token.tokenIn) - cy.selectTokenInFavoriteTokensList(token.favoriteToken, tokenSymbol[1]) - cy.verifySelectedToken(token.tokenIn, tokenSymbol[1]) - //select tokenOut - cy.importNewTokenByAddress(token.tokenOut, unWhiteListedToken.OHM.address) - cy.verifySelectedToken(token.tokenOut, unWhiteListedToken.OHM.name) - cy.verifyURL(tokenSymbol[1], unWhiteListedToken.OHM.name) - //delete imported tokenOut - cy.clickButton(token.tokenOut) - cy.clickButton(tab.import) - cy.verifyValueInList(token.rowInWhiteList, [unWhiteListedToken.OHM.name], true) - cy.deleteImportedToken(unWhiteListedToken.OHM.address) - cy.verifyNoResultFound() - cy.get(token.tokenOut).should('include.text', 'Select a token') - }) - }) -}) diff --git a/cypress/e2e/specs/connect-wallet.e2e.cy.ts b/cypress/e2e/specs/connect-wallet.e2e.cy.ts new file mode 100644 index 0000000000..34f9afabbb --- /dev/null +++ b/cypress/e2e/specs/connect-wallet.e2e.cy.ts @@ -0,0 +1,29 @@ + +import { Network, SwapPage } from '../pages/swap-page.po.cy' +import { DEFAULT_NETWORK, DEFAULT_URL, NETWORK, TAG } from '../selectors/constants.cy' + + +const wallet = new Network() + +describe('Metamask Extension tests', { tags: TAG.regression }, () => { + beforeEach(() => { + SwapPage.open(DEFAULT_URL) + SwapPage.connectWallet() + }) + + it('Redirects to swap page when a user has already connected a wallet', () => { + cy.acceptMetamaskAccess() + SwapPage.getStatusConnectedWallet() + cy.url().should('include', '/swap') + }) + + it('Should approve permission to switch network', () => { + if (NETWORK !== DEFAULT_NETWORK) { + SwapPage.getStatusConnectedWallet() + wallet.selectNetwork(NETWORK) + cy.allowMetamaskToAddAndSwitchNetwork().then(approved => { + expect(approved).to.be.true + }) + } + }) +}) diff --git a/cypress/e2e/specs/ethereum/connect-wallet.e2e-spec.cy.ts b/cypress/e2e/specs/ethereum/connect-wallet.e2e-spec.cy.ts deleted file mode 100644 index 71fd1b0464..0000000000 --- a/cypress/e2e/specs/ethereum/connect-wallet.e2e-spec.cy.ts +++ /dev/null @@ -1,43 +0,0 @@ -import { tag } from '../../pages/swap-page.po.cy' -import { homePage, network, wallet } from '../../selectors/selectors.cy' - -const chainList = [ - 'BNB', - 'Polygon', - 'Avalanche', - 'Arbitrum', - 'Optimism', - 'BitTorrent', - 'Oasis', - 'Fantom', - 'Cronos', - 'Velas', - 'Aurora', -] - -describe('Metamask Extension tests', () => { - beforeEach(() => { - cy.visit('/') - cy.clickButton(homePage.skipTutorial) - cy.get(wallet.btnConnectWallet).should('be.visible').click() - cy.connectWallet() - }) - - it('Redirects to swap page when a user has already connected a wallet', { tags: tag.regression }, () => { - cy.acceptMetamaskAccess() - cy.get(wallet.statusConnected, { timeout: 10000 }).should('be.visible') - cy.url().should('include', '/swap') - }) - - it.skip('Should approve permission to switch network', { tags: tag.regression }, () => { - cy.get(wallet.statusConnected, { timeout: 10000 }).should('be.visible') - chainList.forEach(element => { - cy.clickButton(network.btnSelectNetwork) - cy.get(network.btnNetwork).contains(element).click({ force: true }) - cy.allowMetamaskToAddAndSwitchNetwork().then(approved => { - expect(approved).to.be.true - }) - cy.url().should('include', '/swap/' + element.toLowerCase()) - }) - }) -}) diff --git a/cypress/e2e/specs/ethereum/intercept.e2e-spec.cy.ts b/cypress/e2e/specs/ethereum/intercept.e2e-spec.cy.ts deleted file mode 100644 index a0918db908..0000000000 --- a/cypress/e2e/specs/ethereum/intercept.e2e-spec.cy.ts +++ /dev/null @@ -1,58 +0,0 @@ -import { tag } from '../../pages/swap-page.po.cy' -import { homePage, menu, network } from '../../selectors/selectors.cy' - -const mainPage = 'swap/ethereum' -describe('Intercept', { tags: tag.regression }, () => { - beforeEach(() => { - cy.visit('/') - cy.url().should('include', mainPage) - cy.clickButton(homePage.skipTutorial) - }) - describe('Swap', { tags: tag.smoke }, () => { - it('Should get route successfully', () => { - cy.intercept('GET', '**/routes?**').as('get-route') - cy.wait('@get-route', { timeout: 20000 }).its('response.statusCode').should('be.oneOf', [200, 404, 408]) - }) - }) - - describe('Pools', () => { - it('Should get pool, farm list successfully', () => { - cy.intercept('GET', '**/farm-pools?**').as('get-farm-list') - cy.intercept('GET', '**/pools?**').as('get-pool-list') - cy.intercept('GET', '**/block?**').as('get-block') - cy.get(menu.earnMenu).click({ force: true }) - cy.get(menu.poolMenu).click({ force: true }) - cy.wait('@get-farm-list', { timeout: 5000 }).its('response.statusCode').should('equal', 200) - cy.wait('@get-pool-list', { timeout: 5000 }).its('response.statusCode').should('equal', 200) - cy.wait('@get-block', { timeout: 5000 }).its('response.statusCode').should('equal', 200) - }) - }) - - describe('My Pools', () => { - it('Should get farm list successfully', () => { - cy.intercept('GET', '**/farm-pools?**').as('get-farm-list') - cy.get(menu.earnMenu).click({ force: true }) - cy.get(menu.myPoolMenu).click({ force: true }) - cy.wait('@get-farm-list', { timeout: 5000 }).its('response.statusCode').should('equal', 200) - }) - }) - - describe('Farms', () => { - it('Should get pool, farm list successfully', () => { - cy.intercept('GET', '**/farm-pools?**').as('get-farm-list') - cy.intercept('GET', '**/pools?**').as('get-pool-list') - cy.intercept('GET', '**/block?**').as('get-block') - cy.get(menu.earnMenu).click({ force: true }) - cy.get(menu.farmMenu).click({ force: true }) - cy.get('[data-testid=farm-block]') - .should(_ => {}) - .then($list => { - if ($list.length) { - cy.wait('@get-pool-list', { timeout: 5000 }).its('response.statusCode').should('equal', 200) - } - cy.wait('@get-farm-list', { timeout: 5000 }).its('response.statusCode').should('equal', 200) - cy.wait('@get-block', { timeout: 5000 }).its('response.statusCode').should('equal', 200) - }) - }) - }) -}) diff --git a/cypress/e2e/specs/ethereum/swap-page.e2e-spec.cy.ts b/cypress/e2e/specs/ethereum/swap-page.e2e-spec.cy.ts deleted file mode 100644 index bbb3cf8b19..0000000000 --- a/cypress/e2e/specs/ethereum/swap-page.e2e-spec.cy.ts +++ /dev/null @@ -1,195 +0,0 @@ -import { homePage, tab, token } from '../../selectors/selectors.cy' - -const mainPage = 'swap/ethereum' -const tokenSymbol = ['BAND', 'DAI', 'USDT', 'USDC'] -const unListedToken = ['KNNC', 'KCCN'] - -const unWhiteListedToken = { - SCOOBY: { - name: 'SCOOBY', - address: '0xAd497eE6a70aCcC3Cbb5eB874e60d87593B86F2F', - }, - UNIBOT: { - name: 'UNIBOT', - address: '0x25127685dc35d4dc96c7feac7370749d004c5040', - }, - BGB: { - name: 'BGB', - address: '0x19de6b897ed14a376dda0fe53a5420d2ac828a28', - }, -} - -describe('Token Catalog', () => { - beforeEach(() => { - cy.visit('/') - cy.url().should('include', mainPage) - cy.clickButton(homePage.skipTutorial) - }) - describe('Select token in favorite tokens list', () => { - it('Should be selected tokenIn in favorite tokens list successfully', { tags: 'regression' }, () => { - cy.clickButton(token.tokenIn) - cy.selectTokenInFavoriteTokensList(token.favoriteToken, tokenSymbol[1]) - cy.verifySelectedToken(token.tokenIn, tokenSymbol[1]) - cy.verifyURL(tokenSymbol[1], '') - }) - - it('Should be selected tokenOut in favorite tokens list successfully', { tags: 'regression' }, () => { - cy.clickButton(token.tokenOut) - cy.selectTokenInFavoriteTokensList(token.favoriteToken, tokenSymbol[1]) - cy.verifySelectedToken(token.tokenOut, tokenSymbol[1]) - cy.verifyURL('', tokenSymbol[1]) - }) - }) - - describe('Remove/add token with favorite tokens list', () => { - it('Should be removed tokenIn from favorite tokens list', { tags: 'regression' }, () => { - cy.clickButton(token.tokenIn) - cy.verifyValueInList(token.favoriteToken, [tokenSymbol[3]], true) - cy.removeTokenInFavoriteTokensList(tokenSymbol[3]) - cy.wait(2000) - cy.verifyValueInList(token.favoriteToken, [tokenSymbol[3]], false) - cy.input(token.inputToken, tokenSymbol[3]) - cy.verifyIcon('false') - }) - - it('Should be added tokenIn to favorite tokens list', { tags: 'regression' }, () => { - cy.clickButton(token.tokenIn) - cy.addTokenToFavoriteTokensList(tokenSymbol[0]) - cy.verifyIcon('true') - cy.verifyValueInList(token.favoriteToken, [tokenSymbol[0]], true) - }) - - it('Should be removed tokenOut from favorite tokens list', { tags: 'regression' }, () => { - cy.clickButton(token.tokenOut) - cy.verifyValueInList(token.favoriteToken, [tokenSymbol[2]], true) - cy.removeTokenInFavoriteTokensList(tokenSymbol[2]) - cy.wait(2000) - cy.verifyValueInList(token.favoriteToken, [tokenSymbol[2]], false) - cy.input(token.inputToken, tokenSymbol[2]) - cy.verifyIcon('false') - }) - - it('Should be added tokenOut to favorite tokens list', { tags: 'regression' }, () => { - cy.clickButton(token.tokenOut) - cy.addTokenToFavoriteTokensList(tokenSymbol[0]) - cy.verifyIcon('true') - cy.verifyValueInList(token.favoriteToken, [tokenSymbol[0]], true) - }) - }) - - describe('Select token by symbol', () => { - it('Should be selected tokenIn by symbol successfully', { tags: 'regression' }, () => { - cy.clickButton(token.tokenIn) - cy.selectTokenBySymbol(token.inputToken, tokenSymbol[0]) - cy.verifySelectedToken(token.tokenIn, tokenSymbol[0]) - cy.verifyURL(tokenSymbol[0], '') - }) - - it('Should be selected tokenOut by symbol successfully', { tags: 'regression' }, () => { - cy.clickButton(token.tokenOut) - cy.selectTokenBySymbol(token.inputToken, tokenSymbol[1]) - cy.verifySelectedToken(token.tokenOut, tokenSymbol[1]) - cy.verifyURL('', tokenSymbol[1]) - }) - - it('Should be unselected tokenIn not exist in whitelist', { tags: 'regression' }, () => { - cy.clickButton(token.tokenIn) - cy.input(token.inputToken, unListedToken[0]) - cy.verifyNoResultFound() - }) - - it('Should be unselected tokenOut not exist in whitelist', { tags: 'regression' }, () => { - cy.clickButton(token.tokenOut) - cy.input(token.inputToken, unListedToken[1]) - cy.verifyNoResultFound() - }) - }) - - describe('Import token', () => { - it('Should be imported tokenIn successfully', { tags: 'regression' }, () => { - cy.importNewTokenByAddress(token.tokenIn, unWhiteListedToken.SCOOBY.address) - cy.verifySelectedToken(token.tokenIn, unWhiteListedToken.SCOOBY.name) - cy.clickButton(token.tokenIn) - cy.clickButton(tab.import) - cy.verifyValueInList(token.rowInWhiteList, [unWhiteListedToken.SCOOBY.name], true) - }) - - it('Should be imported tokenOut successfully', { tags: 'regression' }, () => { - cy.importNewTokenByAddress(token.tokenOut, unWhiteListedToken.UNIBOT.address) - cy.verifySelectedToken(token.tokenOut, unWhiteListedToken.UNIBOT.name) - cy.clickButton(token.tokenOut) - cy.clickButton(tab.import) - cy.verifyValueInList(token.rowInWhiteList, [unWhiteListedToken.UNIBOT.name], true) - }) - }) - - describe('Delete token', () => { - it('Should be deleted the imported tokenIn successfully', { tags: 'regression' }, () => { - cy.importNewTokenByAddress(token.tokenIn, unWhiteListedToken.SCOOBY.address) - cy.clickButton(token.tokenIn) - cy.clickButton(tab.import) - cy.verifyValueInList(token.rowInWhiteList, [unWhiteListedToken.SCOOBY.name], true) - cy.deleteImportedToken(unWhiteListedToken.SCOOBY.address) - cy.verifyNoResultFound() - }) - - it('Should be deleted the imported tokenOut successfully', { tags: 'regression' }, () => { - cy.importNewTokenByAddress(token.tokenOut, unWhiteListedToken.SCOOBY.address) - cy.clickButton(token.tokenOut) - cy.clickButton(tab.import) - cy.verifyValueInList(token.rowInWhiteList, [unWhiteListedToken.SCOOBY.name], true) - cy.deleteImportedToken(unWhiteListedToken.SCOOBY.address) - cy.verifyNoResultFound() - }) - - it('Should be cleared all the imported tokenIn successfully', { tags: 'regression' }, () => { - cy.importNewTokenByAddress(token.tokenIn, unWhiteListedToken.SCOOBY.address) - cy.importNewTokenByAddress(token.tokenIn, unWhiteListedToken.BGB.address) - cy.importNewTokenByAddress(token.tokenIn, unWhiteListedToken.UNIBOT.address) - cy.clickButton(token.tokenIn) - cy.clickButton(tab.import) - cy.verifyValueInList( - token.rowInWhiteList, - [unWhiteListedToken.SCOOBY.name, unWhiteListedToken.BGB.name, unWhiteListedToken.UNIBOT.name], - true, - ) - cy.clearAllImportedTokens() - cy.verifyNoResultFound() - }) - - it('Should be cleared all the imported tokenOut successfully', { tags: 'regression' }, () => { - cy.importNewTokenByAddress(token.tokenOut, unWhiteListedToken.SCOOBY.address) - cy.importNewTokenByAddress(token.tokenOut, unWhiteListedToken.BGB.address) - cy.importNewTokenByAddress(token.tokenOut, unWhiteListedToken.UNIBOT.address) - cy.clickButton(token.tokenOut) - cy.clickButton(tab.import) - cy.verifyValueInList( - token.rowInWhiteList, - [unWhiteListedToken.SCOOBY.name, unWhiteListedToken.BGB.name, unWhiteListedToken.UNIBOT.name], - true, - ) - cy.clearAllImportedTokens() - cy.verifyNoResultFound() - }) - }) - - describe('E2E Token Catalog', () => { - it('Should be selected tokenIn and tokenOut to swap', { tags: ['smoke', 'regression'] }, () => { - //select tokenIn - cy.clickButton(token.tokenIn) - cy.selectTokenInFavoriteTokensList(token.favoriteToken, tokenSymbol[1]) - cy.verifySelectedToken(token.tokenIn, tokenSymbol[1]) - //select tokenOut - cy.importNewTokenByAddress(token.tokenOut, unWhiteListedToken.SCOOBY.address) - cy.verifySelectedToken(token.tokenOut, unWhiteListedToken.SCOOBY.name) - cy.verifyURL(tokenSymbol[1], unWhiteListedToken.SCOOBY.name) - //delete imported tokenOut - cy.clickButton(token.tokenOut) - cy.clickButton(tab.import) - cy.verifyValueInList(token.rowInWhiteList, [unWhiteListedToken.SCOOBY.name], true) - cy.deleteImportedToken(unWhiteListedToken.SCOOBY.address) - cy.verifyNoResultFound() - cy.get(token.tokenOut).should('include.text', 'Select a token') - }) - }) -}) diff --git a/cypress/e2e/specs/intercept.e2e.cy.ts b/cypress/e2e/specs/intercept.e2e.cy.ts new file mode 100644 index 0000000000..cefd5f6ce7 --- /dev/null +++ b/cypress/e2e/specs/intercept.e2e.cy.ts @@ -0,0 +1,57 @@ +/* eslint-disable @typescript-eslint/no-empty-function */ +import { SwapPage } from "../pages/swap-page.po.cy" +import { DEFAULT_URL, TAG, } from "../selectors/constants.cy" +import { HeaderLocators } from "../selectors/selectors.cy" + +describe('Intercept', { tags: TAG.regression }, () => { + beforeEach(() => { + SwapPage.open(DEFAULT_URL) + }) + describe('Swap', () => { + it('Should get route successfully', () => { + cy.intercept('GET', '**/routes?**').as('get-route') + cy.wait('@get-route', { timeout: 20000 }).its('response.statusCode').should('be.oneOf', [200, 404, 408]) + }) + }) + + describe('Pools', () => { + it('Should get pool, farm list successfully', () => { + cy.intercept('GET', '**/farm-pools?**').as('get-farm-list') + cy.intercept('GET', '**/pools?**').as('get-pool-list') + cy.intercept('GET', '**/block?**').as('get-block') + cy.get(HeaderLocators.dropdownEarn).click({ force: true }) + cy.get(HeaderLocators.lblPools).click({ force: true }) + cy.wait('@get-farm-list', { timeout: 5000 }).its('response.statusCode').should('equal', 200) + cy.wait('@get-pool-list', { timeout: 5000 }).its('response.statusCode').should('equal', 200) + cy.wait('@get-block', { timeout: 60000 }).its('response.statusCode').should('equal', 200) + }) + }) + + describe('My Pools', () => { + it('Should get farm list successfully', () => { + cy.intercept('GET', '**/farm-pools?**').as('get-farm-list') + cy.get(HeaderLocators.dropdownEarn).click({ force: true }) + cy.get(HeaderLocators.lblPools).click({ force: true }) + cy.wait('@get-farm-list', { timeout: 5000 }).its('response.statusCode').should('equal', 200) + }) + }) + + describe('Farms', () => { + it('Should get pool, farm list successfully', () => { + cy.intercept('GET', '**/farm-pools?**').as('get-farm-list') + cy.intercept('GET', '**/pools?**').as('get-pool-list') + cy.intercept('GET', '**/block?**').as('get-block') + cy.get(HeaderLocators.dropdownEarn).click({ force: true }) + cy.get(HeaderLocators.lblFarms).click({ force: true }) + cy.get('[data-testid=farm-block]') + .should(_ => {}) + .then($list => { + if ($list.length) { + cy.wait('@get-pool-list', { timeout: 5000 }).its('response.statusCode').should('equal', 200) + } + cy.wait('@get-farm-list', { timeout: 5000 }).its('response.statusCode').should('equal', 200) + cy.wait('@get-block', { timeout: 60000 }).its('response.statusCode').should('equal', 200) + }) + }) + }) +}) \ No newline at end of file diff --git a/cypress/e2e/specs/optimism/intercept.e2e-spec.cy.ts b/cypress/e2e/specs/optimism/intercept.e2e-spec.cy.ts deleted file mode 100644 index 35725f3ba8..0000000000 --- a/cypress/e2e/specs/optimism/intercept.e2e-spec.cy.ts +++ /dev/null @@ -1,58 +0,0 @@ -import { tag } from '../../pages/swap-page.po.cy' -import { homePage, menu, network } from '../../selectors/selectors.cy' - -const mainPage = 'swap/optimism' -describe('Intercept', { tags: tag.regression }, () => { - beforeEach(() => { - cy.visit('/' + mainPage) - cy.url().should('include', mainPage) - cy.clickButton(homePage.skipTutorial) - }) - describe('Swap', { tags: tag.smoke }, () => { - it('Should get route successfully', () => { - cy.intercept('GET', '**/routes?**').as('get-route') - cy.wait('@get-route', { timeout: 20000 }).its('response.statusCode').should('be.oneOf', [200, 404, 408]) - }) - }) - - describe('Pools', () => { - it('Should get pool, farm list successfully', () => { - cy.intercept('GET', '**/farm-pools?**').as('get-farm-list') - cy.intercept('GET', '**/pools?**').as('get-pool-list') - cy.intercept('GET', '**/block?**').as('get-block') - cy.get(menu.earnMenu).click({ force: true }) - cy.get(menu.poolMenu).click({ force: true }) - cy.wait('@get-farm-list', { timeout: 5000 }).its('response.statusCode').should('equal', 200) - cy.wait('@get-pool-list', { timeout: 5000 }).its('response.statusCode').should('equal', 200) - cy.wait('@get-block', { timeout: 5000 }).its('response.statusCode').should('equal', 200) - }) - }) - - describe('My Pools', () => { - it('Should get farm list successfully', () => { - cy.intercept('GET', '**/farm-pools?**').as('get-farm-list') - cy.get(menu.earnMenu).click({ force: true }) - cy.get(menu.myPoolMenu).click({ force: true }) - cy.wait('@get-farm-list', { timeout: 5000 }).its('response.statusCode').should('equal', 200) - }) - }) - - describe('Farms', () => { - it('Should get pool, farm list successfully', () => { - cy.intercept('GET', '**/farm-pools?**').as('get-farm-list') - cy.intercept('GET', '**/pools?**').as('get-pool-list') - cy.intercept('GET', '**/block?**').as('get-block') - cy.get(menu.earnMenu).click({ force: true }) - cy.get(menu.farmMenu).click({ force: true }) - cy.get('[data-testid=farm-block]') - .should(_ => {}) - .then($list => { - if ($list.length) { - cy.wait('@get-pool-list', { timeout: 5000 }).its('response.statusCode').should('equal', 200) - } - cy.wait('@get-farm-list', { timeout: 5000 }).its('response.statusCode').should('equal', 200) - cy.wait('@get-block', { timeout: 5000 }).its('response.statusCode').should('equal', 200) - }) - }) - }) -}) diff --git a/cypress/e2e/specs/optimism/swap-page.e2e-spec.cy.ts b/cypress/e2e/specs/optimism/swap-page.e2e-spec.cy.ts deleted file mode 100644 index 16c33c7eaa..0000000000 --- a/cypress/e2e/specs/optimism/swap-page.e2e-spec.cy.ts +++ /dev/null @@ -1,195 +0,0 @@ -import { homePage, tab, token } from '../../selectors/selectors.cy' - -const mainPage = 'swap/optimism' -const tokenSymbol = ['BOB', 'DAI', 'USDT', 'USDC'] -const unListedToken = ['KNNC', 'KCCN'] - -const unWhiteListedToken = { - CHI: { - name: 'CHI', - address: '0xca0e54b636db823847b29f506bffee743f57729d', - }, - ACX: { - name: 'ACX', - address: '0xFf733b2A3557a7ed6697007ab5D11B79FdD1b76B', - }, - PSP: { - name: 'PSP', - address: '0xd3594e879b358f430e20f82bea61e83562d49d48', - }, -} - -describe('Token Catalog', { tags: 'regression' }, () => { - beforeEach(() => { - cy.visit('/optimism') - cy.url().should('include', mainPage) - cy.clickButton(homePage.skipTutorial) - }) - describe('Select token in favorite tokens list', () => { - it('Should be selected tokenIn in favorite tokens list successfully', { tags: 'regression' }, () => { - cy.clickButton(token.tokenIn) - cy.selectTokenInFavoriteTokensList(token.favoriteToken, tokenSymbol[1]) - cy.verifySelectedToken(token.tokenIn, tokenSymbol[1]) - cy.verifyURL(tokenSymbol[1], '') - }) - - it('Should be selected tokenOut in favorite tokens list successfully', { tags: 'regression' }, () => { - cy.clickButton(token.tokenOut) - cy.selectTokenInFavoriteTokensList(token.favoriteToken, tokenSymbol[1]) - cy.verifySelectedToken(token.tokenOut, tokenSymbol[1]) - cy.verifyURL('', tokenSymbol[1]) - }) - }) - - describe('Remove/add token with favorite tokens list', () => { - it('Should be removed tokenIn from favorite tokens list', { tags: 'regression' }, () => { - cy.clickButton(token.tokenIn) - cy.verifyValueInList(token.favoriteToken, [tokenSymbol[3]], true) - cy.removeTokenInFavoriteTokensList(tokenSymbol[3]) - cy.wait(2000) - cy.verifyValueInList(token.favoriteToken, [tokenSymbol[3]], false) - cy.input(token.inputToken, tokenSymbol[3]) - cy.verifyIcon('false') - }) - - it('Should be added tokenIn to favorite tokens list', { tags: 'regression' }, () => { - cy.clickButton(token.tokenIn) - cy.addTokenToFavoriteTokensList(tokenSymbol[0]) - cy.verifyIcon('true') - cy.verifyValueInList(token.favoriteToken, [tokenSymbol[0]], true) - }) - - it('Should be removed tokenOut from favorite tokens list', { tags: 'regression' }, () => { - cy.clickButton(token.tokenOut) - cy.verifyValueInList(token.favoriteToken, [tokenSymbol[2]], true) - cy.removeTokenInFavoriteTokensList(tokenSymbol[2]) - cy.wait(2000) - cy.verifyValueInList(token.favoriteToken, [tokenSymbol[2]], false) - cy.input(token.inputToken, tokenSymbol[2]) - cy.verifyIcon('false') - }) - - it('Should be added tokenOut to favorite tokens list', { tags: 'regression' }, () => { - cy.clickButton(token.tokenOut) - cy.addTokenToFavoriteTokensList(tokenSymbol[0]) - cy.verifyIcon('true') - cy.verifyValueInList(token.favoriteToken, [tokenSymbol[0]], true) - }) - }) - - describe('Select token by symbol', () => { - it('Should be selected tokenIn by symbol successfully', { tags: 'regression' }, () => { - cy.clickButton(token.tokenIn) - cy.selectTokenBySymbol(token.inputToken, tokenSymbol[0]) - cy.verifySelectedToken(token.tokenIn, tokenSymbol[0]) - cy.verifyURL(tokenSymbol[0], '') - }) - - it('Should be selected tokenOut by symbol successfully', { tags: 'regression' }, () => { - cy.clickButton(token.tokenOut) - cy.selectTokenBySymbol(token.inputToken, tokenSymbol[1]) - cy.verifySelectedToken(token.tokenOut, tokenSymbol[1]) - cy.verifyURL('', tokenSymbol[1]) - }) - - it('Should be unselected tokenIn not exist in whitelist', { tags: 'regression' }, () => { - cy.clickButton(token.tokenIn) - cy.input(token.inputToken, unListedToken[0]) - cy.verifyNoResultFound() - }) - - it('Should be unselected tokenOut not exist in whitelist', { tags: 'regression' }, () => { - cy.clickButton(token.tokenOut) - cy.input(token.inputToken, unListedToken[1]) - cy.verifyNoResultFound() - }) - }) - - describe('Import token', () => { - it('Should be imported tokenIn successfully', { tags: 'regression' }, () => { - cy.importNewTokenByAddress(token.tokenIn, unWhiteListedToken.CHI.address) - cy.verifySelectedToken(token.tokenIn, unWhiteListedToken.CHI.name) - cy.clickButton(token.tokenIn) - cy.clickButton(tab.import) - cy.verifyValueInList(token.rowInWhiteList, [unWhiteListedToken.CHI.name], true) - }) - - it('Should be imported tokenOut successfully', { tags: 'regression' }, () => { - cy.importNewTokenByAddress(token.tokenOut, unWhiteListedToken.ACX.address) - cy.verifySelectedToken(token.tokenOut, unWhiteListedToken.ACX.name) - cy.clickButton(token.tokenOut) - cy.clickButton(tab.import) - cy.verifyValueInList(token.rowInWhiteList, [unWhiteListedToken.ACX.name], true) - }) - }) - - describe('Delete token', () => { - it('Should be deleted the imported tokenIn successfully', { tags: 'regression' }, () => { - cy.importNewTokenByAddress(token.tokenIn, unWhiteListedToken.CHI.address) - cy.clickButton(token.tokenIn) - cy.clickButton(tab.import) - cy.verifyValueInList(token.rowInWhiteList, [unWhiteListedToken.CHI.name], true) - cy.deleteImportedToken(unWhiteListedToken.CHI.address) - cy.verifyNoResultFound() - }) - - it('Should be deleted the imported tokenOut successfully', { tags: 'regression' }, () => { - cy.importNewTokenByAddress(token.tokenOut, unWhiteListedToken.CHI.address) - cy.clickButton(token.tokenOut) - cy.clickButton(tab.import) - cy.verifyValueInList(token.rowInWhiteList, [unWhiteListedToken.CHI.name], true) - cy.deleteImportedToken(unWhiteListedToken.CHI.address) - cy.verifyNoResultFound() - }) - - it('Should be cleared all the imported tokenIn successfully', { tags: 'regression' }, () => { - cy.importNewTokenByAddress(token.tokenIn, unWhiteListedToken.CHI.address) - cy.importNewTokenByAddress(token.tokenIn, unWhiteListedToken.ACX.address) - cy.importNewTokenByAddress(token.tokenIn, unWhiteListedToken.PSP.address) - cy.clickButton(token.tokenIn) - cy.clickButton(tab.import) - cy.verifyValueInList( - token.rowInWhiteList, - [unWhiteListedToken.CHI.name, unWhiteListedToken.ACX.name, unWhiteListedToken.PSP.name], - true, - ) - cy.clearAllImportedTokens() - cy.verifyNoResultFound() - }) - - it('Should be cleared all the imported tokenOut successfully', { tags: 'regression' }, () => { - cy.importNewTokenByAddress(token.tokenOut, unWhiteListedToken.CHI.address) - cy.importNewTokenByAddress(token.tokenOut, unWhiteListedToken.ACX.address) - cy.importNewTokenByAddress(token.tokenOut, unWhiteListedToken.PSP.address) - cy.clickButton(token.tokenOut) - cy.clickButton(tab.import) - cy.verifyValueInList( - token.rowInWhiteList, - [unWhiteListedToken.CHI.name, unWhiteListedToken.ACX.name, unWhiteListedToken.ACX.name], - true, - ) - cy.clearAllImportedTokens() - cy.verifyNoResultFound() - }) - }) - - describe('E2E Token Catalog', () => { - it('Should be selected tokenIn and tokenOut to swap', { tags: ['smoke', 'regression'] }, () => { - //select tokenIn - cy.clickButton(token.tokenIn) - cy.selectTokenInFavoriteTokensList(token.favoriteToken, tokenSymbol[1]) - cy.verifySelectedToken(token.tokenIn, tokenSymbol[1]) - //select tokenOut - cy.importNewTokenByAddress(token.tokenOut, unWhiteListedToken.CHI.address) - cy.verifySelectedToken(token.tokenOut, unWhiteListedToken.CHI.name) - cy.verifyURL(tokenSymbol[1], unWhiteListedToken.CHI.name) - //delete imported tokenOut - cy.clickButton(token.tokenOut) - cy.clickButton(tab.import) - cy.verifyValueInList(token.rowInWhiteList, [unWhiteListedToken.CHI.name], true) - cy.deleteImportedToken(unWhiteListedToken.CHI.address) - cy.verifyNoResultFound() - cy.get(token.tokenOut).should('include.text', 'Select a token') - }) - }) -}) diff --git a/cypress/e2e/specs/swap-page.e2e.cy.ts b/cypress/e2e/specs/swap-page.e2e.cy.ts new file mode 100644 index 0000000000..4c52d4e28b --- /dev/null +++ b/cypress/e2e/specs/swap-page.e2e.cy.ts @@ -0,0 +1,165 @@ +import { SwapPage, TokenCatalog } from "../pages/swap-page.po.cy" +import { DEFAULT_URL, NETWORK, NORESULTS_TEXT, NOTOKENS_TEXT, TAG, TOKEN_SYMBOLS, UNWHITELIST_SYMBOL_TOKENS, UNWHITELIST_TOKENS } from "../selectors/constants.cy" + +const unWhitelistTokens = UNWHITELIST_TOKENS[NETWORK] +const tokenSymbols = TOKEN_SYMBOLS[NETWORK] + +const arrAddress = [unWhitelistTokens[0].address, unWhitelistTokens[1].address, unWhitelistTokens[2].address] +const arrSymbol = [unWhitelistTokens[0].symbol, unWhitelistTokens[1].symbol, unWhitelistTokens[2].symbol] + + +const tokenCatalog = new TokenCatalog(); + + +describe(`Token Catalog on ${NETWORK}`, { tags: TAG.regression }, () => { + beforeEach(() => { + SwapPage.open(DEFAULT_URL) + }) + + describe('Select token in favorite tokens list', () => { + it('Should be selected tokenIn in favorite tokens list successfully', () => { + SwapPage.selectTokenIn().getFavoriteTokens((arr) => { + tokenCatalog.selectFavoriteToken(arr[1]) + SwapPage.getCurrentTokenIn((text) => { + expect(text).to.equal(arr[1]) + }) + }) + }) + + it('Should be selected tokenOut in favorite tokens list successfully', () => { + SwapPage.selectTokenOut().getFavoriteTokens((arr) => { + tokenCatalog.selectFavoriteToken(arr[2]) + SwapPage.getCurrentTokenOut((text) => { + expect(text).to.equal(arr[2]) + }) + }) + }) + }) + + describe('Remove/add token with favorite tokens list', () => { + it('Should be removed tokenIn from favorite tokens list', () => { + SwapPage.selectTokenIn().getFavoriteTokens((arr) => { + tokenCatalog.removeFavoriteToken(arr[1]) + tokenCatalog.getFavoriteTokens((list) => { + expect(list).not.to.include.members([arr[1]]) + }) + }) + }) + + it('Should be added tokenIn to favorite tokens list', () => { + SwapPage.selectTokenIn().addFavoriteToken(tokenSymbols[0]) + tokenCatalog.getFavoriteTokens((list) => { + expect(list).to.include.members([tokenSymbols[0]]) + }) + }) + + it('Should be removed tokenOut from favorite tokens list', () => { + SwapPage.selectTokenOut().getFavoriteTokens((arr) => { + tokenCatalog.removeFavoriteToken(arr[2]) + tokenCatalog.getFavoriteTokens((list) => { + expect(list).not.to.include.members([arr[2]]) + }) + }) + }) + + it('Should be added tokenOut to favorite tokens list', () => { + SwapPage.selectTokenOut().addFavoriteToken(tokenSymbols[0]) + tokenCatalog.getFavoriteTokens((list) => { + expect(list).to.include.members([tokenSymbols[0]]) + }) + }) + }) + + describe('Select token by symbol', () => { + it('Should be selected tokenIn by symbol successfully', () => { + SwapPage.selectTokenIn().selectTokenBySymbol(tokenSymbols[0]) + SwapPage.getCurrentTokenIn((text) => { + expect(text).to.equal(tokenSymbols[0]) + }) + }) + + it('Should be selected tokenOut by symbol successfully', () => { + SwapPage.selectTokenOut().selectTokenBySymbol(tokenSymbols[1]) + SwapPage.getCurrentTokenOut((text) => { + expect(text).to.equal(tokenSymbols[1]) + }) + }) + + it('Should be unselected tokenIn not exist in whitelist', () => { + SwapPage.selectTokenIn().searchToken(UNWHITELIST_SYMBOL_TOKENS[0]) + tokenCatalog.getNoResultsFound((text) => { + expect(text).to.equal(NORESULTS_TEXT) + }) + }) + + it('Should be unselected tokenOut not exist in whitelist', () => { + SwapPage.selectTokenOut().searchToken(UNWHITELIST_SYMBOL_TOKENS[0]) + tokenCatalog.getNoResultsFound((text) => { + expect(text).to.equal(NORESULTS_TEXT) + }) + }) + }) + + describe('Import and delete token', () => { + it('Should be imported then deleted tokenIn successfully', () => { + tokenCatalog.importNewTokens(arrAddress) + SwapPage.selectTokenIn().selectImportTab() + tokenCatalog.getWhitelistTokens((list) => { + expect(list).to.include.members(arrSymbol) + }) + + tokenCatalog.deleteImportedToken(arrSymbol[2]) + tokenCatalog.getWhitelistTokens((list) => { + expect(list).not.to.include.members([arrSymbol[2]]) + }) + + tokenCatalog.clearAllImportedTokens() + tokenCatalog.getNoResultsFound((text) => { + expect(text).to.equal(NORESULTS_TEXT) + }) + }) + + it('Should be imported then deleted tokenOut successfully', () => { + tokenCatalog.importNewTokens(arrAddress) + SwapPage.selectTokenOut().selectImportTab() + tokenCatalog.getWhitelistTokens((list) => { + expect(list).to.include.members(arrSymbol) + }) + + tokenCatalog.deleteImportedToken(arrSymbol[1]) + tokenCatalog.getWhitelistTokens((list) => { + expect(list).not.to.include.members([arrSymbol[1]]) + }) + + tokenCatalog.clearAllImportedTokens() + tokenCatalog.getNoResultsFound((text) => { + expect(text).to.equal(NORESULTS_TEXT) + }) + }) + }) + + describe(`E2E Token Catalog`, () => { + it('Should be selected tokenIn and tokenOut to swap', { tags: TAG.smoke }, () => { + tokenCatalog.importNewTokens([arrAddress[2]]) + SwapPage.getCurrentTokenIn((text) => { + expect(text).to.equal(arrSymbol[2]) + }) + + SwapPage.selectTokenOut().getFavoriteTokens((arr) => { + tokenCatalog.selectFavoriteToken(arr[1]) + SwapPage.getCurrentTokenOut((text) => { + expect(text).to.equal(arr[1]) + }) + }) + + SwapPage.selectTokenOut() + tokenCatalog.deleteImportedToken(arrSymbol[2]) + tokenCatalog.getNoResultsFound((text) => { + expect(text).to.equal(NORESULTS_TEXT) + }) + SwapPage.getCurrentTokenIn((text) => { + expect(text).to.equal(NOTOKENS_TEXT) + }) + }) + }) +}) \ No newline at end of file diff --git a/cypress/support/connectWalletCommands.ts b/cypress/support/connectWalletCommands.ts index c72276ba93..556542d341 100644 --- a/cypress/support/connectWalletCommands.ts +++ b/cypress/support/connectWalletCommands.ts @@ -1,8 +1,9 @@ -import { wallet } from '../e2e/selectors/selectors.cy' +import { WalletLocators } from '../e2e/selectors/selectors.cy' export {} declare global { + // eslint-disable-next-line @typescript-eslint/no-namespace namespace Cypress { interface Chainable { connectWallet(): Chainable @@ -11,6 +12,6 @@ declare global { } Cypress.Commands.add('connectWallet', () => { - cy.get(wallet.checkboxAcceptTerm).click() - cy.get(wallet.btnMetaMask).click() + cy.get(WalletLocators.chkAcceptTerm).click() + cy.get(WalletLocators.btnMetaMask).click() }) diff --git a/cypress/support/selectTokenCommands.ts b/cypress/support/selectTokenCommands.ts index 36c9a8a20b..098d334d3e 100644 --- a/cypress/support/selectTokenCommands.ts +++ b/cypress/support/selectTokenCommands.ts @@ -1,105 +1,105 @@ -import { getText, getTokenList } from '../e2e/pages/swap-page.po.cy' -import { notification, tab, token } from '../e2e/selectors/selectors.cy' +/* eslint-disable @typescript-eslint/no-namespace */ -export {} + +import { myCallbackType } from '../e2e/pages/swap-page.po.cy' +import { SwapPageLocators, TokenCatalogLocators } from '../e2e/selectors/selectors.cy' +export { } declare global { - namespace Cypress { - interface Chainable { - selectTokenInFavoriteTokensList(selector: string, value: string): Chainable - clickButton(selector: string): Chainable - input(selector: string, value: string): Chainable - selectTokenBySymbol(selector: string, value: string): Chainable - verifyURL(txtTokenIn: string, txtTokenOut: string): Chainable - verifySelectedToken(selector: string, value: string): Chainable - removeTokenInFavoriteTokensList(value: string): Chainable - verifyIcon(check: string): Chainable - verifyValueInList(selector: string, value: Array, exist: boolean): Chainable - addTokenToFavoriteTokensList(value: string): Chainable - verifyNoResultFound(): Chainable - importNewTokenByAddress(selector: string, address: string): Chainable - deleteImportedToken(address: string): Chainable - clearAllImportedTokens(): Chainable - } - } + namespace Cypress { + interface Chainable { + closeTutorialPopup(): Chainable + searchToken(value: string): Chainable + selectTokenIn(): Chainable + selectTokenOut(): Chainable + selectTokenBySymbol(value: string): Chainable + removeFavoriteToken(value: string): Chainable + addFavoriteToken(): Chainable + selectImportTab(): Chainable + importNewToken(address: string): Chainable + deleteImportedToken(value: string): Chainable + clearAllImportedTokens(): Chainable + selectFavoriteToken(tokenSymbol: string): Chainable + getContent(selector: string, callback: myCallbackType): Chainable + getList(selector: string, callback: myCallbackType): Chainable + } + } } -Cypress.Commands.add('clickButton', selector => { - cy.get(selector, { timeout: 30000 }).should('be.visible').click() +Cypress.Commands.add('closeTutorialPopup', () => { + cy.get(SwapPageLocators.btnSkipTutorial, { timeout: 30000 }).should('be.visible').click() }) -Cypress.Commands.add('verifySelectedToken', (selector, value) => { - cy.get(selector) - .invoke('text') - .then($text => { - $text.match(value) - }) +Cypress.Commands.add('selectTokenIn', () => { + cy.get(SwapPageLocators.dropdownTokenIn, { timeout: 30000 }).should('be.visible').click() }) -Cypress.Commands.add('input', (selector, value) => { - cy.get(selector).should('be.visible').type(value) +Cypress.Commands.add('selectTokenOut', () => { + cy.get(SwapPageLocators.dropdownTokenOut, { timeout: 30000 }).should('be.visible').click() }) -Cypress.Commands.add('selectTokenInFavoriteTokensList', (selector, value) => { - cy.get(selector, { timeout: 10000 }).contains(value).click() +Cypress.Commands.add('searchToken', (value) => { + cy.get(TokenCatalogLocators.txtToken).should('be.visible').type(value) }) -Cypress.Commands.add('selectTokenBySymbol', (selector, value) => { - cy.input(selector, value) - cy.get(token.rowInWhiteList, { timeout: 10000 }).eq(0).should('contain', value) - cy.get(token.rowInWhiteList).eq(0).click({ force: true }) +Cypress.Commands.add('selectTokenBySymbol', (value) => { + cy.get(TokenCatalogLocators.lblRowInWhiteList, { timeout: 10000 }).first().should('contain', value) + cy.get(TokenCatalogLocators.lblRowInWhiteList).first().click({ force: true }) }) -Cypress.Commands.add('removeTokenInFavoriteTokensList', value => { - cy.get(token.favoriteToken, { timeout: 10000 }) - .contains(value) - .parent() - .find(token.iconRemoveToken) - .click({ force: true }) +Cypress.Commands.add('removeFavoriteToken', (value) => { + cy.get(TokenCatalogLocators.lblFavoriteToken, { timeout: 10000 }) + .contains(value) + .parent() + .find(TokenCatalogLocators.iconRemoveFavoriteToken) + .click({ force: true }) }) -Cypress.Commands.add('verifyValueInList', (selector, value, exist) => { - getTokenList(selector, (arr: any) => { - if (exist === true) { - expect(arr).to.include.members(value) - } else { - expect(arr).not.to.include.members(value) - } - }) +Cypress.Commands.add('addFavoriteToken', () => { + cy.get(TokenCatalogLocators.lblRowInWhiteList).find(TokenCatalogLocators.iconFavorite).first().click({ force: true }) }) -Cypress.Commands.add('verifyIcon', checked => { - cy.get(token.rowInWhiteList).find(token.iconFavorite).eq(0).should('have.attr', 'data-active', checked) +Cypress.Commands.add('selectImportTab', () => { + cy.get(TokenCatalogLocators.btnImportTab, { timeout: 30000 }).should('be.visible').click() }) -Cypress.Commands.add('addTokenToFavoriteTokensList', value => { - cy.input(token.inputToken, value) - cy.verifyIcon('false') - cy.get(token.rowInWhiteList).eq(0).should('contain', value) - cy.get(token.rowInWhiteList).find(token.iconFavorite).eq(0).click({ force: true }) +Cypress.Commands.add('importNewToken', (address: string) => { + cy.searchToken(address) + cy.get(TokenCatalogLocators.btnImport).click() + cy.get(TokenCatalogLocators.btnUnderstand).click() }) -Cypress.Commands.add('verifyNoResultFound', () => { - cy.get(notification.notFound).should('have.text', 'No results found.') -}) +Cypress.Commands.add('deleteImportedToken', (value: string) => { + cy.selectImportTab() + cy.searchToken(value) + cy.wait(1000) + cy.get(TokenCatalogLocators.lblRowInWhiteList).children().find(TokenCatalogLocators.iconRemoveImportedToken).click() + cy.get(TokenCatalogLocators.txtToken).clear() -Cypress.Commands.add('importNewTokenByAddress', (selector, address) => { - cy.clickButton(selector) - cy.input(token.inputToken, address) - cy.get(token.btnImport).click() - cy.get(token.btnUnderstand).click() }) -Cypress.Commands.add('deleteImportedToken', address => { - cy.input(token.inputToken, address) - cy.get(token.rowInWhiteList).find(token.iconDelete).click() +Cypress.Commands.add('clearAllImportedTokens', () => { + cy.get(TokenCatalogLocators.btnClearAll, { timeout: 30000 }).should('be.visible').click() }) -Cypress.Commands.add('clearAllImportedTokens', () => { - cy.get(tab.import).click() - cy.get(token.clearAll).click() +Cypress.Commands.add('selectFavoriteToken', (tokenSymbol: string) => { + cy.get(TokenCatalogLocators.lblFavoriteToken, { timeout: 10000 }).contains(tokenSymbol).click() }) -Cypress.Commands.add('verifyURL', (txtTokenIn, txtTokenOut) => { - cy.url().should('contain', txtTokenIn.toLowerCase() + '-to-' + txtTokenOut.toLowerCase()) +Cypress.Commands.add('getContent', (selector: string, callback: myCallbackType) => { + cy.get(selector).invoke('text').then($text => { + callback($text) + }) }) + +Cypress.Commands.add('getList', (selector: string, callback: myCallbackType) => { + const arr: string[] = [] + const listData = cy.get(selector) + listData + .each(item => { + arr.push(item.text()) + }) + .then(() => { + callback(arr) + }) +}) \ No newline at end of file diff --git a/package.json b/package.json index bd982943b8..3e71b5286d 100644 --- a/package.json +++ b/package.json @@ -27,8 +27,8 @@ "start-dev": "vite --mode dev --host", "start-stg": "vite --mode stg --host", "start-prod": "vite --mode production --host", - "test-e2e": "synpress run -cf cypress.config.ts -c baseUrl=http://127.0.0.1:4173/ -e grepTags=smoke,grepFilterSpecs=true,grepOmitFiltered=true", - "test-schedule": "synpress run -cf cypress.config.ts -c baseUrl=https://kyberswap.com/ -e grepTags=regression,grepFilterSpecs=true,grepOmitFiltered=true" + "test-e2e": "synpress run -cf cypress.config.ts -c baseUrl=http://127.0.0.1:4173/", + "test-schedule": "synpress run -cf cypress.config.ts -c baseUrl=https://kyberswap.com/" }, "browserslist": [ "chrome >= 52",