接口自动化架构-2

时间:2019-06-14
本文章向大家介绍接口自动化架构-2,主要包括接口自动化架构-2使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

获取测试用例

import xlrd

from lib.log import atp_log
class OpCase(object):
    def get_case(self,file_path):
        case = []
        if file_path.endswith('.xls') or file_path.endswith('.xlsx'):
            try:
                book = xlrd.open_workbook(file_path)
                sheet = book.sheet_by_index(0)
                for i in range(1, sheet.nrows):  # excle中一共有多少行
                    row_data = sheet.row_values(i)  # 获取每行的值
                    case.append(row_data[4:8])  # 切片(因为只需要取下标4到下标7的值)
                atp_log.info('共读取%s条用例' % (len(case)))
            except Exception as e:
                atp_log.error('%s用例获取失败,错误信息%s' % (file_path, e))
        else:
            atp_log.error('用例文件不合法:%s' % file_path)
        return case

#测试
#m = OpCase()
#m.get_case(r'E:\Users\admin\PycharmProjects\Interface test\ATP')
#m.get_case('xx.xls')
#m.get_case(r'E:\Users\admin\PycharmProjects\Interface test\ATP\cases\测试用例.xlsx')

发送请求

    def my_request(self,url,method,data):
        method = method.upper()
        if method=='POST':
            requests.get(url,params=data)
        else:
            atp_log.warning('该请求方式暂不支持')

原文地址:https://www.cnblogs.com/ruijie/p/11022439.html