Cypress简介

Cypress

1
2
3
4
5
gi node >> .gitignore

npm init

npm i --save-dev cypress
1
vim package.json
1
2
3
4
5
6
{
"scripts": {
"e2e:open": "cypress open",
"e2e:run": "cypress run"
},
}
1
npm run e2e:open

Testing

1
vim cypress/integration/examples/window.spec.js
1
2
3
4
5
6
7
8
9
10
11
12
13
/// <reference types="Cypress" />

context('Window', () => {
beforeEach(() => {
cy.visit('https://domain.com')
})

it('cy.window() - login test', () => {
cy.get('#phone').type('123')
cy.get('#password').type('321')
cy.get('.ant-btn-primary').click()
})
})
1
2
3
npm run e2e:open

npm run e2e:run

Reporter

1
2
3
npm i --save-dev mocha mochawesome mochawesome-merge

vim cypress.json
1
2
3
4
5
6
7
8
{
"reporter": "mochawesome",
"reporterOptions": {
"reportDir": "cypress/report",
"html": true,
"json": false
}
}
1
npm run e2e:run

Git保留文件夹且忽略文件夹下所有文件的.gitignore配置

1
2
report/*
!report/.gitkeep

References