GithubHelp home page GithubHelp logo

httprunner / har2case Goto Github PK

View Code? Open in Web Editor NEW
108.0 13.0 41.0 71 KB

Convert HAR(HTTP Archive) to YAML/JSON testcases for HttpRunner. Merged to httprunner/ext/har2case.

License: Apache License 2.0

Python 100.00%
yaml http-archive har

har2case's Introduction

HttpRunner

Github Actions codecov Go Reference downloads pypi version pyversions TesterHome

HttpRunner 是一个开源的 API 测试工具,支持 HTTP(S)/HTTP2/WebSocket/RPC 等网络协议,涵盖接口测试、性能测试、数字体验监测等测试类型。简单易用,功能强大,具有丰富的插件化机制和高度的可扩展能力。

HttpRunner 用户调研问卷 持续收集中,我们将基于用户反馈动态调整产品特性和需求优先级。

flow chart

版本发布日志 | English

设计理念

相比于其它 API 测试工具,HttpRunner 最大的不同在于设计理念。

  • 约定大于配置:测试用例是标准结构化的,格式统一,方便协作和维护
  • 标准开放:基于开放的标准,支持与 HAR/Postman/Swagger/Curl/JMeter 等工具对接,轻松实现用例生成和转换
  • 一次投入多维复用:一套脚本可同时支持接口自动化测试、性能测试、数字体验监测等多种 API 测试需求
  • 融入最佳工程实践:不仅仅是一款测试工具,在功能中融入最佳工程实践,实现面向网络协议的一站式测试解决方案

核心特性

  • 网络协议:完整支持 HTTP(S)/HTTP2/WebSocket,可扩展支持 TCP/UDP/RPC 等更多协议
  • 多格式可选:测试用例支持 YAML/JSON/go test/pytest 格式,并且支持格式互相转换
  • 双执行引擎:同时支持 golang/python 两个执行引擎,兼具 go 的高性能和 pytest 的丰富生态
  • 录制 & 生成:可使用 HAR/Postman/Swagger/curl 等生成测试用例;基于链式调用的方法提示也可快速编写测试用例
  • 复杂场景:基于 variables/extract/validate/hooks 机制可以方便地创建任意复杂的测试场景
  • 插件化机制:内置丰富的函数库,同时可以基于主流编程语言(go/python/java)编写自定义函数轻松实现更多能力
  • 性能测试:无需额外工作即可实现压力测试;单机可轻松支撑 1w+ VUM,结合分布式负载能力可实现海量发压
  • 网络性能采集:在场景化接口测试的基础上,可额外采集网络链路性能指标(DNS 解析、TCP 连接、SSL 握手、网络传输等)
  • 一键部署:采用二进制命令行工具分发,无需环境依赖,一条命令即可在 macOS/Linux/Windows 快速完成安装部署

用户声音

基于 252 份调研问卷的统计结果,HttpRunner 用户的整体满意度评分 4.3/5,最喜欢的特性包括:

  • 简单易用:测试用例支持 YAML/JSON 标准化格式,可通过录制的方式快速生成用例,上手简单,使用方便
  • 功能强大:支持灵活的自定义函数和 hook 机制,参数变量、数据驱动、结果断言等机制一应俱全,轻松适应各种复杂场景
  • 设计理念:测试用例组织支持分层设计,格式统一,易于实现测试用例的维护和复用

更多内容详见 HttpRunner 首轮用户调研报告(2022.02)

一键部署

HttpRunner 二进制命令行工具已上传至阿里云 OSS,在系统终端中执行如下命令可完成安装部署。

$ bash -c "$(curl -ksSL https://httprunner.com/script/install.sh)"

安装成功后,你将获得一个 hrp 命令行工具,执行 hrp -h 即可查看到参数帮助说明。

$ hrp -h

██╗  ██╗████████╗████████╗██████╗ ██████╗ ██╗   ██╗███╗   ██╗███╗   ██╗███████╗██████╗
██║  ██║╚══██╔══╝╚══██╔══╝██╔══██╗██╔══██╗██║   ██║████╗  ██║████╗  ██║██╔════╝██╔══██╗
███████║   ██║      ██║   ██████╔╝██████╔╝██║   ██║██╔██╗ ██║██╔██╗ ██║█████╗  ██████╔╝
██╔══██║   ██║      ██║   ██╔═══╝ ██╔══██╗██║   ██║██║╚██╗██║██║╚██╗██║██╔══╝  ██╔══██╗
██║  ██║   ██║      ██║   ██║     ██║  ██║╚██████╔╝██║ ╚████║██║ ╚████║███████╗██║  ██║
╚═╝  ╚═╝   ╚═╝      ╚═╝   ╚═╝     ╚═╝  ╚═╝ ╚═════╝ ╚═╝  ╚═══╝╚═╝  ╚═══╝╚══════╝╚═╝  ╚═╝

HttpRunner is an open source API testing tool that supports HTTP(S)/HTTP2/WebSocket/RPC
network protocols, covering API testing, performance testing and digital experience
monitoring (DEM) test types. Enjoy! ✨ 🚀 ✨

License: Apache-2.0
Website: https://httprunner.com
Github: https://github.com/httprunner/httprunner
Copyright 2017 debugtalk

Usage:
  hrp [command]

Available Commands:
  adb          simple utils for android device management
  boom         run load test with boomer
  build        build plugin for testing
  completion   Generate the autocompletion script for the specified shell
  convert      convert multiple source format to HttpRunner JSON/YAML/gotest/pytest cases
  help         Help about any command
  ios          simple utils for ios device management
  pytest       run API test with pytest
  run          run API test with go engine
  startproject create a scaffold project
  wiki         visit https://httprunner.com

Flags:
  -h, --help               help for hrp
      --log-json           set log to json format
  -l, --log-level string   set log level (default "INFO")
      --venv string        specify python3 venv path
  -v, --version            version for hrp

Use "hrp [command] --help" for more information about a command.

用户案例

赞助商

霍格沃兹测试开发学社

霍格沃兹测试开发学社是中国软件测试开发高端教育品牌,产品由国内顶尖软件测试开发技术专家携手打造,为企业与个人提供专业的技能培训与咨询、测试工具与测试平台、测试外包与测试众包服务。领域涵盖 App/Web 自动化测试、接口自动化测试、性能测试、安全测试、持续交付/DevOps、测试左移、测试右移、精准测试、测试平台开发、测试管理等方向。-> 联系我们

Subscribe

关注 HttpRunner 的微信公众号,第一时间获得最新资讯。

HttpRunner

har2case's People

Contributors

debugtalk avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

har2case's Issues

除了post请求,其他请求也需要参数

我看到您在core.py里面只给post方法去配置了postdata,虽然不知道为啥,但在我的实际使用中确实遇到了delete请求会传参数的情况,也许get请求也会。感谢您提供的这么好用的工具,我目前修改了这块,放开了所有method,并且给get方法配置了request_data_key = "params"。当然这个脚本我不会去传播,再次感谢!

exclude支持同时指定多个条件

har2case的过滤是如何实现的?--exclude只能对一个词进行过滤,例如想对css和js等多个词进行过滤就没办法实现。har2case pm.har pm.yml --exclude css,js啥都过滤不了,har2case pm.har pm.yml --exclude css --exclude js只能过滤js,请问作者如果想同时过滤JS和CSS如何实现?

execute commond error

yudeMacBook-Pro:Downloads yufeng$ har2case Untitled1.har 
Traceback (most recent call last):
  File "/usr/local/bin/har2case", line 11, in <module>
    load_entry_point('har2case==0.0.7', 'console_scripts', 'har2case')()
  File "/usr/local/lib/python3.6/site-packages/har2case-0.0.7-py3.6.egg/har2case/cli.py", line 60, in main
    har_parser = HarParser(har_source_file, args.filter, args.exclude)
  File "/usr/local/lib/python3.6/site-packages/har2case-0.0.7-py3.6.egg/har2case/core.py", line 63, in __init__
    self.testset = self.make_testset()
  File "/usr/local/lib/python3.6/site-packages/har2case-0.0.7-py3.6.egg/har2case/core.py", line 288, in make_testset
    testset = self.make_testcases()
  File "/usr/local/lib/python3.6/site-packages/har2case-0.0.7-py3.6.egg/har2case/core.py", line 267, in make_testcases
    {"test": self.make_testcase(entry_json)}
  File "/usr/local/lib/python3.6/site-packages/har2case-0.0.7-py3.6.egg/har2case/core.py", line 249, in make_testcase
    self._make_request_data(testcase_dict, entry_json)
  File "/usr/local/lib/python3.6/site-packages/har2case-0.0.7-py3.6.egg/har2case/core.py", line 161, in _make_request_data
    post_data = entry_json["request"]["postData"]["text"]
KeyError: 'text'

har2case AttributeError

yudeMacBook-Pro:Downloads yufeng$ har2case -V
0.0.6
yudeMacBook-Pro:Downloads yufeng$ har2case Untitled.har a.yaml
Traceback (most recent call last):
  File "/usr/local/bin/har2case", line 11, in <module>
    load_entry_point('har2case==0.0.6', 'console_scripts', 'har2case')()
  File "/usr/local/lib/python3.6/site-packages/har2case-0.0.6-py3.6.egg/har2case/cli.py", line 60, in main
    har_parser = HarParser(har_source_file, args.filter, args.exclude)
  File "/usr/local/lib/python3.6/site-packages/har2case-0.0.6-py3.6.egg/har2case/core.py", line 64, in __init__
    self.testset = self.make_testset()
  File "/usr/local/lib/python3.6/site-packages/har2case-0.0.6-py3.6.egg/har2case/core.py", line 289, in make_testset
    testset = self.make_testcases()
  File "/usr/local/lib/python3.6/site-packages/har2case-0.0.6-py3.6.egg/har2case/core.py", line 268, in make_testcases
    {"test": self.make_testcase(entry_json)}
  File "/usr/local/lib/python3.6/site-packages/har2case-0.0.6-py3.6.egg/har2case/core.py", line 250, in make_testcase
    self._make_request_data(testcase_dict, entry_json)
  File "/usr/local/lib/python3.6/site-packages/har2case-0.0.6-py3.6.egg/har2case/core.py", line 164, in _make_request_data
    if mimeType.startswith("application/json"):
AttributeError: 'NoneType' object has no attribute 'startswith'

har转case时的问题。具体看描述

image

您好,请问一下,遇到这种情况下怎么解决呢?我是chrome中导出的har文件。
因为之前导出的har都是小文件,都可以转化为用例,但是这次文件很大很杂,尝试了只是把其中的一部分提取出来,但是还是不行,所以请问一下到底是什么问题呢?谢谢!

har转换,缺少cookie信息

请问har2case转换时,好像没有对header里面的cookie进行提取而是直接忽略了?需要自己修改吗?

firefox导出的har和fiddler导出的har有些区别,其中fiddler导出har是可以转换的,firefox不行,具体情况下面详述。

har2case在转换FIREFOX或谷歌浏览器导出的HAR时报错,报错信息如下:

post_data = utils.x_www_form_urlencoded(post_data)
  File "c:\Python33\lib\site-packages\har2case\utils.py", line 50, in x_www_form
_urlencoded
    for key, value in origin_dict.items()
AttributeError: 'str' object has no attribute 'items'

发现问题出在 解析"text": "operation=goLoginSelectPage"时,utils.x_www_form_urlencoded(post_data) 报错了。主要原因是firefox或谷歌浏览器导出的HAR与FIDDLER有些不同如下所示:

谷歌:

          "headersSize": 684,
          "bodySize": 27,
          "postData": {
            "mimeType": "application/x-www-form-urlencoded",
            "text": "operation=goLoginSelectPage",
            "params": [
              {
                "name": "operation",
                "value": "goLoginSelectPage"
              }

fiddler:

"postData":{"params":[{"name":"operation", "value":"goLoginSelectPage"}], "mimeType":"application/x-www-form-urlencoded"}, "method":"POST", "queryString":[]}

附上两段导出的har,需要把txt文件名改成har
fiddler.txt
firefox.txt

我用charles把报文导出为har文件,使用命令行转换文件报错

E:>har2case 360fengdai.har
Traceback (most recent call last):
File "C:\Python27\Scripts\har2case-script.py", line 11, in
load_entry_point('har2case==0.1.1', 'console_scripts', 'har2case')()
File "C:\Python27\lib\site-packages\har2case-0.1.1-py2.7.egg\har2case\cli.py", line 60, in main
har_parser = HarParser(har_source_file, args.filter, args.exclude)
File "C:\Python27\lib\site-packages\har2case-0.1.1-py2.7.egg\har2case\core.py", line 36, in init
self.testset = self.make_testset()
File "C:\Python27\lib\site-packages\har2case-0.1.1-py2.7.egg\har2case\core.py", line 302, in make_testset
testset = self.make_testcases()
File "C:\Python27\lib\site-packages\har2case-0.1.1-py2.7.egg\har2case\core.py", line 281, in make_testcases
{"test": self.make_testcase(entry_json)}
File "C:\Python27\lib\site-packages\har2case-0.1.1-py2.7.egg\har2case\core.py", line 264, in make_testcase
self._make_validate(testcase_dict, entry_json)
File "C:\Python27\lib\site-packages\har2case-0.1.1-py2.7.egg\har2case\core.py", line 229, in _make_validate
for key, value in resp_content_json.items():
AttributeError: 'list' object has no attribute 'items'

360fengdai.zip

x-www-form-urlencoded处理的问题

post_data = utils.x_www_form_urlencoded(post_data)

拼接后生成的的用例:

Code=18GYHC713&Id=102830&vpsToken=xV1phNlk9&Number=TJ280421&lId=5&content=asd

测试发现对于x-www-form-urlencoded类型的数据不拼接也不影响请求,生成的yml用例反而更直观,方便维护

request:
    data:
        Code: 18GYHC713
        workId: '102829'
        Number: TJ233575
        vpsToken: xxx
    headers:
        Content-Type: application/x-www-form-urlencoded

自定义结果校验器问题

作者,您好,将har文件转换为yaml测试用例时,例如我只想校验status_code这一个字段,不想校验ContentType,如何自定义结果校验器里的校验内容。

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.