javascript - Karate :通过命令行传递动态参数值不起作用

标签 javascript karate

当我在命令行上运行 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/

相关文章:

javascript - 有没有办法使用 javascript 或 Jquery 找出某人计算机上屏幕的宽度?

javascript - 使用 OpenLayers 在 map 区域上创建框控件

javascript - 删除 <br> 以及相应的 <span>

javascript - 使用服务器时间戳和服务工作人员滞后的倒计时。怎么解决?

spring - Karate如何在Azure管道中启动应用程序?

java - 在 SSL url 上运行 Karate 时如何修复 'Unexpected end of ZLIB input stream' 错误

Karate - 如何仅在一个环境中运行特定场景?

karate - 使用多个参数调用特征文件

javascript - jQuery、CSS : Animating following DOM Elements after display: none

karate - 在 Karate 中通过标签并行运行功能