python 接口自动化测试框架设计(十一)

十二、读取excel表中的数据,执行requests请求

import sys
sys.path.append("D:\\PycharmProjects\\FN_API_V1.0.1")
from base.run_method import RunMethod
from data.get_data import GetData
from util.common_util import CommonUtil
from util.send_email import SendEmail
from util.LoggerHandler import logger

class RunTest:

    def __init__(self):
        self.run_method = RunMethod()
        self.data = GetData()
        self.com_util = CommonUtil()
        self.send_mail = SendEmail()

    def go_on_run(self):
        res = None
        pass_count = []
        fail_count = []
        rows_count = self.data.get_case_lines()
        for i in range(1, rows_count):
            is_run = self.data.get_is_run(i)
            if is_run:
                url = self.data.get_request_url(i)
                method = self.data.get_request_method(i)
                data = self.data.get_request_data(i)
                expect = self.data.get_except_data(i)
                headers = self.data.is_headers(i)
                token = self.data.is_token(i)
                request_name = self.data.get_request_name(i)
                if token is None:
                    if data is None:
                        res = self.run_method.run_main(method, url, headers=headers)
                    else:
                        res = self.run_method.run_main(method, url, data, headers=headers)
                else:
                    if data is not None:
                        res = self.run_method.run_main(method, url + str(token), data, headers=headers)
                    else:
                        res = self.run_method.run_main(method, url + str(token), headers=headers)
                if int(expect) == int(res):
                    self.data.write_result(i, 'pass')
                    pass_count.append(i)
                else:
                    self.data.write_result(i, res)
                    fail_count.append(i)
                    msg = str(i) + '、' + request_name + ':' + url + '\n' + 'error:' + str(res) + '\n' + \
                          '----------------------------------------------------------------------------------------'
                    logger().info(msg)

        if len(fail_count) == 0:
            print("接口运行全部通过")
        else:
            self.send_mail.send_main(pass_count, fail_count)

if __name__ == '__main__':
    run = RunTest()
    print(run.go_on_run())
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

小志老师

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值