取消定位来自JSON文件

时间:2017-09-21 12:53:02

标签: json web-services automation karate

我正在使用空手道自动化工具进行服务自动化..我正在尝试从存储在变量中的json响应中提取部门ID ...

def departmentId = getstorewalk.departments [*]。id

getstorewalk是我存储json响应的变量

以下是json回复

{" walkzz":" 001"" ZZ":ZZ," DDD":" ZZ" " ZZ" {" ZZ":" ZZ""谁" {" ZZ":&# 34; 11"," zz":" zz"}},"部门":[{" id":需要提取这个id," name":" zz"," someorder":1," zzs":[{" zz&#34 ;:zz," name":" zz(zz,zz,zz,zz& zz)"," someorder":zz," zz":[{" zz":51," name":" zz Spread"," someorder":16,&# 34; ZZ":"可用"" ZZ":[{" ZZ":" 1223"" ZZ& #34;:" zz 30g"," zz":3," zz":0," zz":"陈旧& #34;" ZZ":假," ZZ":真," ZZ":[]," ZZ" {&# 34; ZZ":2" ZZ":" ZZ"" ZZ":6," zzName":&#34 ;核心zz(zz)","部门":56," zz":" 015 zz Spreads"," zz" :" zz Spread"," subzz":100," somezz":" zz& ZZ"" ZZ":{}," ZZ _":100}" ZZ" {" ZZ":&# 34; 2017-09-21T11:09:15.524Z""谁" {" ZZ":" 11"" ZZ&# 34;:" ZZ"}},"动作" {" ZZ":"包含"}" ZZ&#34 ;:[{" capturezz":375716," ZZ":"空位""数量":15," ZZ&# 34;:" ZZ"" ZZ" {" ZZ":" ZZ""类型":& #34; N""名称":" ZZ""序列":1}," ZZ" {&# 34; ZZ":" 211""谁" {" ZZ":" 11"" ZZ&# 34;:" ZZ"}}}]}]}]}]}]}

我在后台使用了以下内容:

  • def getstorewalk = callonce read(' classpath:zz / zz / zz.feature')
  • def departmentId = getstorewalk.departments [*]。id

错误如下: com.jayway.jsonpath.PathNotFoundException:路径$ [' departments']中缺少属性     在com.jayway.jsonpath.internal.path.PathToken.handleObjectProperty(PathToken.java:72)     在com.jayway.jsonpath.internal.path.PropertyPathToken.evaluate(PropertyPathToken.java:77)     在com.jayway.jsonpath.internal.path.RootPathToken.evaluate(RootPathToken.java:62)     在com.jayway.jsonpath.internal.path.CompiledPath.evaluate(CompiledPath.java:53)     在com.jayway.jsonpath.internal.path.CompiledPath.evaluate(CompiledPath.java:61)     在com.jayway.jsonpath.JsonPath.read(JsonPath.java:187)     在com.jayway.jsonpath.internal.JsonContext.read(JsonContext.java:164)     在com.jayway.jsonpath.internal.JsonContext.read(JsonContext.java:151)     at com.intuit.karate.Script.evalJsonPathOnVarByName(Script.java:339)     在com.intuit.karate.Script.eval(Script.java:262)     在com.intuit.karate.Script.eval(Script.java:182)     在com.intuit.karate.Script.assign(Script.java:606)     在com.intuit.karate.Script.assign(Script.java:537)     在com.intuit.karate.StepDefs.def(StepDefs.java:268)     在?。* def departmentId = getstorewalk.departments [*]。id(C:/Karate/zz/zz/src/test/java/zz/zz/zz.feature:11)

1 个答案:

答案 0 :(得分:0)

这对我有用,您可以尝试在空手道文件中粘贴下面的3行。顺便说一下,这是一个很好的故障排除技巧,您可以测试这样的代码片段,而无需进行HTTP调用。

19:40:55.135 [main] INFO  com.intuit.karate - [print] ["need to extract this id"]

记录:

getstorewalk

所以,显然你错误地将回复分配给def result = callonce read('classpath:zz/zz/zz.feature') def departmentId = result.response.departments[*].id

我的猜测是你打算这样做:

{{1}}

请仔细阅读有关调用其他功能文件的文档,您可能会意识到自己做错了什么。