httprunner1.x 断言-equal

没有断言的接口测试是不完整的。

接口就算运行成功,也不代表返回的接口信息正确。

断言的作用就是将预期的返回结果与实际的返回结果做对比,如果匹配则允许成功,如果不匹配则证明该接口运行失败。

以xx.yml文件为例

 断言的格式如下:

自己测试成功的demo:

1.在生成的xx.yml文件中添加断言信息,如上图

2.在cmd命名行执行:hrun xx.yml  --log-level info

3.查看生成的报告-断言相关:

 4.踩过的坑

(1)httprunner.exceptions.ParamsError: Failed to extract attribute from response!=JSON.data.record[0].naSvs

 取数组的第一个元素之前的经验用的都是xx[0],现在这个不好使

正确的写法:json.data.records.0.nmSvs

 (2)JSON.data.record[0].naSvs  或  body.data.records[0].nmSvs 

关键词错误JSON body都不对,正确的 应该是:json.data.records.0.nmSvs 

available response attributes: status_code, cookies, elapsed, headers, content, text, json, encoding, ok, reason, url.

(3)一定要注意空格的使用,严格规范.

httprunner常用的断言有如下:

  以上图片源于:https://www.cnblogs.com/xiaoyujuan/p/14774994.html

原文地址:https://www.cnblogs.com/eosclover/p/15507740.html