空手道API框架如何将响应值与表格列匹配? [英] Karate API framework how to match the response values with the table columns?

查看:47
本文介绍了空手道API框架如何将响应值与表格列匹配?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下API响应示例

I have below API response sample

    {
  "items": [
             {
              "id":11,
              "name": "SMITH",
              "prefix": "SAM",
              "code": "SSO"
           },
          {
              "id":10,
              "name": "James",
              "prefix": "JAM",
              "code": "BBC"
          }
         ]
}

根据上述回复,我的测试表明,每当我访问API请求时,第11个ID为SMITH,第10个ID为JAMES

As per above response, my tests says that whenever I hit the API request the 11th ID would be of SMITH and 10th id would be JAMES

所以我想将其存储在表中并根据实际响应进行断言

So what I thought to store this in a table and assert against the actual response

  * table person
          | id        | name       |
          | 11        | SMITH      |
          | 10        | James      |
          | 9         | RIO        |

现在我将如何一一匹配?像第一个一样,它解析API响应中的第一个ID和名字,并与Tables第一个ID和表的名字匹配

Now how would I match one by one ? like first it parse the first ID and first name from the API response and match with the Tables first ID and tables first name

请从KARATE分享任何方便的方法

Please share any convenient way of doing it from KARATE

推荐答案

有几种可能的方法,这是一种:

There are a few possible ways, here is one:

* def lookup = { 11: 'SMITH', 10: 'James' }
* def items =
"""
[
   {
      "id":11,
      "name":"SMITH",
      "prefix":"SAM",
      "code":"SSO"
   },
   {
      "id":10,
      "name":"James",
      "prefix":"JAM",
      "code":"BBC"
   }
]
"""
* match each items contains { name: "#(lookup[_$.id+''])" }

并且您已经知道如何使用table而不是JSON.

And you already know how to use table instead of JSON.

请阅读文档和其他有关堆栈溢出的答案,以获取更多想法.

Please read the docs and other stack-overflow answers to get more ideas.

这篇关于空手道API框架如何将响应值与表格列匹配?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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