试图对SSE类型内容类型进行断言 [英] trying to do assertion on SSE type content type

查看:61
本文介绍了试图对SSE类型内容类型进行断言的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

这可以正常工作并正确断言,但这是包含的,我需要事先知道该值

并匹配jsonresponse.data._包含'00000000000000000000abc'

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'

并匹配jsonresponse.data._包含'123456789'

And match jsonresponse.data._ contains '123456789'

有没有一种方法可以从此json获取groundNumber的值和其他属性.

预先感谢

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

Thanks in advance

推荐答案

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

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

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

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

现在您可以执行常规的JsonPath处理.

Now you can do normal JsonPath processing.

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

这篇关于试图对SSE类型内容类型进行断言的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆