admin管理员组文章数量:1355697
I've been using nightwatch.js
for functional test automation. The problem is that the test is pausing when the test suite is finished. It doesn't end the process. The code looks like this :
var afterSuite = function(browser) {
dbFixture.deleteCollectionItemById(panyId, 'cilents');
dbFixture.deleteCollectionItemById(customerId, 'users');
dbFixture.deleteCollectionItemById(assetId, 'assets');
dbFixture.deleteFile(imageId);
browser.end();
};
var loginTest = function(browser) {
dbFixture.createCompany(function(pany) {
dbFixture.createCustomer(pany._id, function(customer, assetid, imageid) {
panyId = pany._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
};
I also tried adding done();
in afterSuite
but still no success. Thanks in advance!
I've been using nightwatch.js
for functional test automation. The problem is that the test is pausing when the test suite is finished. It doesn't end the process. The code looks like this :
var afterSuite = function(browser) {
dbFixture.deleteCollectionItemById(panyId, 'cilents');
dbFixture.deleteCollectionItemById(customerId, 'users');
dbFixture.deleteCollectionItemById(assetId, 'assets');
dbFixture.deleteFile(imageId);
browser.end();
};
var loginTest = function(browser) {
dbFixture.createCompany(function(pany) {
dbFixture.createCustomer(pany._id, function(customer, assetid, imageid) {
panyId = pany._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
};
I also tried adding done();
in afterSuite
but still no success. Thanks in advance!
4 Answers
Reset to default 7An approach is to register a global reporter
function that is run once all tests have finished and exits the process accordingly ie. if tests have failed or errored, exit 1
, otherwise exit 0
.
eg. http://nightwatchjs/guide#external-globals
In your nightwatch.json
config add:
{
"globals_path": "./config/global.js"
}
Then in ./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);
}
}
};
What was the root cause of this issue?
Using Josh's approach solves the issue, but then I'm not getting a junit report anymore.
in the latest global.js
script, is a tiny bug ... the property name is 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);
}
}
};
Small tweak over Martin Oppitz's answer; setTimeout
is necessary to give webdriver time to terminate. Otherwise, running it again will give a race condition.
// 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);
},
};
This can be run via nightwatch --reporter test/reporter.js
.
本文标签: javascriptnightwatchjs pausing at the end of test suiteStack Overflow
版权声明:本文标题:javascript - nightwatch.js pausing at the end of test suite - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1743950347a2567177.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论