空手道API测试-从响应中删除重复的值,并将其与新响应进行比较 [英] Karate API Testing- Remove duplicate values from the response and compare it with the new response

查看:42
本文介绍了空手道API测试-从响应中删除重复的值,并将其与新响应进行比较的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在一种情况下,我会收到重复的值.

I have a scenario where in response I receive duplicate values.

And def abcName =  $ListDataSet_Response.rowData[*].4

并打印abcName

And print abcName

 [
 "BP Part Sht NCA MS",
  "BP Part Sht NCA MS",
  "BP Part Sht NCA MS",
  "BP Part Sht NCA MS",
  "BP Part Sht NCA MS",
  "Bay Pond USB, Inc MS",
  "Bay Pond USB, Inc MS",
  "BP USB III Inc MS",
  "BP USB III Inc MS",
  "BP USB III Inc MS",
  "BP USB III Inc MS",
  "BP CS Sht NCA",
  "BP CS Sht NCA",
  "BP CS Sht NCA",
  "BP CS Sht NCA", 
  "BP USB IV, Inc MS",
  "BP Mrts Block NCA MS",
  "BP Mrts Block NCA MS"

  ]

现在我有一个功能,其中使用不同的值查询,我可以获得没有重复值的响应.执行该操作后.新响应为:

Now I have a feature where with distinct values query I can get response without duplicate values.After performing that operation .New response is:

  [
  "BP Part Sht NCA MS",
  "Bay Pond USB, Inc MS",
  "BP USB III Inc MS",
  "BP CS Sht NCA",
   "BP USB IV, Inc MS",
  "BP Mrts Block NCA MS",
  ]

现在,我需要在早期响应的情况下验证此响应,请记住,如果我从第一个响应中删除重复的值,它将是我的新响应(从不同的值查询中接收到).

Now I need to validate this response with the earlier one keeping in mind that if I remove duplicate values from the first response, it will be my new response (received from the distinct values quesry).

所有这些值都是运行时和动态的.

All these values are run time and dynamic.

到目前为止,我的方法:

My Approach till now:

第一:

  1. 将abcName存储在集合中(Java).它将删除重复项.
  2. 现在将其与新响应进行比较.

  1. Storing abcName in a set(Java). It will remove the duplicate.
  2. Now compare it with the new response.

这是不可行的,因为两者都是不同的类型.

This is not feasible as both are of different type.

第二:

将abcName存储在集合中(Java)

Storing abcName in a set(Java)

将第二个响应存储在另一个集合中(这会违背目的,因为它应该采用集合格式)

store second response in another set (This will go against the purpose as it should be in a set format)

第三:

将abcName存储在集合中(Java)

Storing abcName in a set(Java)

现在比较这两个列表

空手道有什么办法可以在不使用Java的情况下完成这项活动?

Is there any way in karate where without using Java we can do this activity?

推荐答案

* def response = 
"""
[
 "BP Part Sht NCA MS",
  "BP Part Sht NCA MS",
  "BP Part Sht NCA MS",
  "BP Part Sht NCA MS",
  "BP Part Sht NCA MS",
  "Bay Pond USB, Inc MS",
  "Bay Pond USB, Inc MS",
  "BP USB III Inc MS",
  "BP USB III Inc MS",
  "BP USB III Inc MS",
  "BP USB III Inc MS",
  "BP CS Sht NCA",
  "BP CS Sht NCA",
  "BP CS Sht NCA",
  "BP CS Sht NCA", 
  "BP USB IV, Inc MS",
  "BP Mrts Block NCA MS",
  "BP Mrts Block NCA MS"
]
"""
* json response = new java.util.HashSet(response)
* def expected =
"""
[
  "BP Part Sht NCA MS",
  "Bay Pond USB, Inc MS",
  "BP USB III Inc MS",
  "BP CS Sht NCA",
   "BP USB IV, Inc MS",
  "BP Mrts Block NCA MS",
]
"""
* match response contains only expected

这篇关于空手道API测试-从响应中删除重复的值,并将其与新响应进行比较的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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