before/after介绍
<h1>1. 说明</h1>
<h2>1.1 before/after的使用域</h2>
<p>当有before/beforeeach/after/aftereach,以及嵌套的,那么其作用域与普通的语言编程的作用域是一样的道理,只在相应的范围内生效。参考ref1</p>
<pre><code class="language-javascript">before(() => {
// root-level hook
// runs once before all tests
})
beforeEach(() => {
// root-level hook
// runs before every test block
})
afterEach(() => {
// runs after each test block
})
after(() => {
// runs once all tests are done
})
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
})
})</code></pre>
<h2>1.2 日志中未发现afterall的执行</h2>
<p>根据reference文章中的说明,after的执行并不会单独显示,也不一定是在最后一个用例执行之后执行并在日志中显示,而且在恰当的位置。原句:after is actually executing in the right place, it is just not displaying with the right test. It's just a visual issue.</p>
<h1>2. Reference</h1>
<p>[1]. <a href="https://docs.cypress.io/guides/core-concepts/writing-and-organizing-tests#Hooks">作用域</a>
[2]. <a href="https://github.com/cypress-io/cypress/issues/405">after执行结果在日志中的体现</a></p>