我只是想知道如何进行条件模式验证。API响应是基于customerType键的动态响应。如果customerType是person,则将包括人员详细信息,如果customerType是org组织详细信息,则将包含在JSON响应中。因此,响应可以以下列任一形式出现
{
"customerType" : "person",
"person" : {
"fistName" : "A",
"lastName" : "B"
},
"id" : 1,
"requestDate" : "2021-11-11"
}{
"customerType" : "org",
"organization" : {
"orgName" : "A",
"orgAddress" : "B"
},
"id" : 2,
"requestDate" : "2021-11-11"
}我为验证上述2种场景而创建的模式如下
{
"customerType" : "#string",
"organization" : "#? response.customerType=='org' ? karate.match(_,personSchema) : karate.match(_,null)",
"person" : "#? response.customerType=='person' ? karate.match(_,orgSchema) : karate.match(_,null)",
"id" : "#number",
"requestDate" : "#string"
}但是,模式无法与实际响应匹配。我应该对模式进行哪些更改以使其正常工作?
Note : I am planning to reuse the schema in multiple tests so I will be keeping the schema in separate files, independent of the feature file发布于 2021-11-17 08:05:35
你能参考我认为更好的方法:https://stackoverflow.com/a/47336682/143475的答案吗?
尽管如此,我认为您忽略了JS karate.match() API不返回布尔值,而是返回包含pass布尔属性的JSON。
所以你必须这样做:
* def someVar = karate.match(actual, expected).pass ? {} : {}https://stackoverflow.com/questions/70000610
复制相似问题