1.简单读取
#coding=utf-8 #调用封装好的excel读取公共方法 from python_API.common.ReadExcel import ReadExcel import requests import json #获取excel中的url url = ReadExcel("d:\\dym.xls","Sheet1").getValue(1,1) #获取excel中的请求方式 Method = ReadExcel("d:\\dym.xls","Sheet1").getValue(1,2) #获取excel中的header header = json.loads(ReadExcel("d:\\dym.xls","Sheet1").getValue(1,3)) #获取excel中的param body = json.loads(ReadExcel("d:\\dym.xls","Sheet1").getValue(1,4)) response = requests.request(Method,url,headers=header,params=body) print response.json()
2.加上unitest框架管理用例生成测试报告
#coding=utf-8 from python_API.common.ReadExcel import ReadExcel import requests import json import unittest import HTMLTestRunner class Test(unittest.TestCase): def setUp(self): self.url = ReadExcel("d:\\dym.xls","Sheet1").getValue(1,1) self.Method = ReadExcel("d:\\dym.xls","Sheet1").getValue(1,2) self.header = json.loads(ReadExcel("d:\\dym.xls","Sheet1").getValue(1,3)) def test01(self): body = json.loads(ReadExcel("d:\\dym.xls","Sheet1").getValue(1,4)) response = requests.request(self.Method,self.url,headers=self.header,params=body) self.assertEqual(response.json()["values"]["loginName"],"17779828887",msg="test01 error!") def test02(self): body = json.loads(ReadExcel("d:\\dym.xls","Sheet1").getValue(2,4)) response = requests.request(self.Method,self.url,headers=self.header,params=body) self.assertIn(u"错误",response.json()["errorMsg"],msg="test02 error!") def test03(self): body = json.loads(ReadExcel("d:\\dym.xls","Sheet1").getValue(3,4)) response = requests.request(self.Method,self.url,headers=self.header,params=body) self.assertIn(u"错误",response.json()["errorMsg"],msg="test02 error!") if __name__ == ‘__main__‘: suit = unittest.TestSuite() testcases = [Test("test01"),Test("test02"),Test("test03")] suit.addTests(testcases) dir = "D:\work_doc\pycharm2\python_API\\result\\report.html" path = open(dir,"wb") runner =HTMLTestRunner.HTMLTestRunner(stream=path,title="TestReport",description="test desc") runner.run(suit)
原文地址:https://www.cnblogs.com/Mr-ZY/p/11877062.html
时间: 2024-10-04 06:39:20