trying to do assertion on SSE type content type

雨燕双飞 提交于 2020-02-28 23:47:21

问题


Scenario: Test
* def contentType = 'text/event-stream'
* def response =
"""
<data contentLength="5930" contentType="text/event-stream;charset=UTF-8"><![CDATA[
data:
}
}

This works and asserts correctly but this is contains and i would need to have the value known beforehand

And match jsonresponse.data._ contains '00000000000000000000abc'

This works and fails correctly but this is contains and i would need to have the value known beforehand

And match jsonresponse.data._ contains '123456789'

Is there a way where i can get the value for groundNumber and other attribute from this json.

Thanks in advance


回答1:


You need to convert that stuff into a valid JSON. Refer type conversion: https://github.com/intuit/karate#type-conversion

For the given response, this will convert the multiple rows into a single JSON array.

* def data = /data
* print data
* def data = data.replaceAll('data:', '').replaceAll('}', '},')
* json data = '[' + data + ']'
* print data

Now you can do normal JsonPath processing.

* def numbers = $data[*].groundNumber
* match numbers == ['00000000000000000000123', '00000000000000000000456', '00000000000000000000789', '00000000000000000000000']


来源:https://stackoverflow.com/questions/60121921/trying-to-do-assertion-on-sse-type-content-type

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