As number of tests goes up need of tags also goes up. We have use case to run selected tests from multiple folders/features. It would be great if we can run them by tag. Currently It's only possible to add tag at file level.
These will allow me to run grunt nightwatch --tag tag9
module.exports = {
//tags: t1, t2, t3
'Demo test Google 1' : function (client) {
client
.url('http://google.no')
.end();
},
//tags: t1, t3, t9
'Demo test Google 2' : function (client) {
client
.url('http://google.no')
.end();
}
};
module.exports = {
'Demo test Google 1' : function (client, {tags: [t1, t2]}) {
client
.url('http://google.no')
.end();
},
'Demo test Google 2' : function (client, [t1, t3]) {
client
.url('http://google.no')
.end();
}
};
This feature already exists: http://nightwatchjs.org/guide#test-tags
Well what I was looking for is still not possible. For example please look at following simple test file. How do I run login only prod-ready tests by tag?
module.exports = {
tags: ['login', 'sanity', 'prod-ready'],
'demo login test': function (client) {
console.log('In login test');
client.end();
},
tags: ['checkout', 'sanity'],
'demo checkout test': function (client) {
console.log('In checkout test');
client.end();
},
tags: ['signup', 'sanity', 'prod-ready'],
'demo sign up test': function (client) {
console.log('In sign up test');
client.end();
}
};
I am having the same exact problem ^
Need a way to use different tags on test cases in the same file.
Same issue, need a way to use different tags on same file
@beatfactor can you re-open this one or provide an alternate solution?
Maybe this comment belongs in a new issue, but I'd rather not create a duplicate so starting here.
@beatfactor mentioned in another post that the feature to tag individual test cases within a module is not easily possible to implement in a consistent manner, so it seems like that won't happen anytime soon.
In the mean time: Has anyone come up with a good workaround for this? (where "this" = tagging a subset of test cases within a module(s) and then running (or excluding) all test cases with that tag)
This is not the most elegant solution, but here's a simple workaround:
const argv = require('minimist')(process.argv.slice(2))
module.exports = {
filterTaggedTests (testModule) {
const tagToExclude = argv['foo-tags-exclude']
if (tagToExclude) {
const filteredTestModule = {}
for (let testName in testModule) {
if (!testName.includes(`[${tagToExclude}]`)) {
filteredTestModule[testName] = testModule[testName]
}
}
return filteredTestModule
}
return testModule
}
}
In your spec file, wrap your tests:
const lib = require('../lib')
module.exports = lib.filterTaggedTests({
'Test A': function(){ ... },
'Test B [my-tag]': function(){ ... }
})
You can now exclude tests tagged my-tag by using the new option --foo-tags-exclude:
$ npm run e2e -- --foo-tags-exclude my-tag
I'm using the namespace foo to avoid collision with any existing or future cli option from nightwatch.
@beatfactor , this question is still relevant today. Is it possible to get a workaround that doesn't involve adding our own custom cli options?
Here are our use cases:
Most helpful comment
@beatfactor can you re-open this one or provide an alternate solution?