学习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 = sheet1.col_values(0)  # 获取表格第一列的数据
12 row_data = 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 = sheet1.col_values(0)  # 获取第一列的数据

        for i in range(1, nrow):  # 循环每行,并获取每行每列的值,第0行是标题,所以从第一行开始取
             row_data = 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=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=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 = sheet1.col_values(0)  # 获取第一列的数据

    for i in range(1, nrow):  # 循环每行,并获取每行每列的值
         row_data = 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,对其理解也比较浅。身为一名测试工程师,有着一颗摆脱手工测试,进阶到自动化测试的心,后面的路还很长。。。。

同时,感谢学习期间“大师兄”和“饭哥”的帮助~

时间: 2024-11-02 23:26:23

学习python的第一个小目标:通过requests+xlrd实现简单接口测试,将测试用例维护在表格中,与脚本分开。的相关文章

Python爬虫——第一个小爬虫01

Python小爬虫——贴吧图片的爬取 在对Python有了一定的基础学习后,进行贴吧图片抓取小程序的编写. 目标: 首先肯定要实现图片抓取这个基本功能 然后要有一定的交互,程序不能太傻吧 最后实现对用户所给的链接进行抓取 一.页面获取 要让python可以进行对网页的访问,那肯定要用到urllib之类的包.So先来个 import urllib urllib中有 urllib.urlopen(str) 方法用于打开网页并返回一个对象,调用这个对象的read()方法后能直接获得网页的源代码,内容与

学习Python的第一课(简单的单元测试)

由于有C#开发基础,感觉学习Python应该不难,主要是一些语法了,再加上现在互联网这么发达. 感觉还是要有思路,否则学什么也只能是什么. 话不多说,简单发下这几天的学习成果吧: 第一次写博客,大家不要见笑啊 简单的语法就不多说了,随便搜搜就可以得到.() 单元测试来了: 要做两个测试: # 用于判断质数 import math def isPrime(n): print ("验证数字"+str(n)+"是否质数开始") print ("开平方:"

《Mysql 公司职员学习篇》 第一章 小A的烦恼

第一章  小A的烦恼 ----- 为什么学习数据库 和 如何选择数据库 小A是某公司的职员,公司数据部的员工,平常的大小工作,完全离不开EXCELL,而最近小A却越来越苦恼,不由的向好朋友小Y吐槽.小Y是某互联网公司的程序员,拥有多年开发经验. 小Y:"小A,你最近'印堂发黑',越来越疲劳无力,怎么?工作上遇见什么难题了?". 小A:"唉,别提了,最近公司发展迅速,数据量越来越大,我那'极品'电脑,关打开EXCELL就要卡个半天,再加上处理和计算,一天下来,卡顿的时间,都够我

零基础学习python,第一天

python入门在网上看了一遍 关键是不会用 通过做一个在线会议 小项目慢慢练习使用 python连接数据库,python使用的是3.6版本,由于 MySQLdb 模块还不支持 Python3.x,所以 Python3.x 如果想连接MySQL需要安装 pymysql 模块. pymysql 模块可以通过 pip 安装.pip install pymysql 安装PHPstudy phpStudy是一个PHP调试环境的程序集成包. 该程序包集成最新的Apache+PHP+MySQL+phpMyA

学习Python爬虫第一步,Bs4库

首先是安装BS4库 因为Python的pip真的很方便,所以一般不出意外,只需要一个pip就足以完成一个库的安装. pip install beautifulsoup4 名字很长不要记错名字呦. 想要利用爬虫获得我们想要的内容,就一定要学会一个解析HTML的库. 我们总不能用正则表达式,匹配出我们需要的内容,那任务量一定是巨大的,繁琐的,很少有人去那么做,除非你就是需要这个网页中特定的元素. 怎么使用BS4库? Bs4库和有些库还有一些不同,像我们学习爬虫一定要学习的requests库,我们只需

小白学习Python【第一天(简介和安装)】

Python简介 Python来历            1989年的圣诞节期间,python的创始人为吉多·范罗苏姆(Guido van Rossum)为了在阿姆斯特丹打发时间,开发了Python. Python语言排行    最新的TIOBE排行榜,Python赶超PHP占据第五!!! Python应用      Python可以应用于众多领域,互联网公司广泛使用Python来做的事:[自动化测试]哈哈....这个我们测试人员最关注.大数据分析.爬虫.自动化运维.Web等. 国内使用Pyth

学习python的第一天

Python基础一 1,python历史. 宏观上:python2 与 python3 区别: python2 源码不标准,混乱,重复代码太多, python3 统一 标准,去除重复代码.2,python的环境. 编译型:一次性将所有程序编译成二进制文件. 缺点:开发效率低,不能跨平台. 优点:运行速度快. :C,C++等等. 解释型:当程序执行时,一行一行的解释. 优点:开发效率高,可以跨平台. 缺点:运行速度慢. :python ,php,等等. 3,运行第一个py文件: python3x

Python零基础好学吗?零基础如何学习Python?

现在越来越多的人想要学习Python课程,在学习Python的过程中不少人都会关注学习Python难吗?今天小编就为大家详细的解读一下吧. 0基础学习Python语言可以吗?首先个人认为可以的,Python是一门非常适合入门的编程语言. Python语法简单明了,代码可读性很高,容易入门;对于初学者规范自己的学习有很大的帮助,同时还可以帮助初学者看懂别人的代码. Python对于代码的要求是非常严谨的,对于初学者可以养成良好的代码习惯;同时Python的语法设计非常优秀,思想也比较现代化,可以更

学习Python需要用什么开发工具?

最近有不少读者私信我,这不刚开始学习Python就开始遇到难题了,对于Python IDE都比较纠结,希望找到一些适合自己的.Python开发工具.本篇给大家分享几款Python开发工具,供正在纠结用哪种开发工具的小伙伴们参考~ 对于学习Python的小伙伴,小编首推的Pycharm. 首先,PyCharm用于一般IDE具备的功能,比如, 调试.语法高亮.Project管理.代码跳转.智能提示.自动完成.单元测试.版本控制 另外,PyCharm还提供了一些很好的功能用于Django开发,同时支持