空手道测试:如何匹配仅包含一个模式就包含了每个嵌套数组的响应 [英] Karate Tests: How to match contains each nested array response with just one schema

查看:26
本文介绍了空手道测试:如何匹配仅包含一个模式就包含了每个嵌套数组的响应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以仅使用一个模式来匹配嵌套数组响应的每个元素(使用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'

或任何其他表达式

非常感谢

推荐答案

您不能使用单个模式"来执行此操作,而必须将重复元素分别声明为空手道变量:

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' }

这篇关于空手道测试:如何匹配仅包含一个模式就包含了每个嵌套数组的响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆