Skip to content

Commit

Permalink
refactor smoke tests (#2444)
Browse files Browse the repository at this point in the history
  • Loading branch information
hadothanh authored Dec 13, 2023
1 parent 9bbfb67 commit 6c9d99d
Show file tree
Hide file tree
Showing 13 changed files with 260 additions and 675 deletions.
130 changes: 1 addition & 129 deletions cypress.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,135 +27,7 @@ export default defineConfig({
// 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()
const prefix = 'e2e_cypress'
const suite = new client.Counter({
name: `${prefix}_suite`,
help: `${prefix}_suite`,
labelNames: ['buildId', 'result', 'baseName', 'duration', 'chain'] as const,
})
suite.reset()
const { totalPassed, totalFailed, totalTests, totalDuration, runs } = results
runs.forEach(run => {
const { stats, spec } = run
const { tests, passes, pending, failures, duration } = stats
const { baseName } = spec
suite
.labels({
buildId: `${process.env.GITHUB_RUN_ID}`,
result: 'failed',
baseName: baseName,
duration: duration,
chain: config.env.NETWORK,
})
.inc(failures)

suite
.labels({
buildId: `${process.env.GITHUB_RUN_ID}`,
result: 'passed',
baseName: baseName,
duration: duration,
chain: config.env.NETWORK,
})
.inc(passes)

suite
.labels({
buildId: `${process.env.GITHUB_RUN_ID}`,
result: 'pending',
baseName: baseName,
duration: duration,
chain: config.env.NETWORK,
})
.inc(pending)
suite
.labels({
buildId: `${process.env.GITHUB_RUN_ID}`,
result: 'tests',
baseName: baseName,
duration: duration,
chain: config.env.NETWORK,
})
.inc(tests)
})

suite
.labels({
buildId: `${process.env.GITHUB_RUN_ID}`,
result: 'passed',
baseName: 'All Specs',
duration: totalDuration,
chain: config.env.NETWORK,
})
.inc(totalPassed)

suite
.labels({
buildId: `${process.env.GITHUB_RUN_ID}`,
result: 'failed',
baseName: 'All Specs',
duration: totalDuration,
chain: config.env.NETWORK,
})
.inc(totalFailed)
suite
.labels({
buildId: `${process.env.GITHUB_RUN_ID}`,
result: 'total',
baseName: 'All Specs',
duration: totalDuration,
chain: config.env.NETWORK,
})
.inc(totalTests)

const testPass = new client.Counter({
name: `${prefix}_test_passed`,
help: `${prefix}_pass`,
labelNames: ['buildId', 'chain'] as const,
})

const testFail = new client.Counter({
name: `${prefix}_test_failed`,
help: `${prefix}_fail`,
labelNames: ['buildId', 'chain'] as const,
})

testPass.reset()
testFail.reset()

testFail.labels({ buildId: `${process.env.GITHUB_RUN_ID}`, chain: config.env.NETWORK }).inc(totalFailed)
testPass.labels({ buildId: `${process.env.GITHUB_RUN_ID}`, chain: config.env.NETWORK }).inc(totalPassed)

register.registerMetric(testPass)
register.registerMetric(testFail)
register.registerMetric(suite)

const gateway = new client.Pushgateway(`${process.env.CORE_PUSH_GATEWAY_URL}`, [], register)
await gateway
.push({ jobName: 'ui-automation' })
.then(({ resp, body }) => {
console.log(`Body: ${body}`)
console.log(`Response status: ${resp}`)
})
.catch((err: any) => {
console.log('err: ', err)
})
}
})
},
specPattern: 'cypress/e2e/specs/*.e2e.cy.ts',
excludeSpecPattern: '*/*/**/zap.e2e.cy.ts',
specPattern: 'cypress/e2e/specs/swap.e2e.cy.ts',
},
})
113 changes: 59 additions & 54 deletions cypress/e2e/pages/limit-order.po.cy.ts
Original file line number Diff line number Diff line change
@@ -1,59 +1,64 @@
import { LimitOrderLocators } from "../selectors/selectors.cy"
import { TokenCatalog } from "./swap-page.po.cy"
import { LimitOrderLocators } from '../selectors/selectors.cy'
import { TokenCatalog } from './swap-page.po.cy'

export interface myCallbackType<T> {
(myArgument: T): void
(myArgument: T): void
}
export const LimitOder = {
checkGetStartedDisplay() {
return cy
.get(LimitOrderLocators.btnGetStarted, { timeout: 10000 })
.should(() => {})
.then($obj => $obj.length > 0)
},

clickGetStarted() {
cy.get(LimitOrderLocators.btnGetStarted, { timeout: 10000 }).click({ force: true })
},

selectTokenSell(): TokenCatalog {
cy.selectToken(LimitOrderLocators.dropdownTokenSell)
return new TokenCatalog()
},
selectTokenBuy(): TokenCatalog {
cy.selectToken(LimitOrderLocators.dropdownTokenBuy)
return new TokenCatalog()
},

getCurrentTokenSell(text: myCallbackType<string>) {
cy.getContent(LimitOrderLocators.dropdownTokenSell, text)
},

getCurrentTokenBuy(text: myCallbackType<string>) {
cy.getContent(LimitOrderLocators.dropdownTokenBuy, text)
},

setSellAmount(value: string) {
cy.get(LimitOrderLocators.txtTokenSellAmount).type(value)
},

setSellingRate(text: string) {
cy.get(LimitOrderLocators.txtSellingRate).click().type(text)
},

getSellingRate() {
return cy.get(LimitOrderLocators.txtSellingRate).invoke('val')
},

getBalanceIn(text: myCallbackType<string>) {
cy.getContent(LimitOrderLocators.lblBalanceIn, text)
},
getSellAmount() {
return cy.get(LimitOrderLocators.txtTokenSellAmount).invoke('val')
},

checkGetStartedDisplay() {
return cy.get(LimitOrderLocators.btnGetStarted, { timeout: 10000 }).should(() => { }).then($obj => {
if ($obj.length > 0) {
return true
}
return false
})
},

clickGetStarted() {
cy.get(LimitOrderLocators.btnGetStarted, { timeout: 10000 }).click({ force: true })
},

selectTokenSell(): TokenCatalog {
cy.selectToken(LimitOrderLocators.dropdownTokenSell)
return new TokenCatalog()
},
selectTokenBuy(): TokenCatalog {
cy.selectToken(LimitOrderLocators.dropdownTokenBuy)
return new TokenCatalog()
},

getCurrentTokenSell(text: myCallbackType<string>) {
cy.getContent(LimitOrderLocators.dropdownTokenSell, text)
},

getCurrentTokenBuy(text: myCallbackType<string>) {
cy.getContent(LimitOrderLocators.dropdownTokenBuy, text)
},

setAmountIn(value: string) {
cy.get(LimitOrderLocators.txtTokenSellAmount).type(value)
},

setSellingRate(text: string) {
cy.get(LimitOrderLocators.txtSellingRate).click().type(text)
},

getSellingRate() {
return cy.get(LimitOrderLocators.txtSellingRate).invoke('val').then(value => {
return value
})
},

getBalanceIn(text: myCallbackType<string>) {
cy.getContent(LimitOrderLocators.lblBalanceIn, text)
},

getInsufficientErrorMessage() {
return cy.get(LimitOrderLocators.lblErrorMessage)
}
getInsufficientErrorMessage() {
return cy.get(LimitOrderLocators.lblErrorMessage)
},
setBuyAmount(amount: string) {
cy.get('#create-limit-order-input-tokenb input').click().type(amount)
},
getBuyAmount() {
return cy.get('#create-limit-order-input-tokenb input').invoke('val')
},
}
12 changes: 10 additions & 2 deletions cypress/e2e/pages/swap-page.po.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ export const SwapPage = {
cy.selectToken(SwapPageLocators.dropdownTokenOut)
return new TokenCatalog()
},
setAmountIn(amount: string) {
cy.get('[data-testid="token-amount-input"]').eq(0).clear().type(amount)
},
getAmountIn() {
return cy.get('[data-testid="token-amount-input"]').eq(0).invoke('val')
},

getCurrentTokenIn(text: myCallbackType<string>) {
cy.getContent(SwapPageLocators.dropdownTokenIn, text)
Expand All @@ -38,8 +44,10 @@ export const SwapPage = {
},

connectWallet() {
cy.get(WalletLocators.btnConnectWallet).should('be.visible').click()
cy.connectWallet()
if (Cypress.$('#web3-status-connected').length === 0) {
cy.get(WalletLocators.btnConnectWallet).should('be.visible').click()
cy.connectWallet()
}
},

getStatusConnectedWallet() {
Expand Down
2 changes: 1 addition & 1 deletion cypress/e2e/selectors/selectors.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export const WalletLocators = {
btnMetaMask: '[data-testid=connect-METAMASK]',
chkAcceptTerm: '[data-testid=accept-term]',
statusConnected: '[data-testid=web3-status-connected]',
lblBalance: '[data-testid=select-network] div div div'
lblBalance: '[data-testid=select-network] div div div',
}

export const NetworkLocators = {
Expand Down
37 changes: 0 additions & 37 deletions cypress/e2e/specs/connect-wallet.e2e.cy.ts

This file was deleted.

49 changes: 0 additions & 49 deletions cypress/e2e/specs/cross-chain.e2e.cy.ts

This file was deleted.

16 changes: 0 additions & 16 deletions cypress/e2e/specs/intercept.e2e.cy.ts

This file was deleted.

Loading

0 comments on commit 6c9d99d

Please sign in to comment.