我需要将URL传递给在createRunner中执行的所有测试。我已经使用args从命令行执行测试。有没有办法将常量从createRunner传递到执行的测试?请参阅下面我正在使用的createRunner。谢谢。
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();
});
答案 0 :(得分:3)
一种解决方案是以编程方式注入命令行参数。在返回跑步者之前,请插入以下行:
process.argv.push('--foo=bar');
process.argv.push('--yo');
在测试文件中,使用minimist
获取自定义的cli参数。
您的问题也是related to this one