Hook函数
Cypress提供了hooks函数,方便我们在组织测试用例的时候,有助于设置在一组测试之前或每个测试之前运行的条件,同样有助于在一组测试之后进行数据清理。
escribe('Hooks', () => {
before(() => {
// runs once before all tests in the block
})
after(() => {
// runs once after all tests in the block
})
beforeEach(() => {
// runs before each test in the block
})
afterEach(() => {
// runs after each test in the block
})
})
Hooks和测试执行的顺序如下:
- before()钩子运行,在所有测试用例前执行一次,作为准备条件;
- beforeEach()每个测试用例前都会运行
- it运行具体的测试用例
- afterEach()每个测试用例之后都会运行
- after()钩子运行,在所有测试用例后执行一次,作为清理条件;
原文链接:
https://www.cnblogs.com/yoyoketang/p/12883950.html