zoukankan      html  css  js  c++  java
  • 简单使用 Requests+Python2 接口测试 读取 Excel 完成接口测试

    代码块

    import xlrd
    import unittest
    import requests,json

    class Test(unittest.TestCase):
    def duqu(self, filename=r'E: estproject est_case est.xlsx'): # 读取 Excel文件
    data = xlrd.open_workbook(filename) # 打开文件把参数传给 data
    table = data.sheets()[0] # 通过索引顺序获取Excel 文件
    parameter = table.row_values(1) # 获取整行数据 获取Excel 第二行数据
    jsoninfo = eval(parameter[3]) # 因为 parameter 变量类型是str 需要用eval函数转换成dict
    url = 'http://基础url地址' + parameter[2] # 基础地址 加上测试接口测路径
    return url,parameter[1], jsoninfo

    def test_requests(self):
    auth = self.duqu() # 调用 duqu 函数
    head = {
    "platform": "ios",
    "xnServer": "aio-app-server",
    "version": "1.0.0",
    "Content-Type": "application/json"
    }
    # requests库作为接口核心,传入url,post请求,json参数
    res = requests.request("%s" % auth[1], auth[0], json=auth[2],headers=head)
    self.assertEqual(res.status_code, 200) # 断言code 是否等于200
    self.assertNotIn(res.text, '"ret":0')



    if __name__=='__main__':
    unittest.main()



    test.xlsx

  • 相关阅读:
    第3次实践作业
    第2次实践作业
    第09组 团队Git现场编程实战
    第二次结对编程作业
    团队项目-需求分析报告
    团队项目-选题报告
    第一次结对编程作业
    第一次个人编程作业
    第一次博客作业
    课程设计第十四天
  • 原文地址:https://www.cnblogs.com/txx403341512/p/9529556.html
Copyright © 2011-2022 走看看