Karate 如何在空手道中使用js EXPR和XML
我必须修改xml表达式并将其与json匹配。下面是我写的代码。我需要验证Karate 如何在空手道中使用js EXPR和XML,karate,Karate,我必须修改xml表达式并将其与json匹配。下面是我写的代码。我需要验证ind是否为真。为此,我不能使用“#boolean”,因为true的行为类似于字符串 XML文件: <ns9:parent xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ns5:parent"> <ns4:ind>true</ns4:ind> <ns4:descripti
ind
是否为真。为此,我不能使用“#boolean”
,因为true
的行为类似于字符串
XML文件:
<ns9:parent xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ns5:parent">
<ns4:ind>true</ns4:ind>
<ns4:description>Some text</ns4:description>
</ns9:parent>
* def Test = call read ('classpath:Path/Test.xml)
* def Check = $Test/parent
* set Downstream.parent
| path | value |
| ind | '#?_ == "true" || _== "false"' |
| description | $Check/parent/description |
* def Match =
"""
{
"parent": {
"ind": "true",
"description": "Some text"
}
}
"""
* match Match == Downstream
尝试使用“#boolean”
也不起作用
| ind | '#boolean' |
我得到下面的错误
com.intuit.karate.exception.KarateException: Test.feature:20 - javascript evaluation failed: '#?_ == "true", <eval>:1:14 Missing close quote '#?_ == "true"
com.intuit.karate.exception.karate exception:Test.feature:20-javascript评估失败:“#?==”真“,:1:14缺少右引号“#?==”真“
这应该行得通
* def Test = call read ('classpath:Path/Test.xml')
* def Check = $Test/parent
* xml Downstream = "<parent></parent>"
* def desc = $Check/parent/description
* set Downstream/parent/ind = '#?_ == "true" || _== "false"'
* set Downstream/parent/description = desc
* match $Test/parent/ind == $Downstream/parent/ind
* match $Test/parent/description == $Downstream/parent/description
*def Test=调用读取('classpath:Path/Test.xml')
*def检查=$Test/父级
*xml下游=“”
*def desc=$Check/父项/说明
*设置下游/parent/ind='#?==“真”| |==“假”'
*设置下游/父级/描述=描述
*匹配$Test/parent/ind==$down/parent/ind
*匹配$Test/parent/description==$down/parent/description
注:
XML的集合似乎不支持表,所以请使用内联集合
很抱歉,您的示例不完整且有拼写错误。修正它,简化它,请更清晰地编辑;提供的详细信息看起来足以复制问题。您能够运行此代码吗?您正在为下游设置值,但没有定义它。由于无法提供适当的示例,请按照以下说明操作:@BabuSekaran是的,该函数工作正常,但出现错误,
com.intuit.karate.exception.karate exception:Test.feature:20-javascript计算失败:'#?==“true”,:1:14缺少右引号'#?==“true”
我正在调用存储在此文件中的xml:*def Test=call read('classpath:Path/Test.xml)