我试图通过使用Karate框架提供多个输入来验证响应。以下是示例功能文件。
Scenario Outline: response validation
Given url 'urls?xyz=[<value>]'
When method get
Then status <status>
And match response == [{abc:'<response>'},{pqr:'<response1>'}]
Examples:
| value | status | response | response1 |
| 3 | 200 | 3 | null |
| * | 400 | | Invalid xyz |
| 65 | 200 | | |
| &^%^&% | 400 | | Invalid xyz |
但是无法一次验证两个条件,其中一个参数将始终为null&abc&#39;或者&#39; pqr&#39;。以下是我得到的例外情况。
12:28:11.204 [pool-1-thread-1] DEBUG com.intuit.karate - response time in milliseconds: 742
12:28:11.276 [pool-1-thread-1] ERROR c.i.k.cucumber.KarateJunitFormatter - failed feature: path.my
java.lang.ClassCastException: java.util.LinkedHashMap cannot be cast to java.util.List
at com.intuit.karate.Script.matchNestedObject(Script.java:969)
at com.intuit.karate.Script.matchJsonPath(Script.java:871)
at com.intuit.karate.Script.matchNamed(Script.java:597)
at com.intuit.karate.StepDefs.matchNamed(StepDefs.java:463)
at com.intuit.karate.StepDefs.matchEquals(StepDefs.java:453)
at ✽.And match response == [{abc:'3'},{pqr:''}](path/my.feature:27)
答案 0 :(得分:0)
实际上我建议你经历一次这个例子,它会给你很多想法,并有不同的方法来解决这个问题:dynamic-params.feature
。例如,您可能希望使用params
关键字,而不是将查询参数连接到URL中。
根据我的经验,在Examples:
表中放置一个JSON片段比较简单:
And match response == <expected>
Examples:
| value | status | expected |
| 3 | 200 | [{abc:3},{pqr:null}] |
| * | 400 | [{pqr:'Invalid xyz'}] |