学习目标
- 掌握 HttpRunner 核心概念
- 掌握 HttpRunner 基本使用方法
课程大纲
学习资料
使用说明文档
HttpRunner 逻辑图
GitHub
HttpRunner: https://github.com/HttpRunner/HttpRunner
har2case: https://github.com/HttpRunner/har2case
工具包安装
HttpRunner
$ pip install -U httprunner
用例生成工具 har2case
$ pip install -U har2case
示例
1、使用抓包工具录制生成 testerhome.har 文件;
2、使用 har2case 将 testerhome.har 转换为 YAML/JSON 格式的测试用例;
- config:
name: testset description
request:
base_url: ''
headers:
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_5) AppleWebKit/537.36
(KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36
variables: []
- test:
name: /
request:
headers:
If-None-Match: W/"2d5f12342e3d9777cb056a26621f8cd9"
method: GET
url: https://testerhome.com/
validate:
- eq: [status_code, 200]
- eq: [headers.Content-Type, text/html; charset=utf-8]
- test:
name: /favicon-32x32.png
request:
method: GET
url: https://testerhome.com/favicon-32x32.png
validate:
- eq: [status_code, 200]
- eq: [headers.Content-Type, image/png]
- test:
name: /topics/15768
request:
headers:
If-None-Match: W/"89076461abfde5d7e2aacc65b104a7ab"
Turbolinks-Referrer: https://testerhome.com/
method: GET
url: https://testerhome.com/topics/15768
extract:
- stars: <i class='fa fa-heart'></i> <span>(.*) 个赞</span></a>
validate:
- eq: [status_code, 200]
- eq: [headers.Content-Type, text/html; charset=utf-8]
3、执行测试
$ hrun testerhome.yml
INFO Start to run testcase: testset description
/
INFO GET https://testerhome.com/
INFO status_code: 200, response_time(ms): 257.41 ms, response_length: 50479 bytes
INFO start to validate.
.
/favicon-32x32.png
INFO GET https://testerhome.com/favicon-32x32.png
INFO status_code: 200, response_time(ms): 48.24 ms, response_length: 2146 bytes
INFO start to validate.
.
/topics/15768
INFO GET https://testerhome.com/topics/15768
INFO status_code: 200, response_time(ms): 199.53 ms, response_length: 61597 bytes
INFO start to extract from response object.
INFO start to validate.
.
----------------------------------------------------------------------
Ran 3 tests in 0.545s
OK
INFO Start to render Html report ...
INFO Generated Html report: /Users/debugtalk/Desktop/reports/1535256821.html
4、查看 html 测试报告