Javascript 当上面的it块失败时,如何不执行it块
假设在描述块中有一个描述块和两个it块Javascript 当上面的it块失败时,如何不执行it块,javascript,automation,protractor,Javascript,Automation,Protractor,假设在描述块中有一个描述块和两个it块 describe(""){ it(""){ } //if this block fails script should not execute next block it(""){ } } 若第一个it块失败,则脚本不应执行下一个it块。如何在量角器中实现这一点。请提供帮助。示例: 我建议您将第二个和第三个expect封装在try/catch中,一个用于两个或每个,并手动处理捕获的错误,然后使用Jasmine的fai
describe(""){
it(""){
} //if this block fails script should not execute next block
it(""){
}
}
若第一个it块失败,则脚本不应执行下一个it块。如何在量角器中实现这一点。请提供帮助。示例:
我建议您将第二个和第三个expect封装在try/catch中,一个用于两个或每个,并手动处理捕获的错误,然后使用Jasmine的fail()失败。您可以将块封装在
try-catch
中。然后,您可以使用一些布尔值来检查第一个it块是否成功执行,以及第二个it块是否成功执行
describe(""){
try{
var firstSuccess = false;
it(""){
//do whatever...
firstSuccess = true; //set firstSuccess to true at end of it block
} //if this block fails script should not execute next block
if(firstSuccess){ //execute second it block only after first it executes successfully
it(""){
}
}
}catch(err){
//handle error here
}
}
您不能将代码包装到
try…catch
块中吗?
describe(""){
try{
var firstSuccess = false;
it(""){
//do whatever...
firstSuccess = true; //set firstSuccess to true at end of it block
} //if this block fails script should not execute next block
if(firstSuccess){ //execute second it block only after first it executes successfully
it(""){
}
}
}catch(err){
//handle error here
}
}