空手道:对于包含URL的Json数组,每个匹配失败

时间:2018-10-04 17:54:34

标签: karate

我正在尝试使用匹配每个函数来验证包含URL的Json数组。尝试执行此操作时出现错误提示

com.intuit.karate.exception.KarateException: path: $[0], actual: 'https://swapi.co/api/films/2/', expected: ["https:\/\/swapi.co\/api\/films\/2\/","https:\/\/swapi.co\/api\/films\/6\/","https:\/\/swapi.co\/api\/films\/3\/","https:\/\/swapi.co\/api\/films\/1\/","https:\/\/swapi.co\/api\/films\/7\/"], reason: actual value is not list-like
at com.intuit.karate.StepDefs.matchNamed(StepDefs.java:551)
at com.intuit.karate.StepDefs.matchEquals(StepDefs.java:537)
at ?.* match each response.films == response.films(C:\Users\r0m01iu\Documents\Projects\Space_Projects\QE_Workspace\api-testing-karate\target\test-classes\examples\swapi\people.feature:19)

功能文件:

Feature: Sample project with SWAPI

Scenario: Test some scenario

Given url 'https://swapi.co/api/people/1/'
When method get
Then status 200
* match each response.films == response.films

1 个答案:

答案 0 :(得分:1)

您的match断言根本没有任何意义。请仔细阅读文档和示例。另外,这里还有一些可行的示例:

Given url 'https://swapi.co/api/people/1/'
When method get
Then status 200
* match each response.films == '#string'
* match each response.films contains 'https://swapi.co/api/films/'
* match response contains { films: '#[] #string' }