Skip to content

Commit

Permalink
Merge branch 'main' into feat/test-aggregator-stg
Browse files Browse the repository at this point in the history
  • Loading branch information
hanguyenk authored Sep 20, 2023
2 parents 7fc0810 + 43c6747 commit 40f5685
Show file tree
Hide file tree
Showing 258 changed files with 9,923 additions and 5,354 deletions.
2 changes: 1 addition & 1 deletion .babelrc
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@
}
]
],
"plugins": ["macros"]
"plugins": ["macros", "lodash"]
}
30 changes: 18 additions & 12 deletions .github/workflows/cypress.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,19 +48,19 @@ jobs:
REF_BRANCH=${REF/refs\/tags\//}
BRANCH=$REF_BRANCH
fi
echo "::set-output name=value::$BRANCH"
echo "value=$BRANCH" >> $GITHUB_OUTPUT
- name: Extract GitHub HEAD SHA
id: head_sha
run: echo "::set-output name=value::$(git rev-parse HEAD)"
run: echo "value=$(git rev-parse HEAD)" >> $GITHUB_OUTPUT

- name: Get Docker image tag
id: get_tag
env:
HEAD_SHA: ${{ github.event.pull_request.head.sha }}
run: |
short_sha="$(echo $HEAD_SHA | head -c7)"
echo "::set-output name=image_tag::adpr-$short_sha"
echo "image_tag=adpr-$short_sha" >> $GITHUB_OUTPUT
cypress-test:
runs-on: ubuntu-latest
Expand All @@ -87,39 +87,45 @@ jobs:
sudo apt-get install --no-install-recommends -y \
fluxbox \
xvfb
- name: Yarn Build
env:
CI: false
VITE_TAG: ${{ needs.prepare.outputs.image_tag }}
CURRENT_BRANCH: ${{ needs.prepare.outputs.current_branch }}
NODE_OPTIONS: '--max_old_space_size=4096'
run: yarn build-adpr

- name: Install cypress
run: yarn cypress install --force
run: yarn cypress install --force

- name: Run xvfb and fluxbox
run: |
Xvfb :0 -screen 0 1024x768x24 -listen tcp -ac &
fluxbox &
env:
DISPLAY: :0.0
DISPLAY: :0.0

- name: Create env file
run: |
touch .env
echo ENV=${ENV} > .env
echo CYPRESS_BASE_URL='http://127.0.0.1:4173/' > .env
- name: Run Cypress Test
run: |+
#!/bin/bash
yarn preview &
yarn test-e2e -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
- name: Archive e2e artifacts

- name: Archive e2e artifacts
uses: actions/upload-artifact@3cea5372237819ed00197afe530f5a7ea3e805c8
if: always()
with:
name: e2e-artifacts
path: |
cypress/videos
cypress/screenshots
continue-on-error: true
continue-on-error: true
54 changes: 25 additions & 29 deletions .github/workflows/schedule.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ name: 'E2E Testing Schedule'

on:
schedule:
- cron: '0 1,5 * * *' # run at 8AM and 12PM (GTM+7)
- cron: '*/20 1-12 * * *'
- cron: '0 13 * * *'
workflow_dispatch:

jobs:
Expand All @@ -11,7 +12,7 @@ jobs:
strategy:
fail-fast: false
matrix:
network: ['Ethereum', 'Arbitrum','Optimism', 'Avalanche', 'BNB']
network: ['Ethereum', 'Arbitrum', 'Optimism', 'Avalanche', 'BNB']
steps:
- name: Trigger Code Checkout
uses: actions/checkout@v3
Expand All @@ -30,44 +31,39 @@ jobs:

- name: Install linux deps
run: |
sudo apt-get install --no-install-recommends -y \
fluxbox \
xvfb
sudo apt-get install --no-install-recommends -y \
fluxbox \
xvfb
- name: Install cypress
run: yarn cypress install --force
run: yarn cypress install --force

- name: Run xvfb and fluxbox
run: Xvfb :0 -screen 0 1024x768x24 -listen tcp -ac &
fluxbox &
env:
DISPLAY: :0.0
DISPLAY: :0.0

- name: Create env file
run: |
touch .env
echo ENV=${ENV} > .env
echo GITHUB_RUN_ID=${GITHUB_RUN_ID} > .env
echo CORE_PUSH_GATEWAY_URL=${{ secrets.CORE_PUSH_GATEWAY_URL }} > .env
- name: Run Cypress Test
run: |+
#!/bin/bash
yarn test-schedule -e grepTags=regression,NETWORK=${{ matrix.network }}
env:
DISPLAY: :0.0

- name: Notify on failure
if: ${{ failure() }}
uses: rtCamp/action-slack-notify@v2
yarn test-schedule -c baseUrl='https://kyberswap.com/' -e grepTags=regression,NETWORK=${{ matrix.network }}
env:
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }}
SLACK_CHANEL: automation-test-bot
SLACK_COLOR: ${{ job.status }} # or a specific color like 'good' or '#ff00ff'
SLACK_ICON: https://icon-library.com/images/star-wars-icon-png/star-wars-icon-png-16.jpg?size=48
SLACK_TITLE: E2E Test ${{inputs.BASE_URL}}
SLACK_USERNAME: autoBot
SLACK_LINK_NAMES: true

- name: Archive e2e artifacts
DISPLAY: :0.0

- name: Archive e2e artifacts
uses: actions/upload-artifact@3cea5372237819ed00197afe530f5a7ea3e805c8
if: always()
with:
name: e2e-artifacts
path: |
cypress/videos
cypress/screenshots
name: e2e-artifacts
path: |
cypress/videos
cypress/screenshots
continue-on-error: true
128 changes: 124 additions & 4 deletions cypress.config.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import synpressPlugins from '@synthetixio/synpress/plugins'
import { defineConfig } from 'cypress'
import client from 'prom-client'

require('dotenv').config()

export default defineConfig({
projectId: '4x4jf8',
component: {
devServer: {
framework: 'create-react-app',
Expand All @@ -14,15 +16,133 @@ export default defineConfig({
viewportWidth: 1920,
viewportHeight: 1080,
env: {
grepFilterSpecs:true,
grepOmitFiltered:true
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)
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'
specPattern: 'cypress/e2e/specs/*.e2e.cy.ts',
},
})
46 changes: 46 additions & 0 deletions cypress/e2e/pages/farm-page.po.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { FarmLocators, HeaderLocators } from "../selectors/selectors.cy"

export class FarmPage {

getTvlValues() {
const arr: string[] = []
const listData = cy.get(FarmLocators.lblTvl)
listData
.each(item => {
arr.push(item.text().split('$')[1])
})
return arr
}

getAprValues() {
const arr: string[] = []
const listData = cy.get(FarmLocators.lblApr)
listData
.each(item => {
arr.push(item.text().split('%')[0])
})
return arr
}

countInvalidFarms(arrApr: string[], arrTvl: string[]) {
const totalFarms = arrApr.length
let count = 0;
for (let i = 0; i < totalFarms; i++) {
if (((arrTvl[i]) === undefined || Number(arrTvl[i]) === 0) && Number(arrApr[i]) === 0) {
count = count + 1;
}
}
return count
}

checkExistData() {
return cy.get(FarmLocators.lblApr, {timeout: 5000}).should(() => { }).then($obj => {
if ($obj.length > 0) {
return true
}
else {
return false
}
})
}
}
Loading

0 comments on commit 40f5685

Please sign in to comment.