【问题标题】:Unable to validate response headers from a REST API using Karate无法使用空手道验证来自 REST API 的响应标头
【发布时间】:2021-02-22 23:04:48
【问题描述】:

我有一个简单的 REST API,它允许在给定端点中发布资源,并且我想验证响应标头是否设置正确。我定义了以下功能,在数据库中插入一堆用户:

  Scenario Outline: Creating a bunch of new users when the database is empty
    Given header Content-Type = 'application/json'
    And request __row
    When method post
    Then status 201
    * match header Content-Type == 'application/json'
    * match header Location == 'http://localhost:8080/users/'+response.id

    Examples:
      | users |

用户已正确插入,在控制台中我可以看到以下响应标头:

1 < 201
1 < Connection: keep-alive
1 < Content-Type: application/json
1 < Date: Mon, 22 Feb 2021 14:06:31 GMT
1 < Keep-Alive: timeout=60
1 < Location: http://localhost:8080/users/user1@test.com
1 < Transfer-Encoding: chunked

但每次我尝试运行此测试时,都会得到相同的响应:

path: $['Content-Type'][0], actual: null, expected: 'application/json', reason: actual json-path does not exist

【问题讨论】:

标签: rest testing karate


【解决方案1】:

在 0.9.6 上为我工作

* url 'https://httpbin.org/get'
* method get
* match header Content-Type == 'application/json'

但正如我在评论中提到的,请尝试 1.0 / RC 版本:https://github.com/intuit/karate/wiki/1.0-upgrade-guide

因为我们正在努力解决这个问题。

【讨论】:

  • 谢谢!我正在尝试 0.9.6 版(在 Windows 上),但使用 0.9.9.RC4 版一切正常
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2023-04-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多