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"}}
  • 相关阅读:
    区块链中的密码学
    初识nodeJS
    JS或jQuery获取当前屏幕宽度
    jQuery与Zepto的异同
    使用递归解决斐波那契数列的性能问题
    sass高级语法的补充
    sass的高级语法
    栅格 CSS中的循环 媒体查询
    Zepto
    dedecms 留言板中引用模板文件方法
  • 原文地址:https://www.cnblogs.com/hito/p/11050170.html
Copyright © 2011-2022 走看看