HttpRunner 3.x (三)环境与简介 测试

1、HttpRunner简介

  httprunner是一款面向HTTP(s)协议的通用开源测试框架,只需要编写维护一份YAML/JSON脚本,

  既可实现自动化测试,持续集成等多种测试需求。

  可支持的接口协议:HTTP(S)

  不支持的接口协议: websocket dubbo 等其他

2、HttpRunner与其他框架对比有哪些优势

  

  httprunner的优势在于上手容易(不同太多代码量,也不用考虑代码数据分类)

  只需要维护YMAL/JSON脚本即可实现接口自动化

  当然复杂的场景需要借助 debugtalk.py写辅助函数完成

3、 HttpRunner框架原理(基于requests库发送请求)

  

 4、HttpRunner主要特性

  4.1:继承Reauests的全部特性,轻松实现HTTP(S)的各种测试需求

  4.2:采用YMAL/JSON的形式面试测试场景,保证测试用例描述的统一性和可维护性

       4.3:在HAR支持下记录并生成测试用例

  4.4:支持variables、extract,validate,hooks机制,创建非常复杂的测试方案

  4.5:借用辅助函数(debugtalk.py),任何功能都可以在测试用例的任何部分使用

  4.6:使用jmespath,提取和验证json的响应从未如此简单

  4.7:有了pytest,数百个插件随时可用

  4.8:使用allure,测试报告可以非常强大

  4.9:通过重复使用Locust,你可以进行性能测试,而且无需额外的工作

  4.10:支持CLI命令,与CI、CD完美结合

5、HttpRunner 用例展示--YAML格式

name: 媒体充值-正常充值
base_url: ${ENV(base_url)}
variables:
    applicationType: 0
    processType: 0
    contractId: '2969995'
    supplierContractId: '2970009'
    payPort: '2140600'
    detailList:
        - accountId: '1434799031334154242'
          accountCurrencyRecharge: '1'
    fileList: [ ]
    reason: API自动化测试
request:
    url: ****
    method: POST
    headers:
        content-type: application/json
        cookie: XXH-SSO-TOKEN=$token
    json:
        applicationType: $applicationType
        processType: $processType
        contractId: $contractId
        supplierContractId: $supplierContractId
        payPort: $payPort
        detailList:
            - accountId: '1434799031334154242'
              accountCurrencyRecharge: '1'
        fileList: $fileList
        reason: $reason
validate:
    - eq: [status_code, 200]

6、HttpRunner 用例展示--JSON格式

{
  "name": "媒体充值-正常充值",
  "base_url": "${ENV(base_url)}",
  "variables": {
    "applicationType": 0,
    "processType": 0,
    "contractId": "2969995",
    "supplierContractId": "2970009",
    "payPort": "2140600",
    "detailList": [
      {
        "accountId": "1434799031334154242",
        "accountCurrencyRecharge": "1"
      }
    ],
    "fileList": [],
    "reason": "API自动化测试"
  },
  "request": {
    "url": "*****",
    "method": "POST",
    "headers": {
      "content-type": "application/json",
      "cookie": "XXH-SSO-TOKEN=$token"
    },
    "json": {
      "applicationType": "$applicationType",
      "processType": "$processType",
      "contractId": "$contractId",
      "supplierContractId": "$supplierContractId",
      "payPort": "$payPort",
      "detailList": [
        {
          "accountId": "1434799031334154242",
          "accountCurrencyRecharge": "1"
        }
      ],
      "fileList": "$fileList",
      "reason": "$reason"
    }
  },
  "validate": [
    {
      "eq": [
        "status_code",
        200
      ]
    }
  ]
}
原文地址:https://www.cnblogs.com/jiliangceshi/p/15558172.html