示例:
FooGetRequest.feature文件的内容
* eval for (var i=0; i<foobarInDB.length; i++) call read('../features/BarGetRequest.feature') { foo_code:'#(foo_code)' , bar_code:'#(foobarInDB[i])'}
BarGetRequest.feature文件的外观如下:
Background:
* url baseUrl
Given path
"/v1/foo/"+foo_code+"/skus/"+bar_code+"/bar"
When method get
Then status 200
当我执行FooGetRequest.feature文件时,出现以下错误
[java.lang.RuntimeException: javascript evaluation failed: Expected ; but found read
答案 0 :(得分:1)
您可以在空手道中使用驱动数据驱动功能来多次遍历功能
假设foobarInDB
是bar_code
的数组,并且foo_code
将始终相同
* set foobarInDB[*].foo_code = foo_code
* call read('../features/BarGetRequest.feature') foobarInDB
答案 1 :(得分:1)
我写了一个小的Java脚本来返回一张类似{foo:bar}的地图
* def fun = function(x){return {foo :x }}
* def fooBarMap = karate.map(fooBarMap,fun)
* def validateResponse = call read('../features/BarGetRequest.feature) propertySkuMap
,然后在BarGetRequest.feature中相应地读取值。