Reputation: 83
This is not a question. I just want to share my solution for running Testcafe tests in sequence with HTML reports. Running tests in parallel on different browsers was not a solution for me. I have to wait for tests on one env to finish, then to run on the next env. It took me a while to figure this out, but it works for me. If someone has better solution, please inform me.
Just add this code (with your specific custom settings) into a runner file. i.e. runner.js
and run it with node runner.js
command.
The solution:
const createTestCafe = require('testcafe');
const fs = require('fs');
const browsers = [
'chrome',
'firefox'
];
let stream = null;
const runTest = async browser => {
console.log('----------------- starting tests on ' + browser);
await createTestCafe('localhost', 1337, 1338)
.then(tc => {
testcafe = tc;
const runner = testcafe.createRunner();
return runner
.src([
"./smokeTests/someTests.js"
])
.browsers(browser)
.reporter('html', stream)
.run();
})
.then(async failedCount => {
console.log('Tests failed: ' + failedCount);
await testcafe.close();
return;
});
}
const runAllBrowsers = async () => {
for (const browser of browsers) {
stream = fs.createWriteStream('./testResults' +'/report_' + browser + '.html');
await runTest(browser);
await testcafe.close();
}
}
runAllBrowsers();
I used the original idea from https://github.com/DevExpress/testcafe/issues/2495. I'd like to thank nabrahamson for the original idea!
Upvotes: 3
Views: 550
Reputation: 4274
Thank you for sharing this solution with everyone.
You might want to contribute your sample to the testcafe-examples repo as well.
Upvotes: 1