Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
809 views
in Technique[技术] by (71.8m points)

karate - 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"|
question from:https://stackoverflow.com/questions/66056010/how-to-use-match-while-using-examples-section-with-column

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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 :)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...