zoukankan      html  css  js  c++  java
  • 接口自动化测试 python+request+excel(六)

    判断接口的返回参数是否包含Excel填写的预期结果

    直接在主函数添加if就好

    #!/usr/bin/env python3
    # -*-coding:utf-8-*-
    # __author__: hunter
    
    from conn.run_demo import RunMain
    from interface.tool.handle_excel import *
    import json
    
    
    class RunTestCase:
        def __init__(self):
            self.Runmain = RunMain()        # 实例化调用get/post请求基类
            self.data = HandleExcel()       # 实例化操作Excel文件类
    
        def go_run(self):
            rows_count = self.data.get_rows()                   # 获取Excel行数
            for i in range(1, rows_count):                      # 利用行数进行迭代处理每个接口
                url = self.data.get_value(i, get_url())         # 循环获取URL的值
                print(url)
                print('=====')
                method = self.data.get_value(i, get_mothod())   # 循环获取method的值
                data = json.loads(self.data.get_value(i, get_params()))     # 循环获取请求参数
                expect = self.data.get_value(i, get_expectvalue())          # 循环获取期望输出
                print(data)
                print('=====')
                is_run = self.data.get_value(i, get_priority()) # 获取是否运行,即判断Excel中priority是不是为“high"
                if is_run == 'high':
                    res = self.Runmain.run_main(url, method, data)  # 调用主函数
                    print(res)
                    if expect in res:           # res返回的内容是否包含expect,是否与期望一致
                        print('测试通过')
                    else:
                        print("测试失败")
                    print('=====')
    
    
    if __name__ == '__main__':
        run = RunTestCase()
        run.go_run()

    得到结果:

     

  • 相关阅读:
    Makefile 文件详细规则
    unrar命令
    Vector容器 和 iteration 迭代器
    python的with语句
    anaconda 使用总结
    vim 保存退出命令集
    Tensorflow实例集
    jupyter notebook 使用例子
    tensorflow 安装教程(最佳)
    Ext.NET 4.1.0 搭建页面布局
  • 原文地址:https://www.cnblogs.com/hemingwei/p/11580945.html
Copyright © 2011-2022 走看看