跳转到主要内容

开发者友好的负载测试框架

项目描述

PyPI PyPI Build Status

har2locust

从头开始创建 locust文件 有时很难。你难道不希望可以从浏览器会话自动生成它吗?

现在你可以做到了!har2locust将你的浏览器记录(HAR文件)转换为locust文件。

以下是生成的文件示例.

har2locust的核心使用一个 jinja2模板 来定义输出。你可以轻松地更改它以自定义输出,或者你可以更进一步,使用 插件系统 来对处理/输出进行任何类型的更改。

安装

pip install har2locust

用法

  1. 使用浏览器导航网页同时记录您的活动。然后将记录导出为HAR文件。以下是一个使用Chrome开发者工具的示例 har.gif

  2. 运行 har2locust myrecording.har > locustfile.py

> har2locust --help
usage: har2locust [-h] [-t TEMPLATE] [--plugins PLUGINS] [--disable-plugins DISABLE_PLUGINS]
                  [--resource-types RESOURCE_TYPES] [--version] [--loglevel LOGLEVEL]
                  input

positional arguments:
  input                 har input file

options:
  -h, --help            show this help message and exit
  -t TEMPLATE, --template TEMPLATE
                        jinja2 template used to generate locustfile. Defaults to locust.jinja2. Will check current
                        directory/relative paths first and har2locust built-ins second
  --plugins PLUGINS     Comma separated list of extra python files to source OR packages to import, containing
                        decorated methods for processing the har file.
  --disable-plugins DISABLE_PLUGINS
                        Temporarily disable default plugins. Specified by comma separated list of default plugin
                        python files to source.
  --resource-types RESOURCE_TYPES
                        Commas separated list of resource types to be included in the locustfile. Supported type are
                        `xhr`, `script`, `stylesheet`, `image`, `font`, `document`, `other`. Defaults to
                        xhr,document,other.
  --version, -V         show program's version number and exit
  --loglevel LOGLEVEL, -L LOGLEVEL

Simplest usage:
har2locust myrecording.har > locustfile.py

Load extra plugins by import path and/or filename:
har2locust --plugins har2locust.extra_plugins.plugin_example,myplugin.py myrecording.har

Disable one of the default plugins:
har2locust --disable-plugins=rest.py myrecording.har

Parameters can also be set using environment variables or config files (har2locust.conf or ~/.har2locust.conf) For details about how to set parameters see https://goo.gl/R74nmi
  1. 运行locust!

高级用法

  • 使用文件 .urlignore.headerignore 过滤您的记录(从您的当前目录读取)。用正则表达式填充它们以过滤记录中的任何不想要的请求或头部。一些头部始终被忽略(cookie、content-length和chrome的“fake”头部)。以下是一些示例: .urlignore.headerignore

  • 使用插件系统进行更高级的处理。

注意

har2locust基于har2py构建,修改为生成locustfile而不是基本的Python文件,并扩展以支持插件。

har2locust非常新,在1.0版本之前,接口可能会有变动而不通知。如果您遇到问题,PR(Pull Requests)非常受欢迎。

此外,不要期望生成的文件总是非常有用。您可能需要添加响应验证以确保测试质量,也许还需要参数化动态数据,如用户名。

项目详情


下载文件

下载适用于您平台的文件。如果您不确定选择哪个,请了解更多关于安装包的信息。

源分布

har2locust-0.9.3.tar.gz (25.6 MB 查看哈希值)

上传时间

构建分布

har2locust-0.9.3-py3-none-any.whl (16.9 kB 查看哈希值)

上传时间 Python 3

支持者

AWS AWS 云计算和安全赞助商 Datadog Datadog 监控 Fastly Fastly CDN Google Google 下载分析 Microsoft Microsoft PSF赞助商 Pingdom Pingdom 监控 Sentry Sentry 错误日志 StatusPage StatusPage 状态页面