使用匹配内容类型为 text/plain 的响应

Using match with response with content type as text/plain

根据文档 - 响应会自动作为 JSON、XML 或字符串对象提供,具体取决于响应内容。

在我的例子中,我的响应内容类型为 text/plain

My server response is
["a.b.c:must match \"(\d{4}(0[1-9"]

这适用于我将字符串转换为响应然后验证(我已经转义了所有反斜杠)

 * string responseString = response
 * match responseString contains '["a.b.c match \"(\\d{4}(0[1-9"]'

这失败了。当响应也可以字符串形式提供时,为什么会失败

* match response contains '["a.b.c match \"(\\d{4}(0[1-9"]'

com.intuit.karate.exception.KarateException:路径:$[*],实际:["a.b.c match \"(\d{4}(0[1-9"],预期:'["a.b.c:must match \" (\d{4}(0[1-9"]',原因:实际值不包含预期

请将以下内容粘贴到一个新的场景中,看看它是否适合您自己。它应该可以帮助您解决问题:

* string response = '["a.b.c:must match \"(\d{4}(0[1-9"]'
* match response contains '["a.b.c:must match \"(\d{4}(0[1-9"]'
* assert response.contains('["a.b.c:must match \"(\d{4}(0[1-9"]')