【问题标题】:Karate does not display a response after a POST request with status 201 [duplicate]空手道在状态为 201 的 POST 请求后不显示响应 [重复]
【发布时间】:2019-05-14 15:57:56
【问题描述】:

我正在努力进行以下测试,这通常很容易......

Feature: Testing Env Create Feature

  Scenario Outline: Create works as intended

    Given url "http://localhost:10000/api/envs"
    And request {"name": <Name>,"gcpProjectName": <GcpProjectName>,"url": <Url>}
    When method POST
    Then status 201
    And match response contains {"id": #string, "name": <Name>,"gcpProjectName": <GcpProjectName>,"url": <Url>}

    Examples:
      | Name     | GcpProjectName                | Url              |
      | tests    | D-COO-ContinuousCollaboration | https://fake.com |
      | approval | Q-COO-ContinuousCollaboration | https://fake.com |
      | demo     | P-COO-ContinuousCollaboration | https://fake.com |
      | prod     | P-COO-ContinuousCollaboration | https://fake.com |

我应该得到一个响应,总结我使用 curl、Postman 甚至 Swagger 成功获得的 POST 请求,但它不会出现在空手道中:

[failed features:
src.test.features.envtest.env-create: [1.1:13] env-create.feature:9 - path: $, actual: '', expected: '{"id":"#string","name":"tests","gcpProjectName":"D-COO-ContinuousCollaboration","url":"https://fake.com"}', reason: not a sub-string

有人知道会发生什么吗?

感谢您的帮助。

【问题讨论】:

    标签: json post request response karate


    【解决方案1】:

    只需在字符串替换周围添加引号:

    And request {"name": "<Name>", "gcpProjectName": "<GcpProjectName>", "url": "<Url>" }
    

    【讨论】:

    • 我对你的建议也有同样的问题,@PeterThomas 需要注意的一点是,即使我 * print response,也什么都没有出现。另一方面,* print responseHeaders 工作正常。这可能与 201 状态和空手道没有取回数据有关吗?我写了很多 POST 测试,在 200 状态下工作得很好,但这是我写的第二个涉及 201 状态和“不可见”响应的测试。
    • @Akro 我相信您可以从日志/JUnit HTML 报告中看到实际从服务器返回的内容。我没有其他建议。我确定您已经尝试过一个更简单的示例(没有Examples 等),并在尝试使事情复杂化之前看到了它的工作原理。如果你仍然卡住 - 请按照这个过程:github.com/intuit/karate/wiki/How-to-Submit-an-Issue
    猜你喜欢
    • 2012-03-01
    • 1970-01-01
    • 1970-01-01
    • 2019-01-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多