【发布时间】:2020-01-30 02:32:58
【问题描述】:
我最近开始使用 rest-assured 来测试一些 xml。这是一个例子:
<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);
我缺少什么或解决方案应该是什么样子的任何想法?非常感谢您的帮助。
【问题讨论】:
标签: java xml rest-assured