当我在命令行上运行 Karate 集成测试时,我试图从命令行传递一个 URL。我看了看this并试图做同样的事情,但到目前为止还没有运气。
我有这个karate-config.js
文件
function karateconf() {
karate.configure('connectTimeout', 5000);
karate.configure('readTimeout', 5000);
var config = { baseURL: 'http://localhost:8080' };
if (karate.env == 'ci') {
config.baseURL = karate.properties['base.URL'];
karate.log('*******************************', karate.properties['base.URL']);
}
return config;
}
我像这样使用 gradle 运行测试
./gradlew integrationTest -Dkarate.env=ci -Dbase.URL=http://someurl:8080
这是 Karate 日志
14:12:54.599 [pool-1-thread-1] INFO com.intuit.karate - ******************************* null
14:12:54.827 [pool-1-thread-1] ERROR com.intuit.karate - url not set, please refer to the keyword documentation for 'url'
14:12:54.827 [pool-1-thread-1] ERROR com.intuit.karate - http request failed: url not set, please refer to the keyword documentation for 'url'
14:12:54.836 [pool-1-thread-1] INFO c.i.karate.cucumber.CucumberRunner - <<<< feature 1 of 1 on thread pool-1-thread-1: com/guidewire/lifecycle/controller/configuration-controller.feature
14:12:55.359 [Test worker] INFO n.m.cucumber.ReportParser - File '/workspace/configuration-service/configuration-infrastructure/app-backend/lifecycle/target/surefire-reports/TEST-com.guidewire.lifecycle.controller.configuration-controller.json' contain 1 features
我无法弄清楚我在这里缺少什么。
最佳答案
Gradle ?这包含在文档中:https://github.com/intuit/karate#command-line - 看起来你需要添加 base.URL
以与以下相同的方式添加到您的 gradle 构建文件:
For gradle you must extend the test task to allow the cucumber.options to be passed to the Cucumber-JVM (otherwise they get consumed by gradle itself). To do that, add the following:
test {
// pull cucumber options into the cucumber jvm
systemProperty "cucumber.options", System.properties.getProperty("cucumber.options")
// pull karate options into the jvm
systemProperty "karate.env", System.properties.getProperty("karate.env")
// ensure tests are always run
outputs.upToDateWhen { false }
}
关于javascript - Karate :通过命令行传递动态参数值不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50489466/