1500字范文,内容丰富有趣,写作好帮手!
1500字范文 > python runner_【httprunner】自动化测试入门(基于python)!

python runner_【httprunner】自动化测试入门(基于python)!

时间:2019-01-10 11:27:18

相关推荐

python runner_【httprunner】自动化测试入门(基于python)!

1、安装httprunner

①需要先安装python(3.7以上最好)

②控制台运行pip/pip3 install httprunner

2、用charles/fiddler抓包,然后右键导出为har格式文件

3、执行har2case把刚才生成的文件转换为.py文件

-s可以看详情,具体详情可在脚本根目录log目录下查看

har2case test.har

①或者是har2case test.har -2j(转化为json格式)

②或者是har2case test.har -2y(转化为yaml格式)

4、运行用例

①hrun test_test.py

②py test_test.py

5、没了

6、其他

可以打开生成的.py文件,更改一些配置

①config层是公共配置包含name、base_url、verify、variables、export

②teststeps包含RunRequest、with_variables、method、with_params、with_headers、with_cookies、with_data、with_json、extract(with_jmespath)、validate(assert_XXX)

③变量是$开头

④Step是具体的用例,在teststeps下面

⑤Step里面的get/post是方式、with_params是参数、with_headers是头、with_cookies是cookies、validate后面是断言

⑥前置RunTestCase下包含with_variables、call、export(操作这个请求之前配置这些前置操作)

⑦--html=report.html可生成默认报告地址(pytest-html的),结尾加上--self-contained-html可生成更多信息

⑧想看allure report,需要安装allure-pytest插件,

pip3 install "allure-pytest" 或者 pip3 install "httprunner[allure]"

--alluredir=DIR: Generate Allure report in the specified directory (may not exist)

--clean-alluredir: Clean alluredir folder if it exists

--allure-no-capture: Do not attach pytest captured logging/stdout/stderr to report

使用hrun /path/to/testcase --alluredir=/tmp/my_allure_results生成测试报告,再执行allure serve /tmp/my_allure_results生成最终测试报告

更多pytest-allure介绍:allure-report

安装:pip install locust

运行用例,并保存报告:

hrun demo_test.py --alluredir=F:\projects\history\tujia\pytest\.idea\my_allure_results

生成在线报告:

allure serve F:/projects/history/tujia/pytest/.idea/my_allure_results

打开web压测:

locusts -f F:/projects/history/tujia/pytest/.idea/demo_test.py

补充参考:

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。