赛普拉斯 after() 仅在成功后调用
Cypress after() called only after success
我的 Web 应用程序有一个 cypress 测试,是一组块:
describe('Test Page X', function () {
before(function () {
cy.navigateTo('page-x', 0)
})
it ('should work', function(){
cy.doSomething()
})
after(function(){
cy.navigateBack()
})
})
问题是,after() 只在 it() 工作时被调用,如果 it() 由于页面 X 上的某些错误而失败,则 after() 不会被调用,结果,测试卡在了X页,Y、Z等页的后续测试也失败了。
我是不是做错了什么?如何制作总是被调用的after()?
可能有技术解决方案,但也有架构解决方案。
Cypress 不鼓励在测试后使用 after hooks 来清理状态。这基本上就是你现在所做的。
if it() failes because of some error on the page X, after() is not called, and as a result, the test got stuck on the page X, and the following tests for pages Y, Z etc. also fails.
这有一个简单的解决方案,您可以从挂钩之前或直接从测试导航到页面 Y、Z。
您可以查看有关此主题的 Cypress 推荐 here。
我的 Web 应用程序有一个 cypress 测试,是一组块:
describe('Test Page X', function () {
before(function () {
cy.navigateTo('page-x', 0)
})
it ('should work', function(){
cy.doSomething()
})
after(function(){
cy.navigateBack()
})
})
问题是,after() 只在 it() 工作时被调用,如果 it() 由于页面 X 上的某些错误而失败,则 after() 不会被调用,结果,测试卡在了X页,Y、Z等页的后续测试也失败了。
我是不是做错了什么?如何制作总是被调用的after()?
可能有技术解决方案,但也有架构解决方案。
Cypress 不鼓励在测试后使用 after hooks 来清理状态。这基本上就是你现在所做的。
if it() failes because of some error on the page X, after() is not called, and as a result, the test got stuck on the page X, and the following tests for pages Y, Z etc. also fails.
这有一个简单的解决方案,您可以从挂钩之前或直接从测试导航到页面 Y、Z。
您可以查看有关此主题的 Cypress 推荐 here。