场景大纲中的零值在示例中被视为空手道中的字符串

发布于 2025-02-02 03:40:03 字数 715 浏览 2 评论 0原文

reqres.feature

Feature: Reqres api test cases
Scenario Outline: register user post -data driven test of negative scenarios
    Given url 'https://reqres.in/api'
    And path 'register'
    And def payload =
      """
      {
      "email": "<email>",
      "password": "<password>"
      }
      """
    And request payload
    When method post
    Then status 400
    * print response
    * match response == <errorResponse>

    Examples: 
      | email | password | errorResponse                          |
      | null  | null     | {"error": "Missing email or username"} |

因此我得到了响应{ “错误”:“注意:只有定义的用户成功注册” }而不是此响应{“错误”:“丢失电子邮件或用户名”}。如何解决这个问题?

reqres.feature

Feature: Reqres api test cases
Scenario Outline: register user post -data driven test of negative scenarios
    Given url 'https://reqres.in/api'
    And path 'register'
    And def payload =
      """
      {
      "email": "<email>",
      "password": "<password>"
      }
      """
    And request payload
    When method post
    Then status 400
    * print response
    * match response == <errorResponse>

    Examples: 
      | email | password | errorResponse                          |
      | null  | null     | {"error": "Missing email or username"} |

Because of this I am getting response {
"error": "Note: Only defined users succeed registration"
} instead of this response {"error": "Missing email or username"}. How to solve this issue?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

云之铃。 2025-02-09 03:40:03

Please spend some time reading the docs here: https://github.com/karatelabs/karate #场景外线 - 增强

我在下面重新编写了您的测试。请注意后缀在示例中的使用:列名。

Feature: reqres api test cases

  Scenario Outline: data driven test of negative scenarios
    Given url 'https://reqres.in/api'
    And path 'register'
    And request { email: '#(email)', password: '#(password)' }
    When method post
    Then status 400
    And match response == errorResponse

    Examples:
      | email! | password! | errorResponse!                         |
      | null   | null      | { error: 'Missing email or username' } |

Please spend some time reading the docs here: https://github.com/karatelabs/karate#scenario-outline-enhancements

I have re-written your test below. Note the use of the ! suffix in the Examples: column names.

Feature: reqres api test cases

  Scenario Outline: data driven test of negative scenarios
    Given url 'https://reqres.in/api'
    And path 'register'
    And request { email: '#(email)', password: '#(password)' }
    When method post
    Then status 400
    And match response == errorResponse

    Examples:
      | email! | password! | errorResponse!                         |
      | null   | null      | { error: 'Missing email or username' } |
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文