__author__ = '程程' import requests import json from common.my_log import MyLogg mylog = MyLogg() class DoRequests: '''完成http的get和post请求,并返回结果''' def __init__(self, url, method, param=None): self.url = url self.method = method self.param = param def get_header(self, index): if index == 1: headers = { 'Connection': 'keep-alive', 'Accept': 'application/json, text/javascript, */*; q=0.01', 'Origin': 'http://172.16.1.107:9088', 'X-Requested-With': 'XMLHttpRequest', 'Authorization': 'Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJrZW4iLCJpYXQiOjE1Mzc1NTQzMDksImRhdGEiOnsidXNlcm5hbWUiOiJ4dXRvbmdiYW8iLCJpc19zdXBlcnVzZXIiOjEsImlkIjoxNywibG9naW5fdGltZSI6MTUzNzU1NDMwOX0sImV4cCI6MTUzODE1NDMwOX0.32Lys4hjjY2XRpM2r9YSmpYA798u821m_M5Tzb6wxIU', 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Safari/537.36', 'Content-Type': 'application/json', 'Accept-Encoding': 'gzip, deflate', 'Accept-Language': 'zh-CN,zh;q=0.9', } elif index == 2:
__author__ = '程程' #1引入单元测试,代替run这个文件 #2引入ddt,参数化我们测试用例里面的每一条数据,提高复用性,做法就是先获取excel文件中用例 #1)然后通过data传入(需要解包),然后将data里面的元祖的每一个元素,传入到函数中,再对传入的元素进行处理 #3测试用例里面引入try..except..finally,最后写回测试数据 #4测试报告--在run文件中进行运行 #5测试报告的路径 import unittest from common.do_requests import DoRequests from common.learn_do_excel import DoExcel from common import project_path from ddt import ddt, data, unpack from common.my_log import MyLogg my_log = MyLogg() test_data = DoExcel(project_path.case_path, "register").read_data() @ddt class TestCases(unittest.TestCase): def setUp(self): #测试之前的准备工作 pass def tearDown(self): pass @data(*test_data) def test_001(self, item): global result #指明全球变量 url = item["url"] method = item["method"]