空手道包含且所有键值不匹配错误 [英] Karate contains and all key-values did not match error
问题描述
我尝试学习空手道,但有一些问题,我无法自己解决.
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 在列表中.据我了解这个 documentation 关键字包含应该只查找给定的短语,但我得到错误:原因:所有键值都不匹配
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屋!