从 YAML 读取空手道配置

Read Karate config from YAML

我想在 .yml/.yaml 文件中定义特定于环境的属性。因此我创建了以下 test.yaml:

baseUrl:  'http://localhost:1234'

接下来我写了这个karate-config.js:

function() {
  var env = karate.env;
   if (!env) {
     env = 'test'; // default is test
   }
   // config =  read(env + '.yaml')
   var config = read('/home/user/git/karate-poc/src/test/java/test.yaml');
   // var config = read('test.yaml');
   // var config = read('classpath:test.yaml');
  return config;
}

如此处 https://github.com/intuit/karate#reading-files 空手道应该知道 read() 函数,但是我不确定这是否仅适用于 .feature 文件或 karate-config.js也。

不幸的是,上述 read() 中的 none 有效,因为我收到此错误:

Caused by: com.intuit.karate.exception.KarateException: javascript function call failed: could not find or read file: /home/user/git/karate-poc/src/test/java/test.yaml, prefix: NONE
    at com.intuit.karate.Script.evalFunctionCall(Script.java:1602)

我确定该文件存在并且可读。

是我做错了什么还是我的方法不受支持?如果不支持,推荐的方法是什么来从 YAML 文件(一次)读取基于环境的配置以便在(多个).feature 文件中使用它?

非常感谢

编辑:项目的树结构:

.
├── build.gradle
├── gradle
│   └── wrapper
│       ├── gradle-wrapper.jar
│       └── gradle-wrapper.properties
├── gradle.properties
├── gradlew
├── gradlew.bat
└── src
    └── test
        └── java
            ├── karate
            │   └── rest
            │       ├── rest.feature
            │       └── RestRunner.java
            ├── karate-config.js
            └── test.yaml

运行 与 ./gradlew test

在JS中,使用karate对象,这里解释为:https://github.com/intuit/karate#the-karate-object

所以这应该有效:

var config = karate.read('classpath:test.yaml');