美文网首页
httpRunner

httpRunner

作者: 小眼睛的露鹿酱 | 来源:发表于2019-09-25 16:30 被阅读0次

    https://cn.httprunner.org/

    李隆——大疆互联网的一站式自动化测试解决方案(基于HttpRunner)

    安装python, pip

    1. 搜索: https://www.python.org/
    2. 点击 download:https://www.python.org/downloads/
    3. 下载完成后,点击安装, 按照自定义形式安装, 就会看到安装了pip, 然后选择安装路径, 并选择:设置环境变量(减少了自己手动设置的麻烦)
    4. 安装完成后, 在ternimal里面输入pip


    5. 安装httprunner
      HttpRunner 的稳定版本托管在 PyPI 上,可以使用 pip 进行安装。
    $ pip install httprunner
    $ pip install -U HttpRunner(版本升级的时候)
    发现存储在d:\install\python\lib\site-packages
    

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

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

    httprunner、hrun、ate 三个命令完全等价,功能特性完全相同,个人推荐使用hrun命令。
    检查httpRunner是否安装成功:

    $ hrun -V
    2.0.2
    
    $ har2case -V
    0.3.1
    
    1. 安装httpRunner开发调试的工具
    先放在这里, 如果需要 返回来安装
    如果你不仅仅是使用 HttpRunner,还需要对 HttpRunner 进行开发调试(debug),那么就需要进行如下操作。
    
    HttpRunner 使用 [pipenv](https://docs.pipenv.org/) 对依赖包进行管理,若你还没有安装 pipenv,需要先执行如下命令进行按照:
    $ pip install pipenv
    参考: [https://cn.httprunner.org/Installation/](https://cn.httprunner.org/Installation/)
    
    1. 参考了https://cn.httprunner.org/quickstart/

    注意事项

    目前的版本是V2.x, 其中的框架跟V1是不一样的


    目录层级结构
    1. 每次运行的时候, 最好到项目根目录下去hrun, 这样能确保文件都能被找到
    C:\Users>hrun -help
    usage: hrun [-h] [-V] [--log-level LOG_LEVEL] [--log-file LOG_FILE]
                [--dot-env-path DOT_ENV_PATH] [--report-template REPORT_TEMPLATE]
                [--report-dir REPORT_DIR] [--failfast] [--save-tests]
                [--startproject STARTPROJECT]
                [--validate [VALIDATE [VALIDATE ...]]]
                [--prettify [PRETTIFY [PRETTIFY ...]]]
                [testcase_paths [testcase_paths ...]]
    hrun: error: argument -h/--help: ignored explicit argument 'elp'
    

    有时候配置的env 文件会有很多 指定env file的时候使用 --dot-env-path

    1. 当前目录下hrun的时候会在当前的路径下自己生成一个reports文件 , 指定路径使用 --report-dir
    2. yaml文件来编写的时候需要注意一下:格式一定要正确,
    name: get token
    variables:
        user_agent: XXX
        device_sn: API_XXX
        os_platform: XXX
        app_version: XXX
    request:
        url: /api/get-token
        method: POST
        headers:
            user_agent: $user_agent
            device_sn: $device_sn
            os_platform: $os_platform
            app_version: $app_version
            Content-Type: "application/json"
            device_sn: $device_sn
        json:
            sign: ${get_sign($device_sn, $os_platform, $app_version)}
    validate:
        - eq: ["status_code", 0]
        - len_eq: ["content.token", 12]
        - contains: [{"a": 1, "b": 2}, "a"]
    
    1. 虽然支持局部变量和全局变量, 最好所有的变量不要重名, 都使用唯一的name
    2. debugtalk.py 文件中来添加需要的函数, 这些函数再yaml文件中自动支持
    3. 我自己觉得先使用postman来检查接口看接口是否可用, 然后再放入到文件中
      另外还可以使用浏览器自带的network信息来查看操作调用了哪些接口。


    相关文章

      网友评论

          本文标题:httpRunner

          本文链接:https://www.haomeiwen.com/subject/qydbyctx.html