nightwatch.js在测试套件结束时暂停
nightwatch.js pausing at the end of test suite
我一直在使用nightwatch.js
进行功能测试自动化。问题是,当测试套件完成时,测试将暂停。它并没有结束这个过程。代码如下:
var afterSuite = function(browser) {
dbFixture.deleteCollectionItemById(companyId, 'cilents');
dbFixture.deleteCollectionItemById(customerId, 'users');
dbFixture.deleteCollectionItemById(assetId, 'assets');
dbFixture.deleteFile(imageId);
browser.end();
};
var loginTest = function(browser) {
dbFixture.createCompany(function(company) {
dbFixture.createCustomer(company._id, function(customer, assetid, imageid) {
companyId = company._id;
customerId = customer._id;
assetId = assetid;
imageId = imageid;
goTo.goTo(url.localhost_home + url.login, browser);
login.loginAsAny(customer.email, browser);
newCustomerLoginAssert.assertNewCustomerLogin(browser);
});
});
};
module.exports = {
after: afterSuite,
'As a Customer, I should be able to login to the system once my registration has been approved': loginTest
};
我还尝试在afterSuite
中添加done();
,但仍然没有成功。提前感谢!
一种方法是注册一个全局reporter
函数,该函数在所有测试完成后运行,并相应地退出进程,即如果测试失败或出错,则为exit 1
,否则为exit 0
。
例如。http://nightwatchjs.org/guide#external-全球
在nightwatch.json
配置中添加:
{
"globals_path": "./config/global.js"
}
然后在./config/global.js
中
module.exports = {
/**
* After all the tests are run, evaluate if there were errors and exit appropriately.
*
* If there were failures or errors, exit 1, else exit 0.
*
* @param results
*/
reporter: function(results) {
if ((typeof(results.failed) === 'undefined' || results.failed === 0) &&
(typeof(results.error) === 'undefined' || results.error === 0)) {
process.exit(0);
} else {
process.exit(1);
}
}
};
这个问题的根本原因是什么?
使用Josh的方法解决了这个问题,但我再也不会收到junit报告了。
在最新的global.js
脚本中,是一个小错误。。。属性名称为errors。
module.exports = {
/**
* After all the tests are run, evaluate if there were errors and exit appropriately.
*
* If there were failures or errors, exit 1, else exit 0.
*
* @param results
*/
reporter: function(results) {
if (
(typeof results.failed === 'undefined' || results.failed === 0) &&
(typeof results.errors === 'undefined' || results.errors === 0)
) {
process.exit(0);
} else {
process.exit(1);
}
}
};
对Martin Oppitz的回答进行了小调整;setTimeout
对于给web驱动程序终止的时间是必要的。否则,再次运行将产生比赛条件。
// test/reporter.js
const reporter = new HtmlReporter({
reportsDirectory: 'test/reports',
});
module.exports = {
write: function(results, options, done) {
const hasFailure =
(typeof results.failed !== 'undefined' && results.failed !== 0) ||
(typeof results.errors !== 'undefined' && results.errors !== 0);
const _forceExit = () => {
done();
// setTimeout is neccessary to give webdriver time to terminate.
setTimeout(() => {
if (hasFailure) {
return process.exit(1);
}
return process.exit(0);
}, 1000);
};
reporter.fn(results, _forceExit);
},
};
这可以通过nightwatch --reporter test/reporter.js
运行。
相关文章:
- 为什么“;未定义的“;在JavaScript中结束循环
- 循环结束/推送到数组之前在页面上呈现EJS
- 如何临时暂停浏览器渲染,然后恢复整个页面
- jQuery循环在特定位置暂停
- NodeJS-readline暂停和恢复事件发射器(逐行读取)
- 在另一个函数成功结束后调用该函数
- 最小化时暂停Javascript动画
- 在动画结束之前调用函数
- jQuery:暂停按钮可以暂停所有其他操作
- tiltSlider播放/暂停视频元素(如果li有当前类)
- Canvas+svg路径动画,在路径中的特定点暂停一段时间,然后继续
- 希望日期开始结束于while循环中的一个房间id的一个数组
- Facebook股票计数,暂停直到回调功能结束
- 在窗口大小调整事件开始时暂停 Greensock 动画,在调整大小事件结束时恢复动画
- 是否可以暂停while循环直到动画结束
- nightwatch.js在测试套件结束时暂停
- 使函数等待/暂停;直到另一个结束
- 无限自动上下滚动,如何控制/配置速度,结束时的暂停时间
- 在循环结束时添加暂停
- 如何区分两个“onpause”?事件-由点击“暂停”按钮引起,并由到达媒体片段的结束引起