接口测试 python:自动化 api 和性能测试框架 FriedRing

CrissChan · 2016年07月13日 · 最后由 CrissChan 回复于 2016年12月16日 · 1532 次阅读
  • 简介
    通过 mitmproxy 实现了交互脚本的录制,通过 multimechanize 实现了并发测试和测试报告(html 格式)生产,同时格式化了 mitmproxy 脚本为 requests 格式

  • 基础

1mitmproxy

 2multimechanize

3requests
  • 安装 mitmproxy 和 multimechanize
    • Mac or Unbuntu
pip install mitmproxy
pip install -U multi-mechanize
pip install requests

- Windows

python -m pip install --upgrade pip(最支持版本8.1.2,多次运行可以升级到对应版本) []()
python -m pip install netlib pyopenssl pyasn1 urwid pil lxml flask
python -m pip install pyamf protobuf
python -m pip install pil
python -m pip install nose pathod countershape
python -m pip install matplotlib
python -m pip install mitmproxy
pip install -U multi-mechanize
pip install requests

-安装 FiredRing

pip install -U FiredRing

已经安装的升级

pip install --upgrade FiredRing

  • 使用 FriedRing

首先,输入命令

python fr.py -p 8888 -w scriptsolution
  -p 端口号-w 测试脚本文件夹

其次,在测试浏览器或者测试手机中设置代理(ip 为运行主机 ip,端口为 888)按照功能测试流程进行功能测试,在当前文件夹中会产生一个 scriptsolition 的文件夹,结构如下:

scriptsolution/config.cfg(multimechan的配置文件
        scriptsolution/test _ scripts/v_user.py默认的初始化脚步
        scriptsolution/test _ scripts/script.py生成的测试脚步

在录制完成后,需要修改 scriptsolution/test _ scripts/script.py 文件,去掉不属于本次测试的请求。

同时可以通过加入 assert 等信息做断言(详情可以参考 requests 包)

  • 运行脚本
    Mac or Unbuntu

  • 在 scriptsolution 的父文件夹,执行

fr -r s 

fr -r p

参数说明: s - 线性执行当前父文件夹(workspace)下的全部性能测试场景 p - 并发执行执行当前父文件夹(workspace)下的全部性能测试场景
测试结果在当前父文件夹(workspace)下的 Report 文件夹内,分为并发测试报告(Report/ParralleResult/文件夹下)和线性执行测试报告(Report/SerialResult/)
fr -r p 后的扩展参数

-t is runtime that duration of test (seconds)
 -u is rampup that duration of user rampup
 -i is resultinterval that time series interval for results analysis (seconds) 
 -b is progressbar that turn on/off console progress bar during test run default = on
 -c is consolelogging that turn on/off logging to stdout default = on
 -x is xmlreport that turn on/off xml/jtl report default = off
 -v is vusers that number of threads/virtual users for each scenrio default=10

-查看结果

结果在 scriptsolution 文件夹下的 Report 里面,按照时间顺序生产的文件夹里面有两种报告,分别是并发报告和线性报告,里面有全部测试的历史记录。



共收到 7 条回复 时间 点赞
Monkey 内容不符合版规屏蔽此话题 07月13日 10:49

使用 markdown 编辑帖子!!!!!!

#2 楼 @monkey 可以吗?

先吐槽下,请在.gitignore加上 *.py[cdo]

#4 楼 @jacexh 好谢谢

请问有测试的截图吗?

m
#6 楼 @davidyang 没有截图,基于 api 测试的 不会有图形化的操作,report 有统计图

新版本,更新了

CrissChan 关闭了讨论 06月20日 22:07
CrissChan 重新开启了讨论 07月19日 09:40
CrissChan 关闭了讨论 07月19日 17:14
需要 登录 后方可回复, 如果你还没有账号请点击这里 注册