运行环境

HttpRunner 是一个基于 Python 开发的测试框架,可以运行在 macOS、Linux、Windows 系统平台上。

HttpRunner 的开发环境为 macOS + Python 3.6;实际上,HttpRunner 支持 Python 2.7 和 Python 3.3 以上的所有版本,并使用 Travis-CI 进行了持续集成测试,测试覆盖的版本包括 2.7/3.4/3.5/3.6。

推荐使用 macOS/Linux + Python 3.6 的运行环境组合。

小七这边安装的是Windows+Python 3.7

安装方式

HttpRunner 的稳定版本托管在 PyPI 上,可以使用pip或者easy_install进行安装。

$ pip install httprunner

或者

$ easy_install httprunner

如果你需要使用最新的开发版本,那么可以采用项目的 GitHub 仓库地址进行安装:

$ pip install git+https://github.com/HttpRunner/HttpRunner.git#egg=HttpRunner

版本升级

假如你之前已经安装过了 HttpRunner,现在需要升级到最新版本,那么你可以使用-U参数。该参数对以上三种安装方式均生效。

$ pip install -U HttpRunner
$ easy_install -U HttpRunner
$ pip install -U git+https://github.com/HttpRunner/HttpRunner.git#egg=HttpRunner

安装校验

在 HttpRunner 安装成功后,系统中会新增如下 5 个命令:

  • httprunner: 核心命令
  • ate: 曾经用过的命令(当时框架名称为 ApiTestEngine),功能与 httprunner 完全相同
  • hrun: httprunner 的缩写,功能与 httprunner 完全相同
  • locusts: 基于 Locust 实现性能测试
  • har2case: 辅助工具,可将标准通用的 HAR 格式(HTTP Archive)转换为YAML/JSON格式的测试用例

httprunner、hrun、ate 三个命令完全等价,功能特性完全相同,个人推荐使用hrun命令。

运行如下命令,若正常显示版本号,则说明 HttpRunner 安装成功。

$ hrun -V
1.4.6 $ har2case -V
0.1.8

  • 帮助命令

    • hrun -h

 hrun -h
usage: hrun [-h] [-V] [--no-html-report] [--html-report-name HTML_REPORT_NAME]
[--html-report-template HTML_REPORT_TEMPLATE]
[--log-level LOG_LEVEL] [--log-file LOG_FILE]
[--dot-env-path DOT_ENV_PATH] [--failfast]
[--startproject STARTPROJECT]
[--validate [VALIDATE [VALIDATE ...]]]
[--prettify [PRETTIFY [PRETTIFY ...]]]
[testset_paths [testset_paths ...]] One-stop solution for HTTP(S) testing. positional arguments:
testset_paths testset file path optional arguments:
-h, --help show this help message and exit
-V, --version show version
--no-html-report do not generate html report.
--html-report-name HTML_REPORT_NAME
specify html report name, only effective when
generating html report.
--html-report-template HTML_REPORT_TEMPLATE
specify html report template path.
--log-level LOG_LEVEL
Specify logging level, default is INFO.
--log-file LOG_FILE Write logs to specified file path.
--dot-env-path DOT_ENV_PATH
Specify .env file path, which is useful for keeping
production credentials.
--failfast Stop the test run on the first error or failure.
--startproject STARTPROJECT
Specify new project name.
--validate [VALIDATE [VALIDATE ...]]
Validate JSON testset format.
--prettify [PRETTIFY [PRETTIFY ...]]
Prettify JSON testset format.

开发者模式

默认情况下,安装 HttpRunner 的时候只会安装运行 HttpRunner 的必要依赖库。

如果你不仅仅是使用 HttpRunner,还需要对 HttpRunner 进行开发调试(debug),那么就需要进行如下操作。

HttpRunner 使用 pipenv 对依赖包进行管理,若你还没有安装 pipenv,需要先执行如下命令进行安装:

$ pip install pipenv


安装的依赖包都会放在python目录site-packages中

获取 HttpRunner 源码(自定义找到一个存放httprunner的路径,比如需要将仓库下载到G:\Tools\Python\Python37下的目录 那么需要进入到此路径下执行 下面的命令):

$ git clone https://github.com/HttpRunner/HttpRunner.git


进入仓库目录,安装所有依赖:

$ pipenv install --dev


 

运行单元测试,若测试全部通过,则说明环境正常。

$ pipenv run python -m unittest discover


查看 HttpRunner 的依赖情况:

$ pipenv graph

HttpRunner==1.4.2
- colorama [required: Any, installed: 0.3.9]
- colorlog [required: Any, installed: 3.1.4]
- har2case [required: Any, installed: 0.1.8]
- PyYAML [required: Any, installed: 3.12]
- Jinja2 [required: Any, installed: 2.10]
- MarkupSafe [required: >=0.23, installed: 1.0]
- PyYAML [required: Any, installed: 3.12]
- requests [required: Any, installed: 2.18.4]
- certifi [required: >=2017.4.17, installed: 2018.4.16]
- chardet [required: >=3.0.2,<3.1.0, installed: 3.0.4]
- idna [required: >=2.5,<2.7, installed: 2.6]
- urllib3 [required: <1.23,>=1.21.1, installed: 1.22]
- requests-toolbelt [required: Any, installed: 0.8.0]
- requests [required: >=2.0.1,<3.0.0, installed: 2.18.4]
- certifi [required: >=2017.4.17, installed: 2018.4.16]
- chardet [required: >=3.0.2,<3.1.0, installed: 3.0.4]
- idna [required: >=2.5,<2.7, installed: 2.6]
- urllib3 [required: <1.23,>=1.21.1, installed: 1.22]

调试运行方式:

# 调试运行 hrun
$ pipenv run python main-debug.py hrun -h+

# 调试运行 locusts
$ pipenv run python main-debug.py locusts -h
没装locust可以安装下
pip install locustio
 

接口自动化 Windows + HttpRunner 初探(一)的更多相关文章

  1. 接口自动化测试之httprunner初探

    ❝ 今天来介绍一个python的一个开源项目:httprunner,接口自动化工具.第一次输入,难免有不周到的地方,轻喷~ ❞ 介绍: HttpRunner是一个简单优雅但功能强大的 HTTP(S) ...

  2. 接口自动化框架 - httprunner

    自己曾经写过一个接口自动化的框架,并做了一版本的优化,一直觉得做的还不错,且没依赖现有的框架. 最近因为一些工作的原因,开始又思考之前写的框架的一些缺点及如何优化,所以找到比较有名的httprunne ...

  3. 接口自动化框架 - httprunner 引用unittest

    httprunner其中一个比较好的点就是利用type动态创建类,使用setattr动态增加方法和属性. 将维护的用例进行转变为继承unittest.Textcase的类,很好的与unittest结合 ...

  4. 接口自动化之unittest初探

    最近几天苦心钻研unittest,终于略有所得,所以想来跟大家分享一下.有关python和unittest的基础知识部分就不在一一细说,相信各位也不是小白了.如果需要我整理基础知识,欢迎留言,我会看情 ...

  5. 接口自动化之Postman+Newman

    简介 Postman 使一款可以方便我们调用API的工具,通过Postman 与 Newman结合我们还可以批量运行API达到API自动化测试的目的. Postman 安装 Window 系统需要先安 ...

  6. 接口自动化的根基--HTTP协议

    点击标题下「蓝色微信名」可快速关注 坚持的是分享,搬运的是知识,图的是大家的进步,没有收费的培训,没有虚度的吹水,喜欢就关注.转发(免费帮助更多伙伴)等来交流,想了解的知识请留言,给你带来更多价值,是 ...

  7. RobotFrameWork环境搭建(基于HTTP协议的接口自动化)

    1. 前言 接着上一篇<RobotFramework框架系统课程介绍>,本篇主要介绍一下在基于RobotFramework框架开展接口自动化前,前期的环境如何搭建,正所谓”工欲善其事,必先 ...

  8. 接口自动化python

    !/usr/bin/env python coding=utf-8 Todo:接口自动化测试 Author:归根落叶 Blog:http://this.ispenn.com import json i ...

  9. python接口自动化-参数化

    原文地址https://www.cnblogs.com/yoyoketang/p/6891710.html python接口自动化 -参数关联(一)https://www.cnblogs.com/11 ...

随机推荐

  1. Træfɪk 服务发现解决方案

    Træfɪk is a modern HTTP reverse proxy and load balancer made to deploy microservices with ease. It s ...

  2. RK3288 查看时钟树

    主控端可以通过指令查看时钟树,enable_cnt为1,表示时钟已使能. # cat d/clk/clk_summary cat d/clk/clk_summary clock enable_cnt ...

  3. idea之jrebel热部署使用教程

    JRebel是一个J2EE热部署的工具.使用它可以减少浪费8-18%的开发时间在项目的构建和部署上.虽然Java也提供了HotSpot的JVM,但是如果你修改的类中有方法名称变动的话,HotSpot就 ...

  4. bfs判断子图是否连通

    int judge() { int v[13] = { 0 }; queue<int> myq; myq.push(ans[0]); v[ans[0]] = 1; while (!myq. ...

  5. HDOJ5437(优先队列)

    Alisha’s Party Time Limit: 3000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) ...

  6. 详细讲解删除SQL Server日志的具体方法

    一: 删除LOG 1:分离数据库 企业管理器->服务器->数据库->右键->分离数据库 2:删除LOG文件 3:附加数据库 企业管理器->服务器->数据库-> ...

  7. 03:TPCC 基准压测my.cnf

    line: V1.3 mail: gczheng@139.com date: 2017-11-09 一.TPCC测试前准备 1.压测环境 配置 信息 主机 Dell PowerEdge R730xd ...

  8. MariaDB主从异步复制详解

    一 异步复制(Asynchronous replication) 1.MariaDB本身支持单向的.异步的复制.异步复制意味着在把数据从一台机器拷贝到另一台机器时有一个延时,最重要的是这意味着当应用系 ...

  9. Windows Azure 应用程序短暂性故障处理

    这两天在做一个Windows Azure blob存储备份的的一个小功能,但是每次使用CloudBlockBlob.UploadFromStream上传本地文件到Blob Storage,总是不成功报 ...

  10. Django学习---缓存

    缓存 由于Django是动态网站,所有每次请求均会去数据进行相应的操作,当程序访问量大时,耗时必然会更加明显,最简单解决方式是使用:缓存. 缓存将一个某个views的返回值保存至内存或者memcach ...