Scenario: Test
* def contentType = 'text/event-stream'
* def response =
"""
<data contentLength="5930" contentType="text/event-stream;charset=UTF-8"><![CDATA[
data:{"groundNumber":"00000000000000000000abc","BatchId":"245","StatusCode":"002","Status":"ACTIVE ","Code":"PF1 ","subCode":"999","sub":" ","StatusEffectiveDate":"","OpenDate":"","lobCode":" ","customerRelationshipCode":"OWN","ownerCustomerName":"TRENT INTERNATIONALE SCHOOL INC ","ownerECId":"0000534024","OwnerCode":" ","CostCenterCode":"000000","Address":{"addressTypeCode":" ","address":{"typeCode":" ","line1Address":" ","line2Address":" ","line3Address":" ","city":" ","stateCode":" ","postalCode":" ","country":" "}},"TitleLine1":" ","TitleLine2":" ","TitleLine3":" ","RelationshipManagerId":" ","withholdingStatus":"79 ","employeeIndicator":"N","currencyCode":" ","Code":"PBIF ","flag":"","name":"Intl Liquidity Funds"}
data:{"groundNumber":"00000000000000000000123","BatchId":"245","StatusCode":"005","Status":"CLOSED ","Code":"SLC ","subCode":"999","sub":" ","StatusEffectiveDate":"2016-05-11","OpenDate":"","lobCode":" ","customerRelationshipCode":"OWN","ownerCustomerName":"MARVIN C SCHWARTZ FAM ACCU TR # II ","ownerECId":"0093921608","OwnerCode":" ","CostCenterCode":" ","Address":{"addressTypeCode":" ","address":{"typeCode":" ","line1Address":" ","line2Address":" ","line3Address":" ","city":" ","stateCode":" ","postalCode":" ","country":" "}},"TitleLine1":" ","TitleLine2":" ","TitleLine3":" ","RelationshipManagerId":" ","withholdingStatus":"60 ","employeeIndicator":"N","currencyCode":" ","Code":"SLC ","flag":"","name":"Corporate Credit Car"}
data:{"groundNumber":"00000000000000000000456","BatchId":"245","StatusCode":"002","Status":"ACTIVE ","Code":"SL1 ","subCode":"999","sub":" ","StatusEffectiveDate":"2008-06-07","OpenDate":"2008-06-07","lobCode":"IVB ","customerRelationshipCode":"OWN","ownerCustomerName":"MARVIN C SCHWARTZ FAM ACCU TR # II ","ownerECId":"0093921608","OwnerCode":"CM","CostCenterCode":"834600","Address":{"addressTypeCode":" ","address":{"typeCode":" ","line1Address":" ","line2Address":" ","line3Address":" ","city":" ","stateCode":" ","postalCode":" ","country":" "}},"TitleLine1":" ","TitleLine2":" ","TitleLine3":" ","RelationshipManagerId":" ","withholdingStatus":"60 ","employeeIndicator":"N","currencyCode":" ","Code":"SLC ","flag":"","name":"Corporate Credit Car"}
data:{"groundNumber":"00000000000000000000789","BatchId":"245","StatusCode":"005","Status":"CLOSED ","Code":"BRZ ","subCode":"999","sub":" ","StatusEffectiveDate":"","OpenDate":"","lobCode":"IVB ","customerRelationshipCode":"OWN","ownerCustomerName":"US PAINTING SERVICES INC ","ownerECId":"0222518677","OwnerCode":"CM","CostCenterCode":"018320","Address":{"addressTypeCode":" ","address":{"typeCode":" ","line1Address":" ","line2Address":" ","line3Address":" ","city":" ","stateCode":" ","postalCode":" ","country":" "}},"TitleLine1":" ","TitleLine2":" ","TitleLine3":" ","RelationshipManagerId":" ","withholdingStatus":"79 ","employeeIndicator":"N","currencyCode":" ","Code":"BRZ ","flag":"","name":"Brazil "}
data:{"groundNumber":"00000000000000000000000","BatchId":"245","StatusCode":"005","Status":"CLOSED ","Code":"SST ","subCode":"999","sub":" ","StatusEffectiveDate":"2016-04-02","OpenDate":"","lobCode":" ","customerRelationshipCode":"OWN","ownerCustomerName":"RAO CAPITAL INVESTMENTS, LLC ","ownerECId":"0222547203","OwnerCode":" ","CostCenterCode":" ","Address":{"addressTypeCode":" ","address":{"typeCode":" ","line1Address":" ","line2Address":" ","line3Address":" ","city":" ","stateCode":" ","postalCode":" ","country":" "}},"TitleLine1":" ","TitleLine2":" ","TitleLine3":" ","RelationshipManagerId":" ","withholdingStatus":"62 ","employeeIndicator":"N","currencyCode":" ","Code":"SST ","flag":"","name":"Systems And Service "}
]]></data>
"""
And print response
And match each response == '#present'
And match $..groundNumber == '#present'
And match $..groundNumber == '123456789'
* json jsonresponse = response
And print jsonresponse
And match jsonresponse.data._ contains '00000000000000000000abc'
And match jsonresponse.data._ contains '123456789'
所以对我不起作用的是,我无法获取groundNumber的值。
这是SSE类型的内容,我不确定是否可以使用,我也尝试通过执行将其转换为Json的方法>
* json jsonresponse = response And print jsonresponse
但是这给了我这样的答复
{ "data": { "_": "data:{\"groundNumber\":\"00000000000000000000abc\",\"BatchId\":\"245\",\"StatusCode\":\"002\",\"Status\":\"ACTIVE \",\"Code\":\"PF1 \",\"subCode\":\"999\",\"sub\":\" \",\"StatusEffectiveDate\":\"\",\"OpenDate\":\"\",\"lobCode\":\" \",\"customerRelationshipCode\":\"OWN\",\"ownerCustomerName\":\"TRENT INTERNATIONALE SCHOOL INC \",\"ownerECId\":\"0000534024\",\"OwnerCode\":\" \",\"CostCenterCode\":\"000000\",\"Address\":{\"addressTypeCode\":\" \",\"address\":{\"typeCode\":\" \",\"line1Address\":\" \",\"line2Address\":\" \",\"line3Address\":\" \",\"city\":\" \",\"stateCode\":\" \",\"postalCode\":\" \",\"country\":\" \"}},\"TitleLine1\":\" \",\"TitleLine2\":\" \",\"TitleLine3\":\" \",\"RelationshipManagerId\":\" \",\"withholdingStatus\":\"79 \",\"employeeIndicator\":\"N\",\"currencyCode\":\" \",\"Code\":\"PBIF \",\"flag\":\"\",\"name\":\"Intl Liquidity Funds\"}\ndata:{\"groundNumber\":\"00000000000000000000123\",\"BatchId\":\"245\",\"StatusCode\":\"005\",\"Status\":\"CLOSED \",\"Code\":\"SLC \",\"subCode\":\"999\",\"sub\":\" \",\"StatusEffectiveDate\":\"2016-05-11\",\"OpenDate\":\"\",\"lobCode\":\" \",\"customerRelationshipCode\":\"OWN\",\"ownerCustomerName\":\"MARVIN C SCHWARTZ FAM ACCU TR # II \",\"ownerECId\":\"0093921608\",\"OwnerCode\":\" \",\"CostCenterCode\":\" \",\"Address\":{\"addressTypeCode\":\" \",\"address\":{\"typeCode\":\" \",\"line1Address\":\" \",\"line2Address\":\" \",\"line3Address\":\" \",\"city\":\" \",\"stateCode\":\" \",\"postalCode\":\" \",\"country\":\" \"}},\"TitleLine1\":\" \",\"TitleLine2\":\" \",\"TitleLine3\":\" \",\"RelationshipManagerId\":\" \",\"withholdingStatus\":\"60 \",\"employeeIndicator\":\"N\",\"currencyCode\":\" \",\"Code\":\"SLC \",\"flag\":\"\",\"name\":\"Corporate Credit Car\"}\ndata:{\"groundNumber\":\"00000000000000000000456\",\"BatchId\":\"245\",\"StatusCode\":\"002\",\"Status\":\"ACTIVE \",\"Code\":\"SL1 \",\"subCode\":\"999\",\"sub\":\" \",\"StatusEffectiveDate\":\"2008-06-07\",\"OpenDate\":\"2008-06-07\",\"lobCode\":\"IVB \",\"customerRelationshipCode\":\"OWN\",\"ownerCustomerName\":\"MARVIN C SCHWARTZ FAM ACCU TR # II \",\"ownerECId\":\"0093921608\",\"OwnerCode\":\"CM\",\"CostCenterCode\":\"834600\",\"Address\":{\"addressTypeCode\":\" \",\"address\":{\"typeCode\":\" \",\"line1Address\":\" \",\"line2Address\":\" \",\"line3Address\":\" \",\"city\":\" \",\"stateCode\":\" \",\"postalCode\":\" \",\"country\":\" \"}},\"TitleLine1\":\" \",\"TitleLine2\":\" \",\"TitleLine3\":\" \",\"RelationshipManagerId\":\" \",\"withholdingStatus\":\"60 \",\"employeeIndicator\":\"N\",\"currencyCode\":\" \",\"Code\":\"SLC \",\"flag\":\"\",\"name\":\"Corporate Credit Car\"}\ndata:{\"groundNumber\":\"00000000000000000000789\",\"BatchId\":\"245\",\"StatusCode\":\"005\",\"Status\":\"CLOSED \",\"Code\":\"BRZ \",\"subCode\":\"999\",\"sub\":\" \",\"StatusEffectiveDate\":\"\",\"OpenDate\":\"\",\"lobCode\":\"IVB \",\"customerRelationshipCode\":\"OWN\",\"ownerCustomerName\":\"US PAINTING SERVICES INC \",\"ownerECId\":\"0222518677\",\"OwnerCode\":\"CM\",\"CostCenterCode\":\"018320\",\"Address\":{\"addressTypeCode\":\" \",\"address\":{\"typeCode\":\" \",\"line1Address\":\" \",\"line2Address\":\" \",\"line3Address\":\" \",\"city\":\" \",\"stateCode\":\" \",\"postalCode\":\" \",\"country\":\" \"}},\"TitleLine1\":\" \",\"TitleLine2\":\" \",\"TitleLine3\":\" \",\"RelationshipManagerId\":\" \",\"withholdingStatus\":\"79 \",\"employeeIndicator\":\"N\",\"currencyCode\":\" \",\"Code\":\"BRZ \",\"flag\":\"\",\"name\":\"Brazil \"}\ndata:{\"groundNumber\":\"00000000000000000000000\",\"BatchId\":\"245\",\"StatusCode\":\"005\",\"Status\":\"CLOSED \",\"Code\":\"SST \",\"subCode\":\"999\",\"sub\":\" \",\"StatusEffectiveDate\":\"2016-04-02\",\"OpenDate\":\"\",\"lobCode\":\" \",\"customerRelationshipCode\":\"OWN\",\"ownerCustomerName\":\"RAO CAPITAL INVESTMENTS, LLC \",\"ownerECId\":\"0222547203\",\"OwnerCode\":\" \",\"CostCenterCode\":\" \",\"Address\":{\"addressTypeCode\":\" \",\"address\":{\"typeCode\":\" \",\"line1Address\":\" \",\"line2Address\":\" \",\"line3Address\":\" \",\"city\":\" \",\"stateCode\":\" \",\"postalCode\":\" \",\"country\":\" \"}},\"TitleLine1\":\" \",\"TitleLine2\":\" \",\"TitleLine3\":\" \",\"RelationshipManagerId\":\" \",\"withholdingStatus\":\"62 \",\"employeeIndicator\":\"N\",\"currencyCode\":\" \",\"Code\":\"SST \",\"flag\":\"\",\"name\":\"Systems And Service \"}", "@": { "contentLength": "5930", "contentType": "text/event-stream;charset=UTF-8" } } }
这可以正常工作并断言,但这是包含的,我需要事先知道该值
并且匹配jsonresponse.data._包含'00000000000000000000abc'
并且匹配jsonresponse.data._包含'123456789'
提前感谢
场景:测试* def contentType ='文本/事件流'* def响应=“”“
您需要将这些内容转换为有效的JSON。引用类型转换:https://github.com/intuit/karate#type-conversion