automation.ninja.08
automation.ninja.08

Reputation: 95

Karate: is it possible to match the json from scenario outline

My use case is to have a Scenario Outline implemented with examples and my small Api returns a json output which I want to parameterize.

My use case is something like

Scenario Outline : test
    Given url "http://myurl.com"
    And params {"id": "<id>"}
    When method get
     Then match response == "<schema>"

Examples:
| id | schema |
| 123 | {"id":"#present"} |
| 456 | {"id":"#present", "name":"test"} |
| 789 | {"id": "#present", "value":"#present"} |

The problem her is examples are taken as string so the match fails here with error: as it is trying to now compare the response {"id":"#present"} with "{"id":"#present"}" and fails Any way to case it back to json when reading from examples. Help would be appreciated. Thank you

Upvotes: 1

Views: 1144

Answers (1)

Peter Thomas
Peter Thomas

Reputation: 58088

Add a ! after the column name. Refer: https://github.com/intuit/karate#scenario-outline-enhancements

Scenario Outline : test
  Given url "http://myurl.com"
  And params {"id": "#(id)"}
  When method get
  Then match response == schema

Examples:
| id! | schema! |
| 123 | {"id":"#present"} |
| 456 | {"id":"#present", "name":"test"} |
| 789 | {"id": "#present", "value":"#present"} |

Upvotes: 1

Related Questions