I need to pass a url to all tests executed in a createRunner. I have used args to do this executing tests from command line. Is there a way to pass a constant from the createRunner to tests executed? See createRunner below I am using. Thanks.
const fs = require('fs');
const createTestCafe = require('testcafe');
let testcafe = null;
let runner = null;
createTestCafe('localhost', 1337, 1338)
.then(tc => {
testcafe = tc;
runner = testcafe.createRunner();
return runner
// list multiple test files
.src([
'tests/login.js'
])
.browsers(['chrome'])
.concurrency(2)
.reporter('slack')
.run({
skipJsErrors: true,
quarantineMode: true,
selectorTimeout: 30000,
assertionTimeout: 10000,
pageLoadTimeout: 15000,
speed: 0.9
});
})
.then(failedCount => {
stream.end();
console.log('Tests failed: ' + failedCount);
testcafe.close();
});
A solution is to programmatically inject command-line args. Before returning the runner, insert these lines:
process.argv.push('--foo=bar');
process.argv.push('--yo');
In the test files use minimist to get your custom cli args.
Your question is also related to this one
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With