Python3简易接口自动化测试框架设计与实现 实例2

目录

  1、开发环境

  2、用到的模块

  3、框架设计 ?3.1、流程

  3.2、项目结构

  5、日志打印

  6、接口请求类封装

  7、Excel数据读取

  7.1、读取配置文件

  7.1、编写Excel操作类

  8、用例组装

  9、用例运行结果校验

  10、运行用例

  11 、小结

  1、开发环境

  操作系统:Ubuntu18

  开发工具:IDEA+PyCharm插件

  Python版本:3.6

  2、用到的模块

  requests:用于发送请求

  xlrd:操作Excel,组织测试用例

  smtplib,email:发送测试报告

  logging:日志追踪

  json:数据格式化

  Django:接口开发

  configparser:读取配置文件

  3、框架设计

  3.1、流程

  接口用例是通过Excel来组织的,定义了URL,Request Body等列。执行流程如下:

  使用xlrd工具读取Excel中的信息,拼接成一个个完整的请求。

  接口请求类拿到一个个完整的请求的去执行,这个过程需要记录日志,每一次执行情况都要有迹可循。

  回填测试结果,发送邮件,归档每次的运行结果。更好一点的做法是把历史运行情况做个报表,更直观。

  优点:

  用例通过Excel来组织,不需要编写代码,上手难度小。

  在用例个数不是很多的情况,开发速度快。

  缺点:

  用例依赖是痛点。

  只能支持接口自动化用例。

  Excel中用例无法预先检查正确性,只有跑一把才能知道。

  无法很好地管理大量用例,且不支持团队协同作业,个人用来回归测试或上线后的冒烟测试会是一个不错的选择。

  通过优缺点的对比,可以明显发现这个框架的硬伤其实很多了。所以无论是业界开源的自动化测试框架或企业自研的还没有见过用Excel来组织用例的。值得一提的是个别企业自研的自动化框架非常难用,抑或是把一堆工具简单组合到一起。根本无法提高团队的生产力。不过好的产品也不是一蹴而就的,需要一个持续优化的过程。所以上面用Excel组织用例的框架还是值的玩一玩的,暂且命名为apitest吧。目前比较好的自动化测试框架有unittest,testng,pytest等。

  3.2、项目结构

  testcase:存放测试用例或请求的json文件。

  config:配置文件。

  report:测试报告和日志文件及其归档。

  untils:工具集,send_request用来发送请求,email_tool用来发送邮件,excel_tool用来读取Excel中的数据,check_result用来校验结果,run_main用例执行入口,log_trace用来追踪日志。

5、日志打印

  采用内置logging模块才记录运行日志,设置日志级别。

  log_trace.log:


   import  logging

  filename = "../report/test_case_run.log"

  logging.basicConfig(level=logging.INFO,

  format=‘%(asctime)s %(levelname)s1 %(filename)s [line:%(lineno)d]  %(message)s‘,

  datefmt=‘%a, %d %b %Y %H:%M:%S‘,

  filename=filename,

  filemode=‘w‘)

  6、接口请求类封装

安装第三方模块requests

 pip install requests

  定义函数send_request,根据传入的方法类型分别去调用request的get,post,delete,put等方法去发送请求。send_request.py:


   import  requests

  from untils. log_trace import  *

  #发送get请求

  def get_request(url,data=None,headers=None):

  res = requests.get(url=url,data=data,headers=headers)

  return res

  #发送post请求

  def post_request(url,data,headers=None):

  res = requests.post(url=url,data=data,headers=headers)

  return res

  #发送delete请求

  def del_request(url,data=None,headers=None):

  res = requests.delete(url,data=data)

  return res

  #发送put请求

  def put_request(url,data,headers=None):

  pass

  def send_request(method,url,data=None,headers=None):

  try:

  logging.info(headers)

  if headers:

  if method == "GET":

  return get_request(url,data,headers=headers)

  if method == "POST":

  return post_request(url,data=data,headers=headers)

  if method == "DELETE":

  return  del_request(url,data=data,headers=headers)

  #put使用频率低,暂时不写

  if method == "PUT":

  return  put_request(url,data=data,headers=headers)

  else:

  logging.info("Header is null")

  except Exception as e:

  logging.info("send request fail:%s"%e)

  在untils_test.py中编写代码测试send_request方法,代码如下:


   #coding:utf-8

  from untils.send_request import send_request

  def test_send_request():

  url="http://127.0.0.1:9000/articles/"

  headers = {

  "X-Token":"0a6db4e59c7fff2b2b94a297e2e5632e"

  }

  res = send_request("GET",url,headers=headers)

  print(res.json())

  if __name__ == "__main__":

  test_send_request()

  运行结果:


   /usr/bin/python3.6 /home/stephen/IdeaProjects/apitest/untils/untils_test.py

  {‘status‘: ‘BS.200‘, ‘all_titles‘: {‘amy1‘: ‘alive‘, ‘modifytest‘: ‘alive‘, ‘addTest‘: ‘alive‘}, ‘msg‘: ‘query articles sucess.‘}

  Process finished with exit code 0

7、Excel数据读取

  用例是放在Excel中的,用xlrd来读取数据,写数据需要用到xluntils,先安装:


  pip install xlrd

  pip install xluntils

  7.1、读取配置文件

  读取Excel数据,我们需要知道对应的行和列,列相对固定,在配置文件settings中定义,然后读取,行作为参数传入。conf/settings文件中的定义如下:

[excel]

  case_no=0

  case_name=1

  is_run=2

  case_level=3

  case_header=4

  case_cookies=5

  req_type=6

  case_url=7

  case_body=8

  expect_result=9

  operator=10

  actual_result=11

  test_result=12

在unitls/load_conf.py中编写读取配置的方法,获取各项列值的方法。lood_conf()函数需要传入两个参数:配置项字符串标识符,配置项类型。比如要读取excel下整数case_url:lood_conf("excel.case_url","int")。class excel_config()下定义返回各项列值的方法。

  完整代码如下:

import  configparser

  ‘‘‘

  read conf from setting.conf

  @:parameter:identstr,value_type

  value_type:"int" or "str"

  ‘‘‘

  def lood_conf(identstr,value_type):

  cf = configparser.ConfigParser()

  cf.read("../config/settings.conf")

  idenlist = identstr.split(‘.‘)

  if value_type == "int":

  try:

  value = cf.getint(idenlist[0],idenlist[1])

  return  value

  except (configparser.NoSectionError ,configparser.NoOptionError) as e:

  print(e)

  if value_type == "str":

  try:

  value = cf.get(idenlist[0],idenlist[1])

  return value

  except (configparser.NoSectionError ,configparser.NoOptionError) as e:

  print(e)

  ‘‘‘

  获取url,request body等的列号

  ‘‘‘

  class excel_config():

  #获取用例编号的列

  def caseno_col(self):

  return lood_conf("excel.case_no","int")

  def casename_col(self):

  return lood_conf("excel.case_name","int")

  def isrun_col(self):

  #print(lood_conf("excel.is_run","int"))

  return lood_conf("excel.is_run","int")

  def level_col(self):

  return lood_conf("excel.case_level","int")

  def header_col(self):

  return lood_conf("excel.case_header","int")

  def cookies_col(self):

  return lood_conf("excel.case_cookies","int")

  def reqtype_col(self):

  return lood_conf("excel.req_type","int")

  def caseurl_col(self):

  return lood_conf("excel.case_url","int")

  def casebody_col(self):

  return lood_conf("excel.case_body","int")

  def expectresult_col(self):

  return lood_conf("excel.expect_result","int")

  def actualresult_col(self):

  return lood_conf("excel.actual_result","int")

  def testresult_col(self):

  return lood_conf("excel.test_result","int")

  def test_operator_col(self):

  return lood_conf("excel.operator","int")

7.1、编写Excel操作类

  unitls/excel_tool.py中定义了获取用例编号,用例名称等方法,需要传入行。回写测试结果,回写实际结果方法需要传入两个参数:行,值。完整代码如下:


   #coding:utf-8

  import xlrd

  from untils.log_trace import *

  from xlutils.copy import copy

  from untils.load_conf import excel_config

  class excel_tool():

  def __init__(self,excel_name):

  self.curr_excel = xlrd.open_workbook(excel_name)

  self.table = self.curr_excel.sheet_by_index(0)

  #print(self.table.cell(1,1).value)

  #实例化excel_config

  self.config = excel_config()

  self.rows = self.table.nrows

  self.excel_name = excel_name

#获取用例编号

  def get_caseno(self,row):

  caseno = self.table.cell(row,self.config.caseno_col()).value

  if caseno:

  return caseno

  else:

  logging.info("case no is null")

  return None

  #获取用例名称

  def get_casename(self,row):

  casename = self.table.cell(row,self.config.casename_col()).value

  return casename

  #获取是否运行标志

  def get_runflag(self,row):

  run_flag = self.table.cell(row,self.config.isrun_col()).value

  return run_flag

  #获取用例级别

  def get_caselevel(self,row):

  caselevel = self.table.cell(row,self.config.level_col()).value

  return caselevel

  #获取请求url

  def get_caseurl(self,row):

  caseurl = self.table.cell(row,self.config.caseurl_col()).value

  return caseurl

  #获取请求body

#获取请求body

  def get_casebody(self,row):

  case_body = self.table.cell(row,self.config.casebody_col()).value

  return case_body

  #获取header

  def get_headerflag(self,row):

  headerflag = self.table.cell(row,self.config.header_col()).value

  return headerflag

  #获取coocikes

  def get_cookiesflag(self,row):

  cookiesflag = self.table.cell(row,self.config.cookies_col()).value

  return cookiesflag

  #获取请求类型

  def get_methodtype(self,row):

  method_type = self.table.cell(row,self.config.reqtype_col()).value

  return method_type

  #获取预期结果

  def get_expectres(self,row):

  expect_res = self.table.cell(row,self.config.expectresult_col()).value

  return expect_res

  #获取测试结果

def get_testres(self,row):

  test_res= self.table.cell(row,self.config.testresult_col()).value

  return test_res

  #获取操作符

  def get_operator(self,row):

  operator = self.table.cell(row,self.config.test_operator_col()).value

  return operator

  #回写测试结果到excel

  def write_testres(self,row,value):

  wbook = copy(xlrd.open_workbook(self.excel_name))

  sheet = wbook.get_sheet(0)

  sheet.write(row, self.config.testresult_col(), value)

  wbook.save(self.excel_name)

  #回写实际结果

  def write_actualres(self,row,value):

  wbook = copy(xlrd.open_workbook(self.excel_name))

  sheet = wbook.get_sheet(0)

  sheet.write(row, self.config.actualresult_col(), value)

  wbook.save(self.excel_name)

 8、用例组装

  有了Excel操作类,就可以方便读取数据和回填结果了。接下来,在unitls/run_main.py中来组装用例。组装之前,先获取是否运行的标志:

  运行标志为N,不组装,将用例标记为skiiped,回填测试结果到Excel文件中。

  运行标志为Y,开始组装用例并执行,并对比预期结果和实际结果。

  用例执行通过,将用例标记为pass,回填测试结果和实际结果,实际结果为接口的返回。

  用例执行失败,将用例标记为failed,回填测试结果和实际结果。

  接口鉴权需要用到的headers,先在run_main.py 中写死,这个问题后面解决,在上面的过程中,增加必要的日志,方便定位问题和查看用例的运行日志。完整代码如下:


#coding:utf-8

  from untils.excel_tool import excel_tool

  from untils.send_request import send_request

  from untils.log_trace import *

  from untils.check_result import CheckResult

  import  json

  headers = {

  "X-Token":"0a6db4e59c7fff2b2b94a297e2e5632e"

  }

  class runner():

  def __init__(self):

  self.excel = excel_tool("../testcase/test.xls")

  self.check = CheckResult()

  def join_case(self):

  global  skip_list,sucess_list,failed_list,skip_list

  sucess_list = []

  sucess_list = []

  failed_list = []

  skip_list = []

  for row in range(1,self.excel.rows):

  no = self.excel.get_caseno(row)

  url = self.excel.get_caseurl(row)

  isrun = self.excel.get_runflag(row)

  name = self.excel.get_casename(row)

  level = self.excel.get_caselevel(row)

  data = self.excel.get_casebody(row)

  expect_res = self.excel.get_expectres(row)

  method = self.excel.get_methodtype(row)

  hasheader = self.excel.get_headerflag(row)

  operator = self.excel.get_operator(row)

  if isrun == "Y":

  logging.info("Begin to run test case : %s,case number :%s" %(name,no))

  logging.info("Request method type is :%s" %method)

  logging.info("Request URL:%s" %url)

  logging.info("Request Body:%s" %json.dumps(json.loads(data),sort_keys=True,indent=2))

  res = send_request(method,url,data=data,headers=headers)

  is_sucess = self.check.cmpdict(eval(expect_res),eval(res.text),operator)

  print(is_sucess)

  if is_sucess:

  sucess_list.append(name)

  #回写测试结果

  self.excel.write_testres(row,"pass")

  #回写实际结果

  self.excel.write_actualres(row,res.text)

  logging.info("Test case %s run sucess." %name)

  else:

  failed_list.append(name)

  print("fail",is_sucess)

  #回写测试结果

  self.excel.write_testres(row,"failed")

  #回写实际结果

  self.excel.write_actualres(row,res.text)

  logging.error("Test case %s run fail." %name)

  logging.info("Response is:%s" %json.dumps(res.json(),sort_keys=True,indent=2))

  else:

  skip_list.append(name)

  self.excel.write_testres(row,"skipped")

  def sum(self):

  total = len(sucess_list)+len(failed_list) + len(skip_list)

  failed = len(failed_list)

  sucess = len(sucess_list)

  logging.info("-----------------------------------------------------------")

  logging.info("本次一共运行:%s 个用例" %total)

  logging.info("本次运行通过:%s 个用例" %sucess)

  logging.info("本次运行跳过:%s 个用例" %len(skip_list))

  logging.info("跳过的用例:%s" %skip_list)

  logging.info("-----------------------------------------------------------")

  9、用例运行结果校验

  在untils/run_main.py中方法cmpdict()是用来校验预期和结果实际结果是否匹配,需要传入三个参数:预期结果字典,实际结果字典,操作符。在check_result.py中编写校验用例结果的方法。目前只支持两种操作符,equal和notequal,预期结果为字典,其中不能嵌套字典。和完整代码如下:

from untils.log_trace import *

  class  CheckResult():

  def dict_value(self,key,actual):

  try:

  if key in actual:

  return actual[key]

  else:

  for keys in actual:

  return self.dict_value(key,actual[keys])

  except Exception as e:

  logging.error(e)

  return None

  def cmpdict(self,expect,actual,equal):

  logging.info("Begin to check result of  testcase.")

  is_dict = isinstance(expect,dict) and isinstance(actual,dict)

  if is_dict:

  if equal == "equal":

  for key in expect.keys():

  if expect[key] == self.dict_value(key,actual):

  logging.info("%s is equal to %s" %(expect[key],self.dict_value(key,actual)))

  return True

  else:

 


logging.error("%s is not equal to %s" %(expect[key],self.dict_value(key,actual)))

  return False

  if equal == "notequal":

  for key in expect.keys():

  if key != self.dict_value(key,actual):

  logging.info("%s is not equal to %s" %(expect[key],self.dict_value(key,actual)))

  return True

  else:

  logging.error("%s is equal to %s" %(expect[key],self.dict_value(key,actual)))

  return False

  else:

  logging.error("Operator :%s is not support now,you can define it in file[check_result.py]" %equal)

  else:

  logging.error("Expect or actual  result is not dict,check it in  excel. ")

  10、运行用例

  新建一个名称为test.xls的Excel,将其放到testcase路径下,并在Excel中编写测试用例。接口开发请参考:使用Django开发简单接口:文章增删改查,我准备的用例如下:

  在untils/untils_test.py中导入run_mian模块来测试一下:


   from untils.run_main import runner

  if __name__ == "__main__":

  #test_send_request()

  runner = runner()

  runner.join_case()

  runner.sum()

  

运行untils_test.py,然后去到Excel中查看运行结果:

report路径下查看测试用例运行日志,如下所示:

Sat, 11 May 2019 19:37:56 INFO check_result.py [line:16]  Begin to check result of  testcase.

  Sat, 11 May 2019 19:37:56 ERROR check_result.py [line:38]  Operator :e1qual is not support now,you can define it in file[check_result.py]

  Sat, 11 May 2019 19:37:56 INFO run_main.py [line:37]  Begin to run test case : 查询文章,case number :1.0

  Sat, 11 May 2019 19:37:56 INFO run_main.py [line:38]  Request method type is :GET

  Sat, 11 May 2019 19:37:56 INFO run_main.py [line:39]  Request URL:http://127.0.0.1:9000/articles

  Sat, 11 May 2019 19:37:56 INFO run_main.py [line:40]  Request Body:{}

  Sat, 11 May 2019 19:37:56 INFO send_request.py [line:25]  {‘X-Token‘: ‘0a6db4e59c7fff2b2b94a297e2e5632e‘}

  Sat, 11 May 2019 19:37:56 INFO check_result.py [line:16]  Begin to check result of  testcase.

  Sat, 11 May 2019 19:37:56 INFO check_result.py [line:22]  BS.200 is equal to BS.200

  Sat, 11 May 2019 19:37:56 INFO run_main.py [line:52]  Test case 查询文章 run sucess.

  Sat, 11 May 2019 19:37:56 INFO run_main.py [line:62]  Response is:{

  "all_titles": {

  "Hello": "alive",

  "amy1": "alive",

  "modifytest": "alive",

  "useasge of ddt": "alive"

  },

  "msg": "query articles sucess.",

"status": "BS.200"

  }

  Sat, 11 May 2019 19:37:56 INFO run_main.py [line:37]  Begin to run test case : 新增文章,case number :2.0

  Sat, 11 May 2019 19:37:56 INFO run_main.py [line:38]  Request method type is :POST

  Sat, 11 May 2019 19:37:56 INFO run_main.py [line:39]  Request URL:http://127.0.0.1:9000/articles/

  Sat, 11 May 2019 19:37:56 INFO run_main.py [line:40]  Request Body:{

  "content": "useasge of ddt",

  "title": "useasge of ddt"

  }

  Sat, 11 May 2019 19:37:56 INFO send_request.py [line:25]  {‘X-Token‘: ‘0a6db4e59c7fff2b2b94a297e2e5632e‘}

  Sat, 11 May 2019 19:37:56 INFO check_result.py [line:16]  Begin to check result of  testcase.

  Sat, 11 May 2019 19:37:56 ERROR check_result.py [line:25]  BS.200 is not equal to BS.400

  Sat, 11 May 2019 19:37:56 ERROR run_main.py [line:60]  Test case 新增文章 run fail.

  Sat, 11 May 2019 19:37:56 INFO run_main.py [line:62]  Response is:{

  "msg": "title aleady exist,fail to publish.",

  "status": "BS.400"

  }

  Sat, 11 May 2019 19:37:56 INFO run_main.py [line:37]  Begin to run test case : 修改文章,case number :3.0

Sat, 11 May 2019 19:37:56 INFO run_main.py [line:38]  Request method type is :POST

  Sat, 11 May 2019 19:37:56 INFO run_main.py [line:39]  Request URL:http://127.0.0.1:9000/articles/7

  Sat, 11 May 2019 19:37:56 INFO run_main.py [line:40]  Request Body:{

  "content": "modify test",

  "title": "modify test"

  }

  Sat, 11 May 2019 19:37:56 INFO send_request.py [line:25]  {‘X-Token‘: ‘0a6db4e59c7fff2b2b94a297e2e5632e‘}

  Sat, 11 May 2019 19:37:57 INFO check_result.py [line:16]  Begin to check result of  testcase.

  Sat, 11 May 2019 19:37:57 ERROR check_result.py [line:25]  BS.200 is not equal to BS.300

  Sat, 11 May 2019 19:37:57 ERROR run_main.py [line:60]  Test case 修改文章 run fail.

  Sat, 11 May 2019 19:37:57 INFO run_main.py [line:62]  Response is:{

  "msg": "article is not exists,fail to modify.",

  "status": "BS.300"

  }

  Sat, 11 May 2019 19:37:57 INFO run_main.py [line:37]  Begin to run test case : 删除文章,case number :4.0

  Sat, 11 May 2019 19:37:57 INFO run_main.py [line:38]  Request method type is :DELETE

  Sat, 11 May 2019 19:37:57 INFO run_main.py [line:39]  Request URL:http://127.0.0.1:9000/articles/7

  Sat, 11 May 2019 19:37:57 INFO run_main.py [line:40]  Request Body:{}

  Sat, 11 May 2019 19:37:57 INFO send_request.py [line:25]  {‘X-Token‘: ‘0a6db4e59c7fff2b2b94a297e2e5632e‘}

  Sat, 11 May 2019 19:37:57 INFO check_result.py [line:16]  Begin to check result of  testcase.

  Sat, 11 May 2019 19:37:57 ERROR check_result.py [line:25]  BS.200 is not equal to BS.300

  Sat, 11 May 2019 19:37:57 ERROR run_main.py [line:60]  Test case 删除文章 run fail.

  Sat, 11 May 2019 19:37:57 INFO run_main.py [line:62]  Response is:{

  "msg": "article is not exists,fail to delete.",

  "status": "BS.300"

  }

  Sat, 11 May 2019 19:37:57 INFO run_main.py [line:74]  -----------------------------------------------------------

  Sat, 11 May 2019 19:37:57 INFO run_main.py [line:75]  本次一共运行:5 个用例

  Sat, 11 May 2019 19:37:57 INFO run_main.py [line:76]  本次运行通过:1 个用例

  Sat, 11 May 2019 19:37:57 INFO run_main.py [line:77]  本次运行跳过:1 个用例

  Sat, 11 May 2019 19:37:57 INFO run_main.py [line:78]  跳过的用例:[‘新增文章缺少title‘]

  Sat, 11 May 2019 19:37:57 INFO run_main.py [line:79]  -----------------------------------------------------------

11 、小结

  框架终于能跑起来了,但是遗留的问题还很多。

  很多地方的代码不够健壮,这个后面慢慢优化。还有用例校验支持的运算符比较少。

  发送邮件模块待完成。

  Headers的问题如何解决?

  如果请求的body比较多,写在Excel是不是很不美观呀?这个可以从固定地方读取文件来完成。

  Excel中测试用例有没有必填项呀?这个可以在运行结果之前进行校验,必填项缺少,不运行。

  最关键的一点,如果第二个用例依赖于第一个用例的返回,用例依赖一直是个痛点,下一篇解决。

  还有很多问题比如,重试机制,耗时的用例设置超时时间,超时默认为失败等等.......

原文地址:https://www.cnblogs.com/bzdmz/p/10934173.html

时间: 2024-07-31 02:40:56

Python3简易接口自动化测试框架设计与实现 实例2的相关文章

【python3+request】python3+requests接口自动化测试框架实例详解教程

转自:https://my.oschina.net/u/3041656/blog/820023 前段时间由于公司测试方向的转型,由原来的web页面功能测试转变成接口测试,之前大多都是手工进行,利用postman和jmeter进行的接口测试,后来,组内有人讲原先web自动化的测试框架移驾成接口的自动化框架,使用的是java语言,但对于一个学java,却在学python的我来说,觉得python比起java更简单些,所以,我决定自己写python的接口自动化测试框架,由于本人也是刚学习python,

从接口自动化测试框架设计到开发(五)--case运行结果统计、发送邮件

1.case运行结果统计 #Run_Test.py# -*- coding: utf-8 -*- # @Author: jiujiu # @Date: 2020-03-04 16:30:31 # @Last Modified time: 2020-03-07 10:05:52 import sys sys.path.append("G:/uni_test") #添加当前过程的目录 import json from base.run_method import RunMethod fro

Python接口自动化测试框架实战 从设计到开发

第1章 课程介绍(不要错过)本章主要讲解课程的详细安排.课程学习要求.课程面向用户等,让大家很直观的对课程有整体认知! 第2章 接口测试工具Fiddler的运用本章重点讲解如何抓app\web的http\https请求包.如何模拟请求数据.过滤规则及修改响应数据.如何解决无法抓包问题        以及fiddler接口测试,让大家能应用好工具! 第3章 Requests常见方法实战运用本章重点讲解 get\post请求测试.接口测试中结果处理.上传\下载文件接口测试.请求中header及coo

Python+requests+exce接口自动化测试框架

一.接口自动化测试框架 二.工程目录 三.Excel测试用例设计 四.基础数据base 封装post/get:runmethod.py #!/usr/bin/env python3 # -*-coding:utf-8-*- # __author__: hunter import requests import json class RunMain: def send_get(self, url, data): res = requests.get(url=url, params=data).js

基于Python接口自动化测试框架(初级篇)附源码

引言 很多人都知道,目前市场上很多自动化测试工具,比如:Jmeter,Postman,TestLink等,还有一些自动化测试平台,那为啥还要开发接口自动化测试框架呢?相同之处就不说了,先说一下工具的局限性: 1.测试数据不可控:    接口虽然是对业务逻辑.程序代码的测试,而实际上是对数据的测试,调用接口输入一批数据,通过断言代码验证接口返回的数据,整个过程围绕数据测试.    如果返回的数据不是固定的,是变化的,那么断言失败,就无法知道是接口程序错误引起的,还是数据变化引起的,所以就需要进行测

Python 基于python实现的http+json协议接口自动化测试框架源码(实用改进版)

目录 1.      写在前面 2.      开发环境 3.      大致流程 4.      框架简介 5.      运行结果展示 6.      文件与配置 7.      测试接口实例 n      1.登陆接口 n      2.支付密码更改接口 8.      数据库设计 9.      测试用例.测试数据准备 10.        模块与类.函数设计 11.        代码实现 a)         class congfighttp.ConfigHttp b)      

python+requests接口自动化测试框架实例详解教程

转自https://my.oschina.net/u/3041656/blog/820023 摘要: python + requests实现的接口自动化框架详细教程 前段时间由于公司测试方向的转型,由原来的web页面功能测试转变成接口测试,之前大多都是手工进行,利用postman和jmeter进行的接口测试,后来,组内有人讲原先web自动化的测试框架移驾成接口的自动化框架,使用的是java语言,但对于一个学java,却在学python的我来说,觉得python比起java更简单些,所以,我决定自

python3+request接口自动化框架

首次书写博客,记录下写的自动化接口框架,框架比较简单,哈哈哈,算是记录下历程把!~~~ 一.本次框架由python3.6 书写 1.准备代码环境,下载python3.6    下载地址:https://www.python.org/downloads 2.下载pycharm 软件. 二.开始创建python接口自动化框架: 1.这是我创建的框架中的各个文件夹,分别有config  配置文件夹.fengzhuang   将接口用get post  两种传输方式进行封装并自动来区分执行. 2.log

接口自动化测试框架 -- reudom

reudom Automated testing framework based on requests and unittest interface. 基于 Unittest 和 Requests 的 接口自动化测试框架 介绍 基于Unittest/Requests的接口自动化测试库 提供脚手架,快速生成接口自动化测试项目. 自动生成HTML测试报告. 支持用例参数化. 支持用例失败重跑 对原生Requests库API无损 目录架构 myreudom/ ├── test_case/ │ ├──