空手道包含且所有键值均不匹配错误 [英] Karate contains and all key-values did not match error

查看:75
本文介绍了空手道包含且所有键值均不匹配错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I try to learn Karate but have some issue and I can't resolve it by myself.

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

So my Feature is looking rather simple:

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在列表中.据我了解,这个文档关键字只应查找给定短语,但是我得到了错误:原因:所有键值都不匹配

The case here is to fetch a response and make sure that given ID is on the list. As far I understand this documentation keyword contains should lookup only for the given phrase but I get an error: reason: all key-values did not match

这是我的控制台输出:

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.

What I have missed? I use karate 0.9.0.

推荐答案

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

Pay attention to the nested structure of your JSON. You can paste this snippet into a Scenario and try it, this is a tip - you can experiment quickly without making HTTP requests like this:

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

只是为了炫耀做断言的其他几种方法:

just to show off a few other ways to do assertions:

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

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

这篇关于空手道包含且所有键值均不匹配错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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