我正在将测试从Intern.js迁移到Nightwatch.js,并且我确定这不是推荐编写测试的方式,但是我的测试异步进行了browser
命令调用(我的测试使用的类具有自己的命令队列)。 Nightwatch命令队列有时可以为空,具体取决于执行的内容,但最终将被填充。我需要一种方法来手动告诉Nightwatch完成时间,然后等到那时,否则浏览器将关闭得太早。
我可以做这样的事情:
finished() {
let done = false;
//will run at the end of my class's internal command queue
this.command
.then(() => {
done = true;
});
//will cause nightwatch to wait until my command queue is done
this.browser.perform(doneFn => {
const check = () => {
if (done) {
return doneFn();
}
setTimeout(check, 10);
}
check();
});
}
但是在这种情况下,perform()
将在等待10秒钟后超时,我似乎无法进行配置。否则,我可以运行约9秒的perform()
调用序列,但这听起来太hacky。我可以改写依赖于守夜命令队列,但是重写所有内容还需要做很多工作。
答案 0 :(得分:0)
最后,根据使用守夜人的命令队列来切换到它更容易。与Intern.js只是.then()
的一切都已以各种形式更改为.perform()
。