zoukankan      html  css  js  c++  java
  • rf接口自动化之结果校验

    接口自动化的结果校验分两个层次:协议层,业务层

    (本篇仅对协议层校验做扩展,仅考虑返回结果为json格式的接口)

    协议层校验即对返回结果的key是否存在,value类型是否与协议一致进行判断

    class CheckResp():
        def check_keys(self,target,template,except_key=""):
            if isinstance(target,(str,unicode)):
                target = json.loads(target)
            if isinstance(template,(str,unicode)):
                template = json.loads(template)
            for key,value in template.items():
                if not target.has_key(key) and key not in except_key:   # 校验断言json的key在返回结果中的是否存在
                    raise Exception("key:%s not in the response" % key)
                elif target.has_key(key) and type(value) != type(target[key]):  # 校验返回结果的value类型与断言json的value类型一致
                    raise Exception("the value's type of key:%s not match the assert json" % key)
                if isinstance(value,dict):  # 多重嵌套的字典类型递归校验判断
                    self.check_keys(target[key],value)

    在robot framework中的应用:

    1. 引用代码库
    2. 在接口调用请求后,获取返回结果,赋值给${resp}
    3. 接口返回结果协议层校验关键字使用:Check Keys    ${resp}    {"a":1,"b":{"c":"d"}}
  • 相关阅读:
    mybaits不能出现小于号
    结合rpyc使用python实现动态升级的方法
    secureCRT使用小贴士
    大数据的实时技术
    gnuplot使用
    Python3.4使用MySql
    Linux内存分配----SLAB
    WinInet:HTTPS 请求出现无效的证书颁发机构的处理
    正则表达式学习
    C++中static的全部作用
  • 原文地址:https://www.cnblogs.com/hito/p/11050170.html
Copyright © 2011-2022 走看看