首页 > 解决方案 > 在空手道框架中,无法通过解析获取 xml 响应中的值

问题描述

努力在我的 POC 中将空手道项目作为工具,这是我的要求 - http://www.mocky.io/v2/5d7267732f00004a007d4cb1

我在空手道中使用了下面的代码

Given url 'http://www.mocky.io/v2/5d7267732f00004a007d4cb1'
When method GET
Then status 200 
Then print response
And match response == expectedoutput

* def val = $expectedoutput/Group/Elements/Group/Elements/Group[0]/Elements/Set
And print 'value is' , val

它抛出一个错误 -

com.intuit.karate.exception.KarateException:userxmlDetails.feature:12 - xpath 不存在:/Group/Elements/Group/Elements/Group[0]/Elements/在✽的预期输出上设置。* def val = $expectedoutput/ Group/Elements/Group/Elements/Group[0]/Elements/Set (userxmlDetails.feature:12)

我也试过expectedoutput/Group/Elements/Group/Elements/Group[0]/Elements/Set

标签: karate

解决方案


对不起,如果这个问题看起来不成熟,但我解决了。我们需要提供以下

  • def val = $expectedoutput/Group/Elements/Group/Elements/Group[1]/Elements/Set

Group[0] 将不被接受,因为这里的索引从 1 开始。


推荐阅读