javascript - 如何在空手道中使用 JavaScript 函数根据标签从 xml 中查找值
问题描述
如果我想获取空手道中某个元素的值,我可以使用“response //RecordA/RecordSequence”。如何使用以下方法在函数中获得相同的值。我已经尝试过 .getElementsByTagName、.find 和 karate.get,但它在基于标签查找特定值的函数下不起作用。任何帮助都可以根据功能下的标签找到价值。
Background:
* def myxml =
"""
function(tags)
{
var xmlValue= tags.getElementsByTagName("RecordA"); // Getting error as
.getElementsByTagName is not supported
return xmlValue;
}
"""
Given request
when soap action ''
Then status 200
* def resxml = response
* def myresult= myxml(resxml)
And assert result100 = '<expected_desc1>'|| result100 = '<expected_desc1>'
解决方案
干得好:
* def temp = <root><hello>world</hello></root>
* def fun = function(data){ return karate.xmlPath(data, '/root/hello') }
* def val = fun(temp)
* match val == 'world'
推荐阅读
- android - Asynctask 崩溃 ViewPager RecyclerView (Android)
- mysql - MariaDB:预定事件触发两次?
- amazon-web-services - 无法创建 AWS EC2 实例 sbin/plymouthd:没有这样的文件
- javascript - Math.floor 为什么这个四舍五入不正确?
- android - android导航清除任务
- jpa - 域被驱逐到 JAR 后 JPA @Inheritance 策略失败
- c# - 从哪里开始在 WPF 表单上生成按钮
- spring - 邮递员:创建复杂的 MULTIPART_FORM_DATA 请求
- python - 如何在单元(api)测试期间模拟/拦截外部 API 调用?
- javascript - 不使用 json_encode 从 PHP5.3 传输数据到 JS