【问题标题】:Karate Tests: How to match contains each nested array response with just one schema空手道测试:如何匹配仅包含一个模式的每个嵌套数组响应
【发布时间】:2023-03-23 09:37:01
【问题描述】:

是否可以仅使用一个模式来匹配嵌套数组响应(使用包含)的每个元素?

我有一组带有请求参数和响应模式的 yml 文件,如下所示:

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'

然后,在一个可重用的特性中:

* def req = read(<testDataFile>)
* match response contains req.response

我可以只用一个架构匹配嵌套对象,但我不确定是否可以使用架构来匹配嵌套数组

也许像:

response:
  appId: '##string'
  attributes: '##array'
  attributes[*]:
    key: '#string'

或任何其他表达方式

非常感谢

【问题讨论】:

    标签: karate


    【解决方案1】:

    您不能使用单个“模式”来执行此操作,您必须将重复元素单独声明为空手道变量: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' }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-07-04
      • 1970-01-01
      • 1970-01-01
      • 2019-04-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多