在空手道测试框架中,$不打印json响应

时间:2020-11-05 21:39:28

标签: karate

使用https://github.com/intuit/karate,并使用下面的简单脚本,将在控制台上显示响应变量,但不会显示$快捷方式。

脚本

  Given url 'http://reqres.in/api/users/2'
  When method GET
  Then status 200   
  * print "Hello, world!"
  * print response
  * print $

输出

[ForkJoinPool-10-worker-3] 16:33:36.642 [print] Hello, world!
[ForkJoinPool-10-worker-3] 16:33:36.643 [print] {
  "ad": {
    "company": "StatusCode Weekly",
    "text": "A weekly newsletter focusing on software development, infrastructure, the server, performance, and the stack end of things.",
    "url": "http://statuscode.org/"
  },
  "data": {
    "last_name": "Weaver",
    "id": 2,
    "avatar": "https://s3.amazonaws.com/uifaces/faces/twitter/josephstein/128.jpg",
    "first_name": "Janet",
    "email": "janet.weaver@reqres.in"
  }
}
[ForkJoinPool-10-worker-3] 16:33:36.644 [print]

对于每个https://github.com/intuit/karate#response,我希望$是对响应的引用。

1 个答案:

答案 0 :(得分:0)

打印必须是“纯JS”,$仅对JsonPath表达式方便:https://github.com/intuit/karate#jsonpath-short-cuts