接口自动化
自动化测试
python+selenium+unittest+htmlTestrunner
python+appium+unittest+htmlTestRunner
python+request+unittest+htmlTestRunner+Excel文档 接口文档(excel表格中)
测试开发路线:
po模型 page object
unittest 单元测试框架
request 接口测试框架
接口测试工具:
postman(接口测试工具) jmeter(性能测试工具) request(接口自动化工具)
接口的几个要素:
url,参数,请求方式,网路协议,编码格式。。。
request
将任意的http请求的接口当作一个测试用例
请求方式:get/post/put/delete
参数:字典格式出现
断言:assert() //判断接口对不对的“断言函数”
pychrom添加requests
get:
# 请求方式为get方式 def getRest(): #请求地址 url="http://apis.juhe.cn/lottery/types" data = { "key":"df86a2f9d939575f52b4c954e596d4d6", "lottery_id":"ssq" } res = requests.get(url,data) #res响应等候的结果 print(res.status_code) #影响状态码 print(res.json()) #响应的json assert res.status_code == 200 getRest()
post:
#请求方式为post def postRest(): url = "http://apis.juhe.cn/lottery/types" data = {"key":"df86a2f9d939575f52b4c954e596d4d6","lottery_id":"qlc"} res = requests.post(url,data) # print(res.status_code) #断言是否包含 assert res.text.__contains__("七乐彩") print(res.text) postRest()
import unittest import HTMLTestRunner import requests # http://apis.juhe.cn/lottery class TestJuhe(unittest.TestCase): def setUp(self): #公共地址(域名) self.url = "http://apis.juhe.cn" print("测试开始") def tearDown(self): print("测试结束") def test_getQuery(self): url = self.url+"/lottery/query" data = {"key": "df86a2f9d939575f52b4c954e596d4d6", "lottery_id": "qlc"} res = requests.get(url,data) assert res.status_code == 200 def test_getTypes(self): url = self.url+"/lottery/types" data = {"key": "df86a2f9d939575f52b4c954e596d4d6"} res = requests.get(url,data) assert res.status_code == 200 if __name__ == '__main__': print("ssss") test = unittest.TestSuite() test.addTest(TestJuhe("test_getQuery")) test.addTest(TestJuhe("test_getTypes")) file = "D:/jiekouTest.html" fil = open(file, "wb") runner = HTMLTestRunner.HTMLTestRunner( stream=fil, title='接口测试报告', description='彩票执行用例结果' ) runner.run(test)