我试图找出我是否能够有条件地跳过it()测试套件中的测试,并处理其异步特性。
我读过有关赛普拉斯文档条件测试https://docs.cypress.io/guides/core-concepts/conditional-testing.html它也mochajs文档https://mochajs.org/。
我的目的是检查网站上是否显示错误,如果没有,请跳过测试。否则,继续断言。
我试图在赛普拉斯中进行测试的mochajs的代码片段为:
it('should only test in the correct environment', function() {
if (/* check test environment */) {
// make assertions
} else {
this.skip();
}
});
Run Code Online (Sandbox Code Playgroud)
所以我在赛普拉斯拥有的是:
it('shows the list', function() {
if (queryFailed()) {
this.skip();
} else {
cy.get('.list')
.should('be.visible')
}
Run Code Online (Sandbox Code Playgroud)
请注意,我将我的arrow功能更改it()为a,function()以便可以使用this。
queryFailed() 是检查查询是否成功的函数。
function queryFailed() {
cy.get('.spin')
.then($container => {
const htmlLoaded = $container[0].innerHTML;
if (htmlLoaded.indexOf('List') !== -1) {
return false;
}
if …Run Code Online (Sandbox Code Playgroud)