尝试对 SSE 类型内容类型进行断言

trying to do assertion on SSE type content type

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'

有没有办法可以从这个 json.

中获取 groundNumber 和其他属性的值

提前致谢

您需要将这些东西转换成有效的 JSON。引用类型转换:https://github.com/intuit/karate#type-conversion

对于给定的响应,这会将多行转换为单个 JSON 数组。

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

现在可以进行正常的JsonPath处理了。

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