Karate 尝试断言2个动态响应

Karate 尝试断言2个动态响应,karate,Karate,我有两种不同的回答: { "id": "U204204", "title": "Safety kit", "categoryPath": "/equipment/accessories/null", "keyFeature": false, "description": "test", "price": 24.5, "availability": "optional-extra", "technolo

我有两种不同的回答:

{
      "id": "U204204",
      "title": "Safety kit",
      "categoryPath": "/equipment/accessories/null",
      "keyFeature": false,
      "description": "test",
      "price": 24.5,
      "availability": "optional-extra",
      "technologyItems": [],
      "bespoke": false
    }

或/及

{
      "id": "GWW1WW1",
      "title": "Winter pack",
      "categoryPath": "/comfort & convenience/packs/null",
      "keyFeature": false,
      "description": "test",
      "price": 410,
      "availability": "optional-extra",
      "technologyItems": [],
      "bespoke": false
    }
现在我要强调的是,只要上面两个响应中的键price的值以“.5”结尾,就可以通过它

我尝试过以下和类似的方法,但不起作用:

Given path 'endpoint'
    And multipart file pdbData =  { read: 'json/PostRequest_201_3.json', filename: 'PostRequest_201_3.json', contentType: 'application/json'}
    When method post
    And status 201
    * def NewpdbId = response.id
    And path 'endpoint'+NewpdbId+'/V3FOY3DG'
    And method GET
    And status 200
    * string aa = response.options[13].price
    * string bb = response.options[16].price

    * def expected = aa contains "#redgex .+[.5]+" ? { pass: true  } 
    * def expected = bb contains "#regex .+[.5]+" ? { pass: true } 

    * string expected = expected


    And match expected == { pass: true }
因此,如果键price在任何响应中以“.5”结尾,则应为通过。如果键price是所有响应中的整数,那么它应该失败


有什么想法吗?我已经尝试了很多不同的方法

有几种方法。阅读以下文件:

首先,仅将
价格
值提取到列表中,转换为字符串(阅读文档了解):

* def prices = $response.options[*].price
* def fun = function(x){ return x + '' }
* def prices = karate.map(prices, fun)
* match prices contains '#regex .+[.5]+'