cypress的hooks :
- before会在第一个用例之前运行,afeter会在跑完所有的用例之后运行。
- beforeEach会在每一个用例前运行,afterEach会在每一个用例结束后运行。
官网说明:https://docs.cypress.io/guides/core-concepts/writing-and-organizing-tests.html#Hooks
以下代码摘自官网。
beforeEach(() => {
// root-level hook
// runs before every test
})
describe('Hooks', () => {
before(() => {
// runs once before all tests in the block
})
beforeEach(() => {
// runs before each test in the block
})
afterEach(() => {
// runs after each test in the block
})
after(() => {
// runs once after all tests in the block
})
})
举例:
before(function () {
cy.log('run before');
});
after(function