首页 > 代码库 > 学习python的第一个小目标:通过requests+xlrd实现简单接口测试,将测试用例维护在表格中,与脚本分开。
学习python的第一个小目标:通过requests+xlrd实现简单接口测试,将测试用例维护在表格中,与脚本分开。
小白的学习方式:通过确定一个小目标来想办法实现它,再通过笔记来加深印象。
面对标题中的小目标我陷入了思考。。。。嗯,首先实现利用xlrd库来取出想要的用例
首先用表格准备好用例,如图下:
先试下取number为1的一行用例试试:
1 #!/usr/bin/env python 2 # -*- coding: utf-8 -*- 3 import xlrd 4 5 xlsurl = r"D:\RequestAPI.xlsx" # 表格文件路径 6 rqapi = xlrd.open_workbook(xlsurl) # 获得文件对象 7 sheet_name = rqapi.sheet_names()[0] # 获取表格第一个sheet名称 8 sheet1 = rqapi.sheet_by_name(sheet_name) # 获取表格第一个sheet对象 9 nrow = sheet1.nrows # 获取表格行总数 10 ncols = sheet1.ncols # 获取表格列总数 11 col_data = http://www.mamicode.com/sheet1.col_values(0) # 获取表格第一列的数据 12 row_data = http://www.mamicode.com/sheet1.row_values(1) # 获取表格第二行的数据 13 print "=======================================================================" 14 print row_data 15 print type(row_data)
执行结果如图:
可以看到,表格中number为1的一行数据已经打印出来了,并且是list类型的,这样通过遍历list可以将数据都当个取出来,不过我没这么做,因为表格中paramete是保存的请求参数,在requests库中,请求参数是dict格式的,所以不需要把每个参数都遍历出来(requests库的使用在笔记后面别急)。
搞定取单行数据,那接下来再取每一行的数据,并把每行中需要的列也取出来,上代码:
#!/usr/bin/env python # -*- coding: utf-8 -*- import xlrd class ApiTest: def xlsee(self, xlsFile): rqapi = xlrd.open_workbook(xlsFile) # 获得文件对象 sheet_name = rqapi.sheet_names()[0] # 获取第一个sheet名称 sheet = rqapi.sheet_by_name(sheet_name) # 获取第一个sheet对象 return sheet if __name__ == "__main__": apitest = ApiTest() xlsFile = r"D:\RequestAPI.xlsx" # 文件路径 sheet1 = apitest.xlsee(xlsFile) nrow = sheet1.nrows # 获取行总数 ncols = sheet1.ncols # 获取列总数 col_data = http://www.mamicode.com/sheet1.col_values(0) # 获取第一列的数据 for i in range(1, nrow): # 循环每行,并获取每行每列的值,第0行是标题,所以从第一行开始取 row_data = http://www.mamicode.com/sheet1.row_values(i) # 获取第i行的数据 nums = int(row_data[0]) # 用例编号 rqtypes = str(row_data[2]) # 请求类型 rqurls = str(row_data[1]) # 请求地址 a = row_data[5:] # 请求参数,并且一次取出这一行所有的参数 parametes = dict(zip(a[0::2], a[1::2])) # 将list类型的参数转换为dict字典类型的 code = row_data[3] # 校验结果用的code状态码 coderesult = row_data[4] # 用于显示校验结果的参数pass或error print "==================================================================================" print "用例编号:", nums print "请求类型", rqtypes print "请求地址", rqurls print "请求参数parametes:", parametes print "校验结果用的code状态码", code print "用于显示校验结果的参数", coderesult
对于上面代码,简单封装了一下,注意
a = row_data[5:] # 请求参数,并且一次取出这一行所有的参数
这个利用list[a:]来取值,可取第a位后面所有的数据,这就表明,我可在表格中设置N个参数,而不会限制于不同接口参数个数不一样的限制了
上面代码运行结果如下:
从表格中读取用例的问题已经搞定了,接下来就是通过requests来执行这些用例,上代码:
class ApiTest: # 请求主方法 def request(self, rqtype, rqurl, paramete, headers): self.rqurl = rqurl # API地址 self.rqtype = rqtype # 请求类型get or post self.paramete = paramete # 请求参数 self.headers = headers # 请求头 if rqtype == "get": apirqhttp = requests.get(url=rqurl, params=paramete, headers=headers) # 发送请求 code = apirqhttp.status_code # 保存返回状态 pam = apirqhttp.text # 保存返回数据并将json转为dict return code, pam if rqtype == "post": apirqhttp = requests.post(url=rqurl, data=http://www.mamicode.com/paramete, headers=headers) code = apirqhttp.status_code pam = apirqhttp.text return code, pam else: print "请求参数错误,请求类型只支持get+post,请求地址支持string,参数支持dict"
其中有个小插曲,就是接口中常见的身份验证问题,需要获取token值,将token值作为herders请求头来进行身份校验
于是再通过登录接口来获取这个token(注意:token值校验不同项目可能不一样,比如我们公司就在touken值前面加了个brarer ,所以需要再将token值拼接一下)值并参数化,上代码:
# 获取B2B分销商token值方法 def seltoken(self): rqtypes = "post" rqurls = "http://xxxxx.dddd.com//account/authorize" parametes = {"username": "Wbfxs001", "password": "111111Qq", "grant_type": "password"} headers = None cod, pam = ApiTest().request(rqtypes, rqurls, parametes, headers) # 掉用request方法请求登录 pam = json.loads(pam) # 保存返回数据并将json转为dict access_token = pam["access_token"] # 截取dic中access_token键的value access_token = "bearer " + str(access_token) # 拼接access_token为最终需要的token值 return access_token
最后将xlrd+requests方法都封装好,上代码(上面代码都整合在这里了):
#!/usr/bin/env python # -*- coding: utf-8 -*- # @Time : 2017-04-13 18:39 import requests, xlrd, xlrd, json class ApiTest: # 请求主方法 def request(self, rqtype, rqurl, paramete, headers): self.rqurl = rqurl # API地址 self.rqtype = rqtype # 请求类型get or post self.paramete = paramete # 请求参数 self.headers = headers # 请求头 if rqtype == "get": apirqhttp = requests.get(url=rqurl, params=paramete, headers=headers) # 发送请求 code = apirqhttp.status_code # 保存返回状态 pam = apirqhttp.text # 保存返回数据并将json转为dict return code, pam if rqtype == "post": apirqhttp = requests.post(url=rqurl, data=http://www.mamicode.com/paramete, headers=headers) code = apirqhttp.status_code pam = apirqhttp.text return code, pam else: print "请求参数错误,请求类型只支持get+post,请求地址支持string,参数支持dict" # 获取B2B分销商token值方法 def seltoken(self): rqtypes = "post" rqurls = "http://xxxxx.dddd.com//account/authorize" parametes = {"username": "Wbfxs001", "password": "111111Qq", "grant_type": "password"} headers = None cod, pam = ApiTest().request(rqtypes, rqurls, parametes, headers) # 掉用request方法请求登录 pam = json.loads(pam) # 保存返回数据并将json转为dict access_token = pam["access_token"] # 截取dic中access_token键的value access_token = "bearer " + str(access_token) # 拼接access_token为最终需要的token值 return access_token def xlsee(self, xlsFile): rqapi = xlrd.open_workbook(xlsFile) # 获得文件对象 sheet_name = rqapi.sheet_names()[0] # 获取第一个sheet名称 sheet = rqapi.sheet_by_name(sheet_name) # 获取第一个sheet对象 return sheet if __name__ == "__main__": apitest = ApiTest() xlsFile = r"D:\RequestAPI.xlsx" # 文件路径 sheet1 = apitest.xlsee(xlsFile) nrow = sheet1.nrows # 获取行总数 ncols = sheet1.ncols # 获取列总数 col_data = http://www.mamicode.com/sheet1.col_values(0) # 获取第一列的数据 for i in range(1, nrow): # 循环每行,并获取每行每列的值 row_data = http://www.mamicode.com/sheet1.row_values(i) # 获取第i行的数据 nums = int(row_data[0]) # 获取第i行的某个数据 rqtypes = str(row_data[2]) rqurls = str(row_data[1]) a = row_data[5:] parametes = dict(zip(a[0::2], a[1::2])) code = row_data[3] coderesult = row_data[4] access_token = apitest.seltoken() # 获取token headers = {"Authorization": access_token} codetest, pamtest = apitest.request(rqtypes, rqurls, parametes, headers) print "用例编号:", nums, "code码:", codetest print pamtest
附上执行效果图:
D:\Python27\python.exe D:/PycharmProjects/testuntitled0325/TestAPI/request_01.py =================================================================================================== 用例编号: 1 code码: 200 200 { "has_next_page": false, "has_previous_page": false, "page_index": 1, "page_size": 10, "total_count": 12, "total_pages": 2, "items": [ { "hotel_id": 13, "product_id": 100029, "main_img_path": "http://xxxx.wqhome.com/ImageUpload/Hotel/HotelExterior/20170103/160154b033d144deb2a3e999611d86ad.jpg", "hotel_name": "测试温泉酒店09", "min_price": 290.00, "create_on": "2017-02-15T09:44:39.993", "star_rated": 3, "city_id": 199, "city_name": null, "district_id": 1771, "address": "广东省深圳市南山区12321323", "app_sort": 1 }, { "hotel_id": 14, "product_id": 100030, "main_img_path": "http://xxxx.wqhome.com/ImageUpload/Hotel/HotelExterior/20170103/d63184bb528546b79584f97c86031b29.jpg", "hotel_name": "测试温泉酒店10测试温泉酒店10测试温泉酒店10测试温泉酒店10测试温泉酒店10测试温泉酒店10测试温泉酒店10测试温泉酒店10测试温泉酒店10测试温泉酒店10测试温泉酒店10测试温泉酒店10测试温泉酒店10测试温泉酒店10测试温泉酒店10测试温泉酒店10测试温泉酒店10测试温泉酒店10测试温泉酒店10测试温泉酒店10测试温泉酒店10", "min_price": 10.00, "create_on": "2017-02-15T09:45:54.633", "star_rated": 5, "city_id": 197, "city_name": null, "district_id": 1747, "address": "广东省广州市东山区", "app_sort": 2 }, { "hotel_id": 12, "product_id": 100028, "main_img_path": "http://xxxx.wqhome.com/ImageUpload/Hotel/HotelExterior/20170103/55b232ad75fe42f8a612f4ab08a8a5a4.jpg", "hotel_name": "测试温泉酒店08", "min_price": 10.00, "create_on": "2017-02-15T09:43:29.883", "star_rated": 2, "city_id": 199, "city_name": null, "district_id": 1773, "address": "广东省深圳市龙岗区", "app_sort": 3 }, { "hotel_id": 10, "product_id": 100025, "main_img_path": "http://xxxx.wqhome.com/ImageUpload/Hotel/HotelExterior/20170103/32054166b9124f27ad09b2e6342c34f1.jpg", "hotel_name": "测试温泉酒店06", "min_price": 10.00, "create_on": "2017-02-14T18:00:44.95", "star_rated": 2, "city_id": 199, "city_name": null, "district_id": 1771, "address": "广东省深圳市南山区", "app_sort": 4 }, { "hotel_id": 2, "product_id": 100005, "main_img_path": "http://xxxx.wqhome.com/ImageUpload/Hotel/HotelExterior/20170103/6245b7e28bbb43d7a761cbace4ff94cb.jpg", "hotel_name": "forver酒店", "min_price": 6.00, "create_on": "2017-01-04T16:15:34.45", "star_rated": 0, "city_id": 199, "city_name": null, "district_id": 1771, "address": "广东省深圳市南山区尚美科技", "app_sort": 5 }, { "hotel_id": 1, "product_id": 100001, "main_img_path": "http://xxxx.wqhome.com/ImageUpload/Hotel/HotelExterior/20170103/6245b7e28bbb43d7a761cbace4ff94cb.jpg", "hotel_name": "forver温泉酒店", "min_price": 7.00, "create_on": "2017-01-03T16:39:26.2", "star_rated": 5, "city_id": 199, "city_name": null, "district_id": 1771, "address": "广东省深圳市南山区广东省深圳市南山区尚美科技", "app_sort": 6 }, { "hotel_id": 11, "product_id": 100027, "main_img_path": "http://xxxx.wqhome.com/ImageUpload/Hotel/HotelExterior/20170103/ac107f6d85a94844a0dde390cf31cb1a.jpg", "hotel_name": "测试价格不一致的问题", "min_price": 32.00, "create_on": "2017-02-15T09:42:08.68", "star_rated": 3, "city_id": 199, "city_name": null, "district_id": 1772, "address": "广东省深圳市宝安区", "app_sort": null }, { "hotel_id": 9, "product_id": 100024, "main_img_path": "http://xxxx.wqhome.com/ImageUpload/Hotel/HotelExterior/20170103/1a9b79068deb409fbcae3ce120fe97a8.jpg", "hotel_name": "测试温泉酒店04", "min_price": 10.00, "create_on": "2017-02-14T17:50:18.153", "star_rated": 4, "city_id": 199, "city_name": null, "district_id": 1771, "address": "广东省深圳市南山区1", "app_sort": null }, { "hotel_id": 8, "product_id": 100023, "main_img_path": "http://xxxx.wqhome.com/ImageUpload/Hotel/HotelExterior/20170103/2e1bc4986ed740f3a9fbc535023c18f2.jpg", "hotel_name": "测试温泉酒店03", "min_price": 10.00, "create_on": "2017-02-14T17:49:17.717", "star_rated": 2, "city_id": 199, "city_name": null, "district_id": 1770, "address": "广东省深圳市福田区", "app_sort": null }, { "hotel_id": 7, "product_id": 100022, "main_img_path": "http://xxxx.wqhome.com/ImageUpload/Hotel/HotelExterior/20170103/2e1bc4986ed740f3a9fbc535023c18f2.jpg", "hotel_name": "测试温泉酒店02", "min_price": 10.00, "create_on": "2017-02-14T17:47:09.95", "star_rated": 3, "city_id": 199, "city_name": null, "district_id": 1771, "address": "广东省深圳市南山区", "app_sort": null } ] } =================================================================================================== 用例编号: 2 code码: 200 200 { "has_next_page": false, "has_previous_page": false, "page_index": 1, "page_size": 10, "total_count": 12, "total_pages": 2, "items": [ { "hotel_id": 13, "product_id": 100029, "main_img_path": "http://xxxx.wqhome.com/ImageUpload/Hotel/HotelExterior/20170103/160154b033d144deb2a3e999611d86ad.jpg", "hotel_name": "测试温泉酒店09", "min_price": 290.00, "create_on": "2017-02-15T09:44:39.993", "star_rated": 3, "city_id": 199, "city_name": null, "district_id": 1771, "address": "广东省深圳市南山区12321323", "app_sort": 1 }, { "hotel_id": 14, "product_id": 100030, "main_img_path": "http://xxxx.wqhome.com/ImageUpload/Hotel/HotelExterior/20170103/d63184bb528546b79584f97c86031b29.jpg", "hotel_name": "测试温泉酒店10测试温泉酒店10测试温泉酒店10测试温泉酒店10测试温泉酒店10测试温泉酒店10测试温泉酒店10测试温泉酒店10测试温泉酒店10测试温泉酒店10测试温泉酒店10测试温泉酒店10测试温泉酒店10测试温泉酒店10测试温泉酒店10测试温泉酒店10测试温泉酒店10测试温泉酒店10测试温泉酒店10测试温泉酒店10测试温泉酒店10", "min_price": 10.00, "create_on": "2017-02-15T09:45:54.633", "star_rated": 5, "city_id": 197, "city_name": null, "district_id": 1747, "address": "广东省广州市东山区", "app_sort": 2 }, { "hotel_id": 12, "product_id": 100028, "main_img_path": "http://xxxx.wqhome.com/ImageUpload/Hotel/HotelExterior/20170103/55b232ad75fe42f8a612f4ab08a8a5a4.jpg", "hotel_name": "测试温泉酒店08", "min_price": 10.00, "create_on": "2017-02-15T09:43:29.883", "star_rated": 2, "city_id": 199, "city_name": null, "district_id": 1773, "address": "广东省深圳市龙岗区", "app_sort": 3 }, { "hotel_id": 10, "product_id": 100025, "main_img_path": "http://xxxx.wqhome.com/ImageUpload/Hotel/HotelExterior/20170103/32054166b9124f27ad09b2e6342c34f1.jpg", "hotel_name": "测试温泉酒店06", "min_price": 10.00, "create_on": "2017-02-14T18:00:44.95", "star_rated": 2, "city_id": 199, "city_name": null, "district_id": 1771, "address": "广东省深圳市南山区", "app_sort": 4 }, { "hotel_id": 2, "product_id": 100005, "main_img_path": "http://xxxx.wqhome.com/ImageUpload/Hotel/HotelExterior/20170103/6245b7e28bbb43d7a761cbace4ff94cb.jpg", "hotel_name": "forver酒店", "min_price": 6.00, "create_on": "2017-01-04T16:15:34.45", "star_rated": 0, "city_id": 199, "city_name": null, "district_id": 1771, "address": "广东省深圳市南山区尚美科技", "app_sort": 5 }, { "hotel_id": 1, "product_id": 100001, "main_img_path": "http://xxxx.wqhome.com/ImageUpload/Hotel/HotelExterior/20170103/6245b7e28bbb43d7a761cbace4ff94cb.jpg", "hotel_name": "forver温泉酒店", "min_price": 7.00, "create_on": "2017-01-03T16:39:26.2", "star_rated": 5, "city_id": 199, "city_name": null, "district_id": 1771, "address": "广东省深圳市南山区广东省深圳市南山区尚美科技", "app_sort": 6 }, { "hotel_id": 11, "product_id": 100027, "main_img_path": "http://xxxx.wqhome.com/ImageUpload/Hotel/HotelExterior/20170103/ac107f6d85a94844a0dde390cf31cb1a.jpg", "hotel_name": "测试价格不一致的问题", "min_price": 32.00, "create_on": "2017-02-15T09:42:08.68", "star_rated": 3, "city_id": 199, "city_name": null, "district_id": 1772, "address": "广东省深圳市宝安区", "app_sort": null }, { "hotel_id": 9, "product_id": 100024, "main_img_path": "http://xxxx.wqhome.com/ImageUpload/Hotel/HotelExterior/20170103/1a9b79068deb409fbcae3ce120fe97a8.jpg", "hotel_name": "测试温泉酒店04", "min_price": 10.00, "create_on": "2017-02-14T17:50:18.153", "star_rated": 4, "city_id": 199, "city_name": null, "district_id": 1771, "address": "广东省深圳市南山区1", "app_sort": null }, { "hotel_id": 8, "product_id": 100023, "main_img_path": "http://xxxx.wqhome.com/ImageUpload/Hotel/HotelExterior/20170103/2e1bc4986ed740f3a9fbc535023c18f2.jpg", "hotel_name": "测试温泉酒店03", "min_price": 10.00, "create_on": "2017-02-14T17:49:17.717", "star_rated": 2, "city_id": 199, "city_name": null, "district_id": 1770, "address": "广东省深圳市福田区", "app_sort": null }, { "hotel_id": 7, "product_id": 100022, "main_img_path": "http://xxxx.wqhome.com/ImageUpload/Hotel/HotelExterior/20170103/2e1bc4986ed740f3a9fbc535023c18f2.jpg", "hotel_name": "测试温泉酒店02", "min_price": 10.00, "create_on": "2017-02-14T17:47:09.95", "star_rated": 3, "city_id": 199, "city_name": null, "district_id": 1771, "address": "广东省深圳市南山区", "app_sort": null } ] } =================================================================================================== 用例编号: 3 code码: 200 200 { "has_next_page": false, "has_previous_page": false, "page_index": 1, "page_size": 10, "total_count": 12, "total_pages": 2, "items": [ { "hotel_id": 13, "product_id": 100029, "main_img_path": "http://xxxx.wqhome.com/ImageUpload/Hotel/HotelExterior/20170103/160154b033d144deb2a3e999611d86ad.jpg", "hotel_name": "测试温泉酒店09", "min_price": 290.00, "create_on": "2017-02-15T09:44:39.993", "star_rated": 3, "city_id": 199, "city_name": null, "district_id": 1771, "address": "广东省深圳市南山区12321323", "app_sort": 1 }, { "hotel_id": 14, "product_id": 100030, "main_img_path": "http://xxxx.wqhome.com/ImageUpload/Hotel/HotelExterior/20170103/d63184bb528546b79584f97c86031b29.jpg", "hotel_name": "测试温泉酒店10测试温泉酒店10测试温泉酒店10测试温泉酒店10测试温泉酒店10测试温泉酒店10测试温泉酒店10测试温泉酒店10测试温泉酒店10测试温泉酒店10测试温泉酒店10测试温泉酒店10测试温泉酒店10测试温泉酒店10测试温泉酒店10测试温泉酒店10测试温泉酒店10测试温泉酒店10测试温泉酒店10测试温泉酒店10测试温泉酒店10", "min_price": 10.00, "create_on": "2017-02-15T09:45:54.633", "star_rated": 5, "city_id": 197, "city_name": null, "district_id": 1747, "address": "广东省广州市东山区", "app_sort": 2 }, { "hotel_id": 12, "product_id": 100028, "main_img_path": "http://xxxx.wqhome.com/ImageUpload/Hotel/HotelExterior/20170103/55b232ad75fe42f8a612f4ab08a8a5a4.jpg", "hotel_name": "测试温泉酒店08", "min_price": 10.00, "create_on": "2017-02-15T09:43:29.883", "star_rated": 2, "city_id": 199, "city_name": null, "district_id": 1773, "address": "广东省深圳市龙岗区", "app_sort": 3 }, { "hotel_id": 10, "product_id": 100025, "main_img_path": "http://xxxx.wqhome.com/ImageUpload/Hotel/HotelExterior/20170103/32054166b9124f27ad09b2e6342c34f1.jpg", "hotel_name": "测试温泉酒店06", "min_price": 10.00, "create_on": "2017-02-14T18:00:44.95", "star_rated": 2, "city_id": 199, "city_name": null, "district_id": 1771, "address": "广东省深圳市南山区", "app_sort": 4 }, { "hotel_id": 2, "product_id": 100005, "main_img_path": "http://xxxx.wqhome.com/ImageUpload/Hotel/HotelExterior/20170103/6245b7e28bbb43d7a761cbace4ff94cb.jpg", "hotel_name": "forver酒店", "min_price": 6.00, "create_on": "2017-01-04T16:15:34.45", "star_rated": 0, "city_id": 199, "city_name": null, "district_id": 1771, "address": "广东省深圳市南山区尚美科技", "app_sort": 5 }, { "hotel_id": 1, "product_id": 100001, "main_img_path": "http://xxxx.wqhome.com/ImageUpload/Hotel/HotelExterior/20170103/6245b7e28bbb43d7a761cbace4ff94cb.jpg", "hotel_name": "forver温泉酒店", "min_price": 7.00, "create_on": "2017-01-03T16:39:26.2", "star_rated": 5, "city_id": 199, "city_name": null, "district_id": 1771, "address": "广东省深圳市南山区广东省深圳市南山区尚美科技", "app_sort": 6 }, { "hotel_id": 11, "product_id": 100027, "main_img_path": "http://xxxx.wqhome.com/ImageUpload/Hotel/HotelExterior/20170103/ac107f6d85a94844a0dde390cf31cb1a.jpg", "hotel_name": "测试价格不一致的问题", "min_price": 32.00, "create_on": "2017-02-15T09:42:08.68", "star_rated": 3, "city_id": 199, "city_name": null, "district_id": 1772, "address": "广东省深圳市宝安区", "app_sort": null }, { "hotel_id": 9, "product_id": 100024, "main_img_path": "http://xxxx.wqhome.com/ImageUpload/Hotel/HotelExterior/20170103/1a9b79068deb409fbcae3ce120fe97a8.jpg", "hotel_name": "测试温泉酒店04", "min_price": 10.00, "create_on": "2017-02-14T17:50:18.153", "star_rated": 4, "city_id": 199, "city_name": null, "district_id": 1771, "address": "广东省深圳市南山区1", "app_sort": null }, { "hotel_id": 8, "product_id": 100023, "main_img_path": "http://xxxx.wqhome.com/ImageUpload/Hotel/HotelExterior/20170103/2e1bc4986ed740f3a9fbc535023c18f2.jpg", "hotel_name": "测试温泉酒店03", "min_price": 10.00, "create_on": "2017-02-14T17:49:17.717", "star_rated": 2, "city_id": 199, "city_name": null, "district_id": 1770, "address": "广东省深圳市福田区", "app_sort": null }, { "hotel_id": 7, "product_id": 100022, "main_img_path": "http://xxxx.wqhome.com/ImageUpload/Hotel/HotelExterior/20170103/2e1bc4986ed740f3a9fbc535023c18f2.jpg", "hotel_name": "测试温泉酒店02", "min_price": 10.00, "create_on": "2017-02-14T17:47:09.95", "star_rated": 3, "city_id": 199, "city_name": null, "district_id": 1771, "address": "广东省深圳市南山区", "app_sort": null } ] } =================================================================================================== 用例编号: 4 code码: 200 200 { "has_next_page": false, "has_previous_page": false, "page_index": 1, "page_size": 10, "total_count": 12, "total_pages": 2, "items": [ { "hotel_id": 13, "product_id": 100029, "main_img_path": "http://xxxx.wqhome.com/ImageUpload/Hotel/HotelExterior/20170103/160154b033d144deb2a3e999611d86ad.jpg", "hotel_name": "测试温泉酒店09", "min_price": 290.00, "create_on": "2017-02-15T09:44:39.993", "star_rated": 3, "city_id": 199, "city_name": null, "district_id": 1771, "address": "广东省深圳市南山区12321323", "app_sort": 1 }, { "hotel_id": 14, "product_id": 100030, "main_img_path": "http://xxxx.wqhome.com/ImageUpload/Hotel/HotelExterior/20170103/d63184bb528546b79584f97c86031b29.jpg", "hotel_name": "测试温泉酒店10测试温泉酒店10测试温泉酒店10测试温泉酒店10测试温泉酒店10测试温泉酒店10测试温泉酒店10测试温泉酒店10测试温泉酒店10测试温泉酒店10测试温泉酒店10测试温泉酒店10测试温泉酒店10测试温泉酒店10测试温泉酒店10测试温泉酒店10测试温泉酒店10测试温泉酒店10测试温泉酒店10测试温泉酒店10测试温泉酒店10", "min_price": 10.00, "create_on": "2017-02-15T09:45:54.633", "star_rated": 5, "city_id": 197, "city_name": null, "district_id": 1747, "address": "广东省广州市东山区", "app_sort": 2 }, { "hotel_id": 12, "product_id": 100028, "main_img_path": "http://xxxx.wqhome.com/ImageUpload/Hotel/HotelExterior/20170103/55b232ad75fe42f8a612f4ab08a8a5a4.jpg", "hotel_name": "测试温泉酒店08", "min_price": 10.00, "create_on": "2017-02-15T09:43:29.883", "star_rated": 2, "city_id": 199, "city_name": null, "district_id": 1773, "address": "广东省深圳市龙岗区", "app_sort": 3 }, { "hotel_id": 10, "product_id": 100025, "main_img_path": "http://xxxx.wqhome.com/ImageUpload/Hotel/HotelExterior/20170103/32054166b9124f27ad09b2e6342c34f1.jpg", "hotel_name": "测试温泉酒店06", "min_price": 10.00, "create_on": "2017-02-14T18:00:44.95", "star_rated": 2, "city_id": 199, "city_name": null, "district_id": 1771, "address": "广东省深圳市南山区", "app_sort": 4 }, { "hotel_id": 2, "product_id": 100005, "main_img_path": "http://xxxx.wqhome.com/ImageUpload/Hotel/HotelExterior/20170103/6245b7e28bbb43d7a761cbace4ff94cb.jpg", "hotel_name": "forver酒店", "min_price": 6.00, "create_on": "2017-01-04T16:15:34.45", "star_rated": 0, "city_id": 199, "city_name": null, "district_id": 1771, "address": "广东省深圳市南山区尚美科技", "app_sort": 5 }, { "hotel_id": 1, "product_id": 100001, "main_img_path": "http://xxxx.wqhome.com/ImageUpload/Hotel/HotelExterior/20170103/6245b7e28bbb43d7a761cbace4ff94cb.jpg", "hotel_name": "forver温泉酒店", "min_price": 7.00, "create_on": "2017-01-03T16:39:26.2", "star_rated": 5, "city_id": 199, "city_name": null, "district_id": 1771, "address": "广东省深圳市南山区广东省深圳市南山区尚美科技", "app_sort": 6 }, { "hotel_id": 11, "product_id": 100027, "main_img_path": "http://xxxx.wqhome.com/ImageUpload/Hotel/HotelExterior/20170103/ac107f6d85a94844a0dde390cf31cb1a.jpg", "hotel_name": "测试价格不一致的问题", "min_price": 32.00, "create_on": "2017-02-15T09:42:08.68", "star_rated": 3, "city_id": 199, "city_name": null, "district_id": 1772, "address": "广东省深圳市宝安区", "app_sort": null }, { "hotel_id": 9, "product_id": 100024, "main_img_path": "http://xxxx.wqhome.com/ImageUpload/Hotel/HotelExterior/20170103/1a9b79068deb409fbcae3ce120fe97a8.jpg", "hotel_name": "测试温泉酒店04", "min_price": 10.00, "create_on": "2017-02-14T17:50:18.153", "star_rated": 4, "city_id": 199, "city_name": null, "district_id": 1771, "address": "广东省深圳市南山区1", "app_sort": null }, { "hotel_id": 8, "product_id": 100023, "main_img_path": "http://xxxx.wqhome.com/ImageUpload/Hotel/HotelExterior/20170103/2e1bc4986ed740f3a9fbc535023c18f2.jpg", "hotel_name": "测试温泉酒店03", "min_price": 10.00, "create_on": "2017-02-14T17:49:17.717", "star_rated": 2, "city_id": 199, "city_name": null, "district_id": 1770, "address": "广东省深圳市福田区", "app_sort": null }, { "hotel_id": 7, "product_id": 100022, "main_img_path": "http://xxxx.wqhome.com/ImageUpload/Hotel/HotelExterior/20170103/2e1bc4986ed740f3a9fbc535023c18f2.jpg", "hotel_name": "测试温泉酒店02", "min_price": 10.00, "create_on": "2017-02-14T17:47:09.95", "star_rated": 3, "city_id": 199, "city_name": null, "district_id": 1771, "address": "广东省深圳市南山区", "app_sort": null } ] } Process finished with exit code 0
至此,以上是本次学习后的一点点成果。此次学习似乎已经看到了一个简单自动化接口测试框架的影子,后面再不断通过学习去完善它。。
由于也是刚开始学习python,对其理解也比较浅。身为一名测试工程师,有着一颗摆脱手工测试,进阶到自动化测试的心,后面的路还很长。。。。
同时,感谢学习期间“大师兄”和“饭哥”的帮助~
学习python的第一个小目标:通过requests+xlrd实现简单接口测试,将测试用例维护在表格中,与脚本分开。