Reputation: 11
Tried to execute the Smoke/Regression tests using the runner method. But need to pass the Smoke and Regression in "node testrunner.ts" command line. Refer the below code:
const createTestCafe = require('testcafe');
var argv = require('minimist')(process.argv.slice(2));
let suite = argv.suite;
const browser = argv.browser;
let testcafe = null;
let runner = null;
createTestCafe('localhost', 1337, 1338)
.then(tc => {
testcafe = tc;
runner = testcafe.createRunner();
return runner
.browsers(['chrome --window-size=1440,900'])
.filter((testName, fixtureName, fixturePath, testMeta, fixtureMeta) => {
suite = {
smoke: fixtureMeta.Smoke === 'true',
regression: fixtureMeta.Regression === 'true',
};
return suite;
})
.reporter('list')
.run();
})
.then(failedCount => {
console.log('Tests failed: ' + failedCount);
testcafe.close();
})
Executed the above code using node testrunner.ts --suite=regression
But it executes all the test from the package including the smoke testcases. Please let me know how to execute the testcases with respective suite name when pass from the command line.
Upvotes: 0
Views: 152
Reputation: 1669
According to the TestCafe documentation, the callback function that you passed to the filter method is called for each test in the source files. To include the current test, it should return true, to exclude it - false.
The callback function in your code example always returns the suite
variable, and it always contains a non-empty value, which JavaScipt casts to true
. That is why, TestCafe executes every test in your test suites.
To achieve the desired behavior, try to rewrite the callback function in the following way:
...
.filter((testName, fixtureName, fixturePath, testMeta, fixtureMeta) => {
return suite === 'regression' && fixtureMeta.Regression === 'true';
})
...
Upvotes: 1