标签:ffd chrome conf 模拟post har token head 图片 runner
httprunner是一款面向 HTTP(S) 协议的通用测试框架。只需编写维护一份 YAML/JSON 脚本,即可实现自动化测试、性能测试、线上监控、持续集成等多种测试需求。
使用命令:
pip install httprunner
har2case -V
hrun -V (若正常显示版本号,说明安装成功。)
pip install httprunner==2.5.7 (安装httprunner 2.5.7,这里安装的这个版本)
1)写yml文件
# 模拟请求头
- config:
name: "验证百度搜索是否正确"
base_url: "https://www.baidu.com"
- test:
name: "百度搜索请求"
request:
url: "/s"
method: GET
headers:
User-Agent: "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.61 Safari/537.36"
params:
wd: "hello"
validate:
- eq: ["status_code",200]
2)执行:hrun 路径/文件名.yml
(如:这里是 hrun ./testcases/20200607/test_demo_03.yml)
3)查看报告
# 模拟带参数的GET请求
- config:
name: "验证能否获取token值"
base_url: "https://api.weixin.qq.com"
- test:
name: "get access_token"
request:
url: "/cgi-bin/token"
method: GET
params:
grant_type: "client_credential"
appid: "wxb9013645f9c6f66b"
secret: "8c80367d3fac3cb6d3dc910fe6416436"
validate:
- eq: ["status_code",200]
- eq: [content.expires_in,7200] #content响应正文
四、发送post请求
# 模拟post请求:发送json数据
- config:
name: "验证修改标签是否成功执行"
base_url: "https://api.weixin.qq.com"
- test:
name: "修改标签请求"
request:
url: "/cgi-bin/tags/update"
method: POST
headers:
User-Agent: "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.61 Safari/537.36"
params:
access_token: "34_MrotWbhBTW-KQmo3VFfjDZGzdYAOtw4FUSgdsgbfwti7_aBFUiHRT0BffdbGWP9RU0CZm4M93PqWB6xxrXNzotVd5R1tN4ubaxVOGeWH7dwfzgh0AB4Fa0yK_H1Ggns3ton2XqNMuI0UQiN4DJIaAAAHNM"
json: { "tag" : { "id" : 100, "name" : "广东东" } }
validate:
- eq: ["status_code",200]
- eq: [content.errcode,0]
【httprunner基本使用01】简介、安装、发get/post请求
标签:ffd chrome conf 模拟post har token head 图片 runner
原文地址:https://www.cnblogs.com/xiaoshijie/p/13114789.html