karate - 使用匹配内容类型为文本/纯文本的响应
问题描述
根据文档 - 响应自动作为 JSON、XML 或 String 对象可用,具体取决于响应内容是什么。
就我而言,我的响应内容类型为 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: 路径: $[*], 实际: ["abc match \"(\d{4}(0[1-9"], 预期: '["abc: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"]')
推荐阅读
- python - 如何通过熊猫结果显示每日直方图在pyecharts或其他?
- android - 我可以在华为 AppGallery 上发布的安卓应用中使用 Facebook Audience Network (FAN) 吗?
- c - 定义后如何重命名函数
- python - Django Authenticate 方法不适用于自定义模型
- c++ - 使用 dll 注入访问方法的参数
- php - Laravel 只从分页中获取数据
- ios - CollectionView 内容视图在 viewdidload 时不更新/刷新
- mysql - 基于 MySQL 分组属性的案例
- excel-formula - 使用 Google 表格公式自动增加发票编号
- r - 我可以使用 ggplot2 在特定数量的值范围内绘制一条水平线吗?