如果数据元素的顺序不同,则空手道匹配失败 [英] Karate match fails if the order of data elements is different
问题描述
我正在尝试验证Xml响应,其中一个父元素具有多个子元素,这些子元素具有相同的标签,但文本内容不同,如下所示:
I'm trying to validate an Xml response where one parent element has multiple child elements with the same tags but different text content like so:
Scenario: test
Given def expectation = <parent><child>1</child><child>2</child</parent>
And def reality = <parent><child>2</child><child>1</child></parent>
Then match reality == expectation
空手道应该不受数据元素顺序的影响,但是这种情况会失败.这是错误还是我忽略了什么?
Karate is supposed to not be affected by the order of data elements but this scenario fails. Is this a bug or am I overlooking something?
我知道我可能可以对每个子节点使用匹配包含",但是我实际上是在尝试验证更复杂的响应.
I know I could probably get away with using "match contains" for each of the child nodes but I'm actually trying to validate a much more complicated response.
提前感谢您的帮助!
推荐答案
好吧,如果将XML转换为JSON,也许可以更好地解释这一点:
Well, maybe this can be better explained if you convert the XML to JSON:
* json expect = expectation
* print json
哪个给您:
{
"parent": {
"child": [
"1",
"2"
]
}
}
另一个json是:
{
"parent": {
"child": [
"2",
"1"
]
}
}
所以您看到的问题是正确的,它们不相等,因此您必须进入包含
之类的东西.
So you see the problem right, they are not equal, and you have to get into contains
and all that.
Then match expectation/parent/child contains $reality/parent/child
如果您的XML相对没有属性复杂性,那么在转换为JSON时您可能会做一些疯狂的事情:
If your XML is relatively free of attribute complexity, you may be able to do some crazy things when you convert to JSON:
* def children = ['1', '2']
* def expected = { parent: { child: '#(^^children)' } }
* json actual = reality
* match actual == expected
这篇关于如果数据元素的顺序不同,则空手道匹配失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!