cyrilgeorge153
cyrilgeorge153

Reputation: 773

null values in Scenario Outline under Examples is considered as string in Karate

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?

Upvotes: 1

Views: 1090

Answers (1)

Peter Thomas
Peter Thomas

Reputation: 58088

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' } |

Upvotes: 1

Related Questions