问题描述
是否可以仅使用一个模式来匹配嵌套数组响应的每个元素(使用contains)?
Is possible to match each element of a nested array response (using contains) using just one schema?
我有一组带有请求参数和响应模式的yml文件,如下所示:
I have a set of yml files with request params and response schemas, like this one:
response:
appId: '#string'
attributes: '#array'
login: '#string'
permissions: '#array'
metadata:
roles: '##array'
userData:
description: '#string'
employeeId: '#string'
employeeNumber: '##string'
id: '#string'
login: '#string'
mail: '#string'
name: '#string'
,然后在可重用功能中:
and then, in a reusable feature:
* def req = read(<testDataFile>)
* match response contains req.response
我只能用一个模式匹配嵌套对象,但是我不确定是否可以使用该模式来匹配嵌套数组
I can match nested objects with just one schema but I'm not sure if it's possible use the schema to match nested arrays
可能像这样:
response:
appId: '##string'
attributes: '##array'
attributes[*]:
key: '#string'
或任何其他表达式
非常感谢
推荐答案
您不能使用单个模式"来执行此操作,而必须将重复元素分别声明为空手道变量: https://github.com/intuit/karate#schema-validation
You can't do this with a single "schema" and you have to declare the repeating element separately, as a Karate variable: https://github.com/intuit/karate#schema-validation
* def foo = { a: '#number' }
* def bar = { baz: [{ a: 1 }, { a: 2 }, { a: 3 }] }
* match each bar.baz == foo
* match bar == { baz: '#[] foo' }
这篇关于空手道测试:如何匹配仅包含一个模式就包含了每个嵌套数组的响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!