Karate API, How do I match 2 different responses

笑着哭i 提交于 2019-12-11 09:28:59

问题


I get 2 different responses from an endpoint depending on it's state and either one of them is fine.

first response:

{"available":'#boolean',"collection":'#boolean'}

second response:

{"code": "#string","message": "#string"}

I'm trying the following but it's not working:

  • def firstSchema = {"available":'#boolean',"collection":'#boolean'}
  • def secondSchema = {"code": "#string","message": "#string"}

match response contains any (firstSchema, secondSchema)

Any ideas how to best get this working so either response is fine?

Thanks


回答1:


Try this:

* def first = { available: true, collection: true }
* def second = { code: 'foo', message: 'bar' }

* def response = second
* def expected = response.code ? { code: '#string', 'message': '#string' } : { available: '#boolean', collection: '#boolean' }
* match response == expected

Also refer to the documentation on "Conditional Logic". You can use JsonPath to "check" what shape the response is and then define expected results.



来源:https://stackoverflow.com/questions/53542990/karate-api-how-do-i-match-2-different-responses

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!