D02_用例中提取数据:extract 关键字简要说明
HttpRunner 编写用例的时候,支持从响应中提取需要的数据,赋值给变量或者进行断言等相关操作。
提取数据关键字:extract
支持的提取方式:
- regex 方式,通过正则表达式从 HTML 文本中提取指定内容。
如: <td width="\d{3}">(.*)</td>
- delimiter 方式,通过分隔符的方式从 JSON 或者 HTML 文本中获取内容。
如: content.data.authCodeToken
- jsonpath 方式,通过 jsonpath 表达式语法从 JSON 实体中提取内容。
如: $..price
\httprunner-2.5.5\httprunner\response.py:
三种提取方式对应的源码函数
class ResponseObject(object):
def _extract_field_with_jsonpath(self, field)
def _extract_field_with_regex(self, field)
def _extract_field_with_delimiter
另外,关于 HttpRunner 的各种问题,在GitHub的issues区域中查看,下图就是新添加 jsonpath 的反馈说明:
https://github.com/httprunner/httprunner/issues