Reputation: 71
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();
});
Upvotes: 3
Views: 667
Reputation: 3030
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
Upvotes: 4