空手道包含且所有键值均不匹配错误

时间:2019-01-10 12:07:37

标签: api karate

我尝试学习空手道,但是遇到了一些问题,我自己无法解决。

所以我的功能看起来很简单:

Feature: Alerting get the list of all alerts
  Background:
    * url 'url'

  Scenario: Retrieve all alerts

    Given path '5c348c553a892c000bb1f2dd'
    When method get
    Then status 200
    And match response contains {id: 5c348c553a892c000bb1f2dd}

这里的情况是获取响应并确保给定的ID在列表中。据我了解,这个documentation关键字仅应针对给定的短语进行查找,但出现错误:原因:所有键值均不匹配

这是我的控制台输出:

allAlertsGet.feature:10 - path: $, actual: {data={name=Baelish of Harrenhal, user=griffin, id=5c348c553a892c000bb1f2dd, tags=["Gared"], triggers={prometheus=[{"js_id":"Qarth","labels":["Harry Potter and the Sorcerer's Stone"],"operator":"==","query":"up","value":"1"}]}, trigger_interval=398s, receivers={slack=[{"holdoffTime":"0s","id":"Stalls","message":"Dark and difficult times lie ahead. Soon we must all face the choice between what is right and what is easy.","revokeMessage":"Every flight begins with a fall.","token":"Buckbeak"}]}, hold_cap=4, max_cap=16, factor=2, createDate=1546947669, triggered_date=1546948867, mute_until=0, muted=false, status=3}}, expected: {id=5c348c553a892c000bb1f2dd}, reason: all key-values did not match

我错过了什么?我使用空手道0.9.0。

1 个答案:

答案 0 :(得分:1)

请注意JSON的嵌套结构。您可以将此代码段粘贴到Scenario中并尝试一下,这是一个提示-您可以快速进行实验而无需发出HTTP请求,如下所示:

* def response = { data: { name: 'Baelish of Harrenhal', user: 'griffin', id: '5c348c553a892c000bb1f2dd' } }
* match response.data contains { id: '5c348c553a892c000bb1f2dd' }

编辑:只是为了展示其他一些断言方法:

* match response.data.id == '5c348c553a892c000bb1f2dd'
* match response..id contains '5c348c553a892c000bb1f2dd'

* def id = { id: '5c348c553a892c000bb1f2dd' }
* match response == { data: '#(^id)' }
* match response contains { data: '#(^id)' }