1、第三方模块安装:
pip install -i https://pypi.douban.com/simple httprunner
验证:hrun -h

2、创建工程目录:
使用命令创建一个工程目录
hrun --startproject myhrun
3、 进入到目录
cd myhrun
dir
可以看到生成的4个目录和一个py文件
api debugtalk.py reports testcases testsuites
4、目录介绍:
testcases:存放用例
testsuites:存放套件
reports:自动生成报告并放到该目录
5、接口请求准备:使用fiddler抓包工具,将接口保存下来:File-Export Sessions->Selected Sessions,保存格式选择:HTTPArchive v1.2,如图:


6、在Pycharm中打开新建的myhrun项目,以下操作都在pycharm中进行
1)、在myhrun项目下新建datas文件,并且将保存的login_ifno.har复制到datas目录下,如图:

2)、使用har2case -h将fiddler保存的har文件转换成json或者yam文件:
har2case datas/login_info.har # 默认转换成json格式的文件
har2case datas/login_info.har -2y #加上参数 -2y转换为yam格式
如图:

生成yam文件:

3)、将生成的yam文件拷贝到testcases目录下,如图:

4)、执行:hrun testcases/login_info.yml --log-level debug,如图:

5)、发现可自动生成报告:

6)、报告格式:

7)、当然,可以自定义报告模板,生成漂亮的自动化测试报告:
1)、新建templates文件夹,将报告模板拷贝过来,如图:

2)、重新运行:hrun testcases/login_info.yml --report -dir template 报告模板路径
3)、重新生成一个报告:

4)、查看报告:

生成的报告是不是很惊艳!!!!!!
8)、 还可以使用locust进行页面的性能测试:
1)、安装locust第三方库:pip install locustio
2)、执行命令: locusts -f testcases/login_info.yml,如图:

3)、在浏览器中进行访问:http://localhost:8089/,出现如下界面:

4)、Number of users to simulate:并发用户数
Hatch rate (users spawned/second):多少秒启动这些并发
5)、开始压测:

6)、生成的图表:


网友评论