全自动swagger转换jmx工具

MIT
python
windows,mac,linux
Pactortester · 2020年07月02日 · 5813 次阅读 · 21 条评论

swaggerjmx

Build Status PyPI PyPI - Python Version GitHub top language Downloads GitHub stars https://blog.csdn.net/flower_drop

logo

安装

pip install swaggerjmx

仓库地址:

社区地址

适用场景

  1. 由于接口测试脚本编写耗时,而且需要持续维护,耗时耗力,使用此工具可以一键生成接口测试脚本.
  2. swagger-ui 接口文档一键生成 jmx 文件供 jmeter 使用.

功能

  1. 将 swagger-ui 文档转换为 jmx 文件

Demo_1

# -*- coding: utf-8 -*-

from swaggerjmx.convert import conversion
from swaggerjmx.settings import Settings as ST
#  swagger_url
ST.swagger_url = 'http://ip:port/v2/api-docs'
#  report_path
ST.report_path = 'jmx'
# 开始转换
conversion()

Demo_2

  • 需要登录才能访问的,可以复制 swagger_url 页面上的 json 信息,保存 json 文件,使用 Demo_2 方式转换
# -*- coding: utf-8 -*-

from swaggerjmx.convert import conversion
from swaggerjmx.settings import Settings as ST
#  swagger_url_json_path 
ST.swagger_url_json_path = 'test.json'
#  report_path
ST.report_path = 'jmx'
# 开始转换
conversion()

以上便是 swaggerjmx 的基本用法介绍。

如果您有发现错误,或者您对 swaggerjmx 有任何建议,欢迎到 swaggerjmx Issues 发表,非常感谢您的支持。您的反馈和建议非常宝贵,希望您的参与能帮助 swaggerjmx 做得更好。

评论列表
andy 发表于 2021年07月29日

新版本的 swagger 不支持

会说话的汤姆猫 发表于 2021年06月18日

有个缺点没解析请求参数

jiminwu 发表于 2021年02月20日

TypeError: unsupported operand type(s) for +: 'NoneType' and 'str' 这个怎么解决

捉虫子的小强 发表于 2021年01月09日

这个能否把 mock 测试数据加到 swagger 文档中,然后生成带测试数据的 jmx,你这如何做到数据参数化,可以考虑下?

jwang 发表于 2020年08月04日

这有个弊端,就是如果 swagger 含有 post 请求时,请求实体为 modles 时,就无法解析到

jwang 发表于 2020年08月04日

由 jmeter 一键转换 swagger,也可也参考下
https://testerhome.com/topics/21123

jwang 发表于 2020年08月04日

老哥,你这个跟我之前写的一个很像啊
https://testerhome.com/topics/21763

此生不换 发表于 2020年07月23日

这个好

Pactortester 发表于 2020年07月22日

@sshh123

修复:
1.path 路径中的变量没有 $ 符号,没有变量化
2.method 更改为 纯大写 字母才可以生效,比如 get 需要更改为 GET

请更新 最新版 试用 pip install -U swaggerjmx

Pactortester 发表于 2020年07月17日

@sshh123

欢迎提 pull requests ,感谢!!!,期待你的优化!
https://github.com/Pactortester/swaggerjmx.git

huis 发表于 2020年07月17日

再补充几个问题:

  1. path 路径中的变量没有 $ 符号,没有变量化
  2. method 我这边需要更改为 纯大写 字母才可以生效,比如 get 需要更改为 GET
  3. 变量 query,body,path,header 等没有做区分,都默认为了 body
  4. 注释中目前使用的是 description 字段,我这边是 summary 字段感觉放到注释中比较好

jmeter 版本:5.1

Pactortester 发表于 2020年07月16日

@sshh123
已修复请更新 v1.0.5 验证
pip install swaggerjmx==1.0.5 -i https://pypi.org/simple

huis 发表于 2020年07月16日

代码没考虑到 swagger-ui url 地址 默认端口 80 的情况

thread_group['host'] = str(host).split(":")[0]
thread_group["port"] = str(host).split(":")[1] //这里会报错

Pactortester 发表于 2020年07月15日

@huahuablue 老哥,你没有 swagger-ui 登陆权限,你用 demo_2 方式,进行转换!https://github.com/Pactortester/swaggerjmx#demo_2

huahuablue 发表于 2020年07月15日

raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

MeterSphere 小助手 发表于 2020年07月14日

也可以看下我们的项目,可以导入 postman、swagger 中的接口进行接口测试和性能测试。

MeterSphere 小助手 发表于 2020年07月14日

虎虎虎虎虎 发表于 2020年07月10日

raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

Pactortester 发表于 2020年07月02日

欢迎使用!!!

心意已决 发表于 2020年11月25日

1234