[英]rerun first test if second fails, mocha, javascript
I currently have 我目前有
describeA();
describeB();
both A and B have it() tests. A和B都有it()测试。 Is there a way to call describeA to run again, in describeB() after() function if any "it" fails in B? 如果B中有任何“失败”的地方,有没有办法在describeB()after()函数中调用describeA再次运行? So in describeB after function it would have: 因此,在describeB之后的函数中它将具有:
after(){
if(haveFailedTests)
// how to call run describeA();
}
You can override the it
function of all your individual tests like so: 您可以像这样覆盖所有单独测试的it
功能:
export function it(test: Function, retryCount: number = 4): (this: ITestCallbackContext, done: MochaDone) => any {
return function() {
for (let index = 0; index < retryCount; index++) {
try {
return test()
} catch (error) {
;(browser as any).logger.info(
`retry number ${index + 1}/${retryCount} for step "${error.message}" on it "${
this.test.title
}" and browser "${(browser.capabilities.browserName || '').toString()}"`
)
}
}
return test()
}
}
This use typescript, but the basic idea remains, wrap your function call with a try/catch
and rerun if it fails. 使用打字稿,但基本思想仍然存在,用try/catch
包裹函数调用,如果失败,则重新运行。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.