软件测试--接口自动化

接口自动化测试框架

目录结构

7 部分(5个目录、2个文件):
api/: 存储接口对象层(自己封装的 接口)
scripts/: 存储测试脚本层 (unittest框架实现的 测试类、测试方法)
data/: 存储 .json 数据文件
report/: 存储 生成的 html 测试报告
common/: 存储 通用的 工具方法
config.py: 存储项目的配置信息(全局变量)
run_suite.py: 组装测试用例、生成测试报告的 代码

在这里插入图片描述
在这里插入图片描述

一、Requests框架

简介:

Requests库 是 Python编写的,基于urllib 的 HTTP库,使用方便。

安装:

pip install requests

查验:

  • 步骤1:pip 中查验
# 方法1
pip list
# 方法2
pip show 库名
  • 步骤2:pycharm 中查验

在这里插入图片描述
在这里插入图片描述

设置http请求语法

resp = requests.请求方法(url='URL地址', params={
   k:v}, headers={
   k:v},data={
   k:v}, json={
   k:v}, cookies='cookie数据'(如:令牌))
请求方法:
get请求 - get()
post请求 - post()
put请求 - put()
delete请求 - delete()
url: 待请求的url - string类型
params:查询参数 - 字典
headers:请求头 - 字典
data:表单格式的 请求体 - 字典
json:json格式的 请求体 - 字典
cookies:cookie数据 - string类型
resp:响应结果

入门案例

使用Requests库访问 百度 http://www.baidu.com

import requests

resp=requests.get(url="http://www.baidu.com")

print(resp.text)

在这里插入图片描述

案例

使用Requests库,完成 平安保险核保接口调用。返回 ”200“ 即可。

import requests
import json

url = "http://mcp-test-health.pingan.com.cn/gateway/mcp/outChannel/validate.do"
params = {
   "c": "WI"}
headers = {
   "Content-Type": "application/json"}

body = {
   
    "requestId": "hebaojiaoyanma_3453946894536",
    "c": "WI",
    "data": {
   
        "productId": "A100000013",
        "outChannelOrderId": "66323958403338552251",
        "effDate": "2020-12-20",
        "applyDate": "2020-12-19",
        "totalPremium": "357.00",
        "isNoticeConfirm": "Y",
        "isShareCoverage": "N",
        "discount": "1",
        "applicant": {
   
            "name": "士发放",
            "birthday": "1980-01-01",
            "sex": "M",
            "idType": "1",
            "idno": "110101198001010117",
            "contactInfo": {
   
                "mobile": "16351656161",
                "email": "123@qq.com",
                "contactAddress": {
   
                    "provinceCode": "110000",
                    "cityCode": "110000",
                    "areaCode": "110101"
                }
            },
            "extend": {
   
                "taxType": "null",
                "realCheckType": "1"
            }
        },
        "insurants": [
            {
   
                "seqno": "1",
                "name": "华东师范",
                "birthday": "1998-12-22",
                "sex": "F",
                "idType": "2",
                "idno": "41151990221",
                "socialSecurity": "Y",
                "relationshipWithApplicant": "2",
                "relationshipWithPrimaryInsurant": "1",
                "contactInfo": {
   
                    "email": "123@qq.com"
                },
                "coverages": [
                    {
   
                        "planType": "0",
                        "sumInsured": "100000.00",
                        "benLevel": "09",
                        "period": "12",
                        "periodDay": "0",
                        
  • 18
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值