Skip to content

Commit

Permalink
e2e:test: Add Zap In simulation (#2375)
Browse files Browse the repository at this point in the history
  • Loading branch information
hadothanh authored Nov 13, 2023
1 parent 0bb30ea commit 4cf2d56
Show file tree
Hide file tree
Showing 29 changed files with 1,559 additions and 395 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/cypress.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: 'Cypress Test'
name: 'E2E Smoke'

# concurrency:
# group: pr-workflow-${{ github.ref }}
Expand Down Expand Up @@ -116,7 +116,7 @@ jobs:
run: |+
#!/bin/bash
yarn preview &
yarn test-e2e -c baseUrl='http://127.0.0.1:4173/' -e grepTags=smoke,NETWORK=Ethereum
yarn test:e2e -c baseUrl='http://127.0.0.1:4173/' -e grepTags=smoke,NETWORK=Ethereum
env:
DISPLAY: :0.0

Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/schedule.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: 'E2E Testing Schedule'
name: 'E2E Regression'

on:
schedule:
Expand Down Expand Up @@ -54,7 +54,7 @@ jobs:
- name: Run Cypress Test
run: |+
#!/bin/bash
yarn test-schedule -c baseUrl='https://kyberswap.com/' -e grepTags=regression,NETWORK=${{ matrix.network }}
yarn test:e2e -c baseUrl='https://kyberswap.com/' -e grepTags=regression,NETWORK=${{ matrix.network }}
env:
DISPLAY: :0.0

Expand Down
12 changes: 12 additions & 0 deletions cypress.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,29 @@ export default defineConfig({
},
userAgent: 'synpress',
chromeWebSecurity: true,
// video: false,
// videoCompression: false,
viewportWidth: 1920,
viewportHeight: 1080,
env: {
grepFilterSpecs: true,
grepOmitFiltered: true,
},
e2e: {
testIsolation: false,
setupNodeEvents(on, config) {
// eslint-disable-next-line @typescript-eslint/no-var-requires
require('@cypress/grep/src/plugin')(config)
synpressPlugins(on, config)
const options = {
printLogsToFile: 'always',
outputRoot: config.projectRoot + '/target/',
specRoot: 'cypress/e2e/specs',
outputTarget: {
'cypress-logs|json': 'json',
},
}
require('cypress-terminal-report/src/installLogsPrinter')(on, options)
on('after:run', async results => {
if (results) {
const register = new client.Registry()
Expand Down
23 changes: 23 additions & 0 deletions cypress/e2e/pages/header.po.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import {
CrossChainLocators,
HeaderLocators,
LimitOrderLocators,
NetworkLocators,
SwapPageLocators,
TokenCatalogLocators,
WalletLocators,
} from '../selectors/selectors.cy'

export interface myCallbackType<T> {
(myArgument: T): void
}
export const Header = {
connectWallet() {
cy.get(WalletLocators.btnConnectWallet).should('be.visible').click()
cy.connectWallet()
},

getStatusConnectedWallet() {
cy.get(WalletLocators.statusConnected, { timeout: 10000 }).should('be.visible')
},
}
51 changes: 51 additions & 0 deletions cypress/e2e/pages/pools-page.po.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import { PoolLocators } from '../selectors/selectors.cy'

export enum CustomRange {
FullRange = 'Full Range',
Safe = 'Safe',
Common = 'Common',
Expert = 'Expert',
}
export type FarmingRange = {
minPrice: string
maxPrice: string
}
export const PoolsPage = {
open(chain: string) {
cy.visit('/pools/' + chain)
},
searchByPoolAddress(poolAddress: string) {
cy.get(PoolLocators.txtSearchPool).clear().type(poolAddress)
cy.wait(2000)
},
selectCustomRange(range: CustomRange) {
cy.get('button').contains(range).click()
},
selectFarmingRange(farmingRange: FarmingRange) {
cy.get('[role=button]').contains('Farming Ranges').click()
cy.get(PoolLocators.txtPriceValue).eq(0).clear().type(farmingRange.minPrice)
cy.get(PoolLocators.txtPriceValue).eq(1).clear().type(farmingRange.maxPrice)
},
getCurrentPrice() {
return cy
.get(PoolLocators.lblCurrentPrice)
.invoke('text')
.then(currenPriceValue => {
return currenPriceValue
})
},
addLiquidity(poolAddress: string, amountIn: string, customRange?: CustomRange, farmingRange?: FarmingRange) {
PoolsPage.searchByPoolAddress(poolAddress)
cy.get('button').contains('Add Liquidity').click()
cy.get(PoolLocators.btnZapIn).click()
if (typeof customRange != 'undefined') {
PoolsPage.selectCustomRange(customRange)
}
if (typeof farmingRange != 'undefined') {
PoolsPage.selectFarmingRange(farmingRange)
}
cy.get(PoolLocators.txtAmountIn).type(amountIn)
cy.wait(20000)
cy.go('back')
},
}
242 changes: 126 additions & 116 deletions cypress/e2e/pages/swap-page.po.cy.ts
Original file line number Diff line number Diff line change
@@ -1,127 +1,137 @@
import { CrossChainLocators, HeaderLocators, LimitOrderLocators, NetworkLocators, SwapPageLocators, TokenCatalogLocators, WalletLocators } from "../selectors/selectors.cy"
import {
CrossChainLocators,
HeaderLocators,
LimitOrderLocators,
NetworkLocators,
SwapPageLocators,
TokenCatalogLocators,
WalletLocators,
} from '../selectors/selectors.cy'

export const NETWORK = Cypress.env('NETWORK')

export interface myCallbackType<T> {
(myArgument: T): void
(myArgument: T): void
}

export const SwapPage = {
open(url: string) {
cy.visit('/' + url)
cy.url().should('include', url)
cy.closeTutorialPopup()
},

selectTokenIn(): TokenCatalog {
cy.selectToken(SwapPageLocators.dropdownTokenIn)
return new TokenCatalog()
},
selectTokenOut(): TokenCatalog {
cy.selectToken(SwapPageLocators.dropdownTokenOut)
return new TokenCatalog()
},

getCurrentTokenIn(text: myCallbackType<string>) {
cy.getContent(SwapPageLocators.dropdownTokenIn, text)
},

getCurrentTokenOut(text: myCallbackType<string>) {
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')
},

goToLimitOrder() {
cy.get(LimitOrderLocators.btnLimit).click()
},

goToCrossChain() {
cy.get(CrossChainLocators.btnCrossChain).click()
},

goToFarmPage() {
cy.get(HeaderLocators.dropdownEarn).click({ force: true })
cy.get(HeaderLocators.lblFarms).click({ force: true })
},

goToPoolPage() {
cy.get(HeaderLocators.dropdownEarn).click({ force: true })
cy.get(HeaderLocators.lblPools).click({ force: true })
},

goToMyPoolsPage() {
cy.get(HeaderLocators.dropdownEarn).click({ force: true })
cy.get(HeaderLocators.lblMyPools).click({ force: true })
},
open(url: string) {
cy.visit('/' + url)
cy.url().should('include', url)
cy.closeTutorialPopup()
},

selectTokenIn(): TokenCatalog {
cy.selectToken(SwapPageLocators.dropdownTokenIn)
return new TokenCatalog()
},
selectTokenOut(): TokenCatalog {
cy.selectToken(SwapPageLocators.dropdownTokenOut)
return new TokenCatalog()
},

getCurrentTokenIn(text: myCallbackType<string>) {
cy.getContent(SwapPageLocators.dropdownTokenIn, text)
},

getCurrentTokenOut(text: myCallbackType<string>) {
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')
},

goToLimitOrder() {
cy.get(LimitOrderLocators.btnLimit).click()
},

goToCrossChain() {
cy.get(CrossChainLocators.btnCrossChain).click()
},

goToFarmPage() {
cy.get(HeaderLocators.dropdownEarn).click({ force: true })
cy.get(HeaderLocators.lblFarms).click({ force: true })
},

goToPoolPage() {
cy.get(HeaderLocators.dropdownEarn).click({ force: true })
cy.get(HeaderLocators.lblPools).click({ force: true })
},

goToMyPoolsPage() {
cy.get(HeaderLocators.dropdownEarn).click({ force: true })
cy.get(HeaderLocators.lblMyPools).click({ force: true })
},
}

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 })
}
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: Array<string>) {
tokenSymbol.forEach(element => {
this.searchToken(element)
cy.wait(2000)
cy.addFavoriteToken()
});
}

removeFavoriteToken(tokenSymbol: string) {
cy.removeFavoriteToken(tokenSymbol)
}

importNewTokens(address: Array<string>) {
address.forEach(element => {
SwapPage.selectTokenIn()
cy.importNewToken(element)
})
}

deleteImportedToken(value: string) {
cy.deleteImportedToken(value)
}

clearAllImportedTokens() {
cy.clearAllImportedTokens()
}

getFavoriteTokens(list: myCallbackType<string[]>) {
cy.getList(TokenCatalogLocators.lblFavoriteToken, list)
}

getWhitelistTokens(list: myCallbackType<string[]>) {
cy.getList(TokenCatalogLocators.lblTokenSymbol, list)
}

getNoResultsFound(text: myCallbackType<string>) {
cy.getContent(TokenCatalogLocators.lblNotFound, text)
}
}
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: Array<string>) {
tokenSymbol.forEach(element => {
this.searchToken(element)
cy.wait(2000)
cy.addFavoriteToken()
})
}

removeFavoriteToken(tokenSymbol: string) {
cy.removeFavoriteToken(tokenSymbol)
}

importNewTokens(address: Array<string>) {
address.forEach(element => {
SwapPage.selectTokenIn()
cy.importNewToken(element)
})
}

deleteImportedToken(value: string) {
cy.deleteImportedToken(value)
}

clearAllImportedTokens() {
cy.clearAllImportedTokens()
}

getFavoriteTokens(list: myCallbackType<string[]>) {
cy.getList(TokenCatalogLocators.lblFavoriteToken, list)
}

getWhitelistTokens(list: myCallbackType<string[]>) {
cy.getList(TokenCatalogLocators.lblTokenSymbol, list)
}

getNoResultsFound(text: myCallbackType<string>) {
cy.getContent(TokenCatalogLocators.lblNotFound, text)
}
}
Loading

0 comments on commit 4cf2d56

Please sign in to comment.