purpletester
purpletester

Reputation: 47

jsonPath in scenario example

Could someone help me with below : Is it possble to use json path expression in the Scenario Outline examples?

Scenario Outline:Verify the path and description

Given url
When method GET
* match <path> == <description>

Examples:
|path|description|
|$.parent.child.description|"First child"|

Upvotes: 1

Views: 89

Answers (1)

Peter Thomas
Peter Thomas

Reputation: 58058

Yes, see example below:

Scenario Outline:
* def response = { foo: '1', bar: '2' }
* match <path> == '<expected>'

Examples:
| path  | expected |
| $.foo | 1        |
| $.bar | 2        |

But I strongly recommend you don't try to do this kind of "clever stuff" since it leads to maintainability issues in the long term. For an example of what I am referring to, see this example: https://stackoverflow.com/a/54126724/143475

Karate is very good at matching the entire JSON in one step and you will lost that advantage. Also your example has a serious problem because it will make a GET request for every row in the table.

So please write one Scenario for each "flow" you want to test as far as possible. Do not combine things too much. I am speaking from experience :)

Upvotes: 1

Related Questions