【问题标题】:KARATE: Match each fails for Json Arrays containing URL空手道:匹配每个包含 URL 的 Json 数组失败
【发布时间】:2018-10-05 11:06:23
【问题描述】:

我正在尝试使用匹配每个函数来验证包含 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

【问题讨论】:

  • 欢迎回来。请先将此答案标记为已接受:stackoverflow.com/a/49804149/143475
  • 道歉@PeterThomas .. 这已经有一段时间了!! ..我已经接受了答案!!

标签: karate


【解决方案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' }

【讨论】:

  • 感谢您的回复 Peter.. 在这种情况下,您能否建议我如何断言 JSON 数组中的每个元素?
  • @RakeshMahendrakar 你读过文档吗? github.com/intuit/karate#match-each
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2023-03-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-11-23
  • 1970-01-01
相关资源
最近更新 更多