java - xmlPath 无法从 xml 中获取要列出的特定对象
问题描述
我最近开始使用 rest-assured 来测试一些 xmls。这是一个例子:
<activity>
<shopping>
<category type="groceries" label="chocolate" />
<category type="groceries" label="chocolate" />
<category type="present" label="chocolate" />
<container number="eight" color="green" />
</shopping>
<shopping>
<category type="groceries" label="chocolate" />
<category type="groceries" label="chocolate" />
<category type="present" label="chocolate" />
<container number="eight" color="green" />
</shopping>
<shopping>
<category type="groceries" label="chocolate" />
<category type="groceries" label="chocolate" />
<category type="present" label="chocolate" />
<container number="eight" color="green" />
</shopping>
</activity>
我想在这里实现的是检查每次购物是否有一个容器编号 =“八”,然后检查每个容器是否有颜色 =“绿色”。这是代码:
assertThat(xmlPath.getList("activity.shopping.list().container.findAll{it.@number == 'eight'}.@color", String.class), everyItem(equalTo("green")));
这工作得很好,当我调试它时,我得到了我想要达到的效果:
List <String> lista = xmlPath.getList("activity.shopping.list().container.findAll{it.@number == 'eight'}.@color", String.class);
这是一个三元素列表,其中每个元素都等于“绿色”。
但是,当我尝试检查每次购物是否有一个类别 type =“present”,然后检查这些类别中的每一个是否都有 label =“chocolate”时,我收到一个空列表:
List <String> lista2 = xmlPath.getList("activity.shopping.list().category.findAll{it.@type == 'present'}.@label", String.class);
我缺少什么或解决方案应该是什么样子的任何想法?非常感谢您的帮助。
解决方案
这是一个猜测,但也许你需要一个.list()
after .category
?
PS您可能打算调用变量container
...
推荐阅读
- mysql - mysql join查询查找最小值和最大值
- c# - 无法从 groupby 中获取值
- python - Python 读取文本文件不适用于 numpy/pandas
- java - 无法在 Weblogic 上部署
- rxjs - Rxjs。嵌套条件 observable 暂停“main” observable
- regex - 我试图在我的正则表达式中只选择 `<` 和 `-` 之间的内容
- asp.net-core - 错误的 appsettings 值在调试时进入 ConfigurationBuilder 对象
- python - 如何将 DateTime 对象与整数进行比较?
- python - 如果提交已经完成,你如何推送 pycharm?
- javascript - 验证在 Jquery 和 rails 中选择的复选框的长度