HttpRunner初体验

理论的东西我们就不说了,直接吃菜;

pip安装httprunner的版本;

pip install httprunner==1.5.8

安装完后检查版本号;

hrun -V

编写yml格式脚本

- config:
    name: logincase
    variables: {}
- test:
    name: 高精度平台的登录
    request:
        url: http://xxxx:xxxx/v1/authorization/login # 你的登录接口
        method: POST
        headers:
            Content-Type: application/json
        json:
            name: admin # 用户名
            password: pwd # 密码
    extract:
        - token: content.data.accessToken # 我的token是存在于data下的
    validate:
        - eq: [status_code, 200]

- test:
    name: 搜索成员
    request:
        url: http://xxxx:xxxx/v1/user/organization/search/1
        method: GET
        headers:
            Content-Type: application/json
            Authorization: Bearer $token # 从登录接口获取到的token值
        json:
            organizationId: 1
            page: 1
            pageSize: 20
    validate:
        - eq: [status_code, 200]
        - eq: [headers.Content-Type, application/json]
        - eq: [content.msg, 搜索成功] # 断言搜索成功
        - eq: [content.code, 200]

第一个用例是登录用例,第二个用例是某一组织下搜索成员用户的信息;

执行脚本:

hrun test_login_demo02.yml

运行用例结果:

 也可以再report报告中查看我们的测试结果;

 

原文地址:https://www.cnblogs.com/spider3658/p/14837807.html