测试用例基类:

# coding=utf-8

import unittest
import Logger log = Logger.Loger()
class BaseCase(unittest.TestCase): def setUp(self):
self.loginfo("============================================================")
self.loginfo("%s is start" % self )
#print self._attribute.decode('utf=8') def tearDown(self):
self.loginfo('test is stop')
self.loginfo("============================================================\n") def loginfo(self, msgStr):
log.info(msgStr) if __name__ == "__main__":
unittest.main()

接口用例InterfaceTestCase.py

#coding=utf-8
import unittest
import requests
from interfacetest.iutil import DataEngine
from interfacetest.iutil import HttpEngine
from IFBaseCase import BaseCase
import datetime
import Utils
import ConfigParser class DoInterfaceTest(BaseCase): def runTest(self):
sttime = datetime.datetime.now()
domain,caselist,header = DataEngine.getCase() #读取Excel获取用例数据
self.loginfo("domain:"+domain)
self.loginfo("header:"+str(header)+"\n")
resultlist = [] for case in caselist:
'''
case[0] 序号 case[1] 优先级 case[2] 模块 case[3] 用例描述 case[4] 是否登录
case[5] 接口url case[6] 方法 case[7] 参数 case[8] 期望结果
'''
self.loginfo("url:"+case[5])
self.loginfo("method:"+case[6]) starttime = datetime.datetime.now()
url = domain+case[5] #拼接请求url
method = case[6] #请求方法:post、get、delete
data = eval(case[7]) #请求数据 sess=object
isexcept = False
if case[4] == "Y": #是否需要登录
sess,isexcept = HttpEngine.login() #返回登录的session和登录是否异常
else:
sess = requests.Session() result = "Failed"
actualre = ""
if isexcept: #如果登录异常,直接中断
actualre = sess
else: #没有登录异常,继续执行
re,isexcept = HttpEngine.getData(sess, url, data, header, method) #发送请求并获取响应结果
if isexcept: #如果请求异常,直接中断
actualre = re
else:
result,actualre = DataEngine.resultCheck(re, case[8]) #结果匹配 if "password" in case[7]:
temp = eval(case[7])
temp['password'] = "******"
case[7] = temp
self.loginfo("data:"+str(case[7]))
self.loginfo("结果:"+result+", 请求返回:"+actualre+"\n") stoptime = datetime.datetime.now()
takentime = ((stoptime-starttime).microseconds)/1000 #获取时间差,单位为毫秒
if len(actualre) > 43:
actualre = actualre[:43]+" ..."
actualre = actualre.replace('<','&lt;').replace('>','&gt;') result_temp = [case[2], case[3], case[5], case[7], actualre, result, takentime]
resultlist.append(result_temp)
sptime = datetime.datetime.now()
passcount,failcount = DataEngine.countResult(resultlist) #统计结果
totalcount = len(resultlist)
tktime = ((sptime-sttime).microseconds)/1000/1000.000 #整体耗时,单位为秒
sttime = sttime.strftime("%Y-%m-%d %H:%M:%S")
tinfo = {'starttime':sttime, 'takentime':tktime, 'pass':passcount, 'fail':failcount, 'total':totalcount}
conf = ConfigParser.ConfigParser()
conf.read("config.conf")
reportfile = conf.get("report", "report_path")
logfile = conf.get("report", "log_path")
Utils.createInterfaceReport(resultlist, tinfo, reportfile, logfile) if __name__ == "__main__":
unittest.main()

Python web功能&接口自动化测试框架搭建——接口用例实现

Python web功能&接口自动化测试框架搭建——接口公共方法

Python web功能&接口自动化测试框架搭建——接口测试模块

Python web功能&接口自动化测试框架搭建——功能测试模块

Python web功能&接口自动化测试框架搭建——测试用例执行和结果收集

Python web功能&接口自动化测试框架搭建——通用模块

Python web功能&接口自动化测试框架搭建——unittest介绍

Python web功能&接口自动化测试框架搭建——环境搭建

python web自动化测试框架搭建(功能&接口)——接口用例实现的更多相关文章

  1. python web自动化测试框架搭建(功能&接口)——接口公共方法

    接口公共方法有:数据引擎.http引擎.Excel引擎 1.数据引擎:获取用例.结果检查.结果统计 # -*- coding:utf-8 -*- from XlsEngine import XlsEn ...

  2. python web自动化测试框架搭建(功能&接口)——接口测试模块

    Python接口测试采用python读取excel的方法,通过requests库发送请求和接收响应.模块有: Data:用于存放excel用例的,用例格式: iutil: 接口公共方法,数据引擎.ht ...

  3. python web自动化测试框架搭建(功能&接口)——功能测试模块

    功能测试使用selenium,模块有: 1.futil: 公共方法,如元素高亮显示 # coding=utf-8 """高亮显示元素""" ...

  4. python web自动化测试框架搭建(功能&接口)——测试用例执行和结果收集

    由于unittest框架中结果收集在不同文件中,所以此处重写结果收集方法,加入执行时间,失败信息,失败截图等 TestRunner.py # coding=utf-8 import sys impor ...

  5. python web自动化测试框架搭建(功能&接口)——通用模块

    1.通用模块: config.conf: 公共配置文件,配置报告.日志.截图路径,以及邮件相关配置 [report] reportpath = E:\workspace\WebAutomation\s ...

  6. Python web自动化测试框架搭建(功能&接口)——unittest介绍

    Python UnitTest测试框架介绍 1)         TestCase:所有测试用例类继承的基本类, TestCase的实例就是测试用例 2)         TestSuite:测试套件 ...

  7. python web自动化测试框架搭建(功能&接口)——环境搭建

    自动化测试框架一般需要实现以下通用功能 执行前准备 结束后清理 执行步骤输出 执行结果输出 错误.失败截图 测试报告 发送邮件 日志 需要的软件和python第三方库有: 通用: JDK Eclips ...

  8. 基于python的自动化测试框架搭建

    滴~ 今日打卡!   好多天没来打卡了.博主最近一直在把碎片化知识转化为知识体系的过程中挣扎.Python语言.selenium.unittest框架.HTMLTestRunner框架都有所了解,也写 ...

  9. selenium +python web自动化测试环境搭建

    基础框架搭建 1.安装python 2.安装selenium cmd输入pip install selenium 问题:在python中输入from selenium import webdriver ...

随机推荐

  1. hibernate的get方法和load方法区别

    读者需注意:Hibernate版本不同,运行机制不太一样,以下是hibernate3.x作为讲解 get方法: Hibernate会确认一下该id对应的数据是否存在,首先在session缓存中查找,然 ...

  2. Leetcode Lect3 内存中的栈空间与堆空间

    内存中的栈空间与堆空间 我们通常所说的内存空间,包含了两个部分:栈空间(Stack space)和堆空间(Heap space) 当一个程序在执行的时候,操作系统为了让进程可以使用一些固定的不被其他进 ...

  3. go中基本数据类型转换为string类型的方法

    代码 // 基本数据类型转换为string类型 package main import ( "fmt" "strconv" ) func main() { // ...

  4. 异步json发送put或者delete

    第一种 put请求或者delete请求 直接写发送的情况 //批量删除 function batchDel() { var ids = []; $("#list-table").f ...

  5. Hugin

    Hugin简介 Hugin是一个开源的拼接软件,包含大量的拼接所需模块源码以及使用了部分Panorama Tools中的工具. 1)libpano13(Panorama Tools). 2)cpfin ...

  6. $mona$要成为高端玩家

    \(mona\)要成为高端玩家! 好在撑过了联赛,接下来要向高端玩家冲击啦! 新时期当然要有新的学习规划啦! 最近的更新(有什么就在这里说啦) 随便更更. \(FFT\)刷着打算先看看生成函数. 感觉 ...

  7. configerparser模块

    '''[mysqld]charater-server-set='utf8'default-engine='innodb'skip-grant-table=Trueport=3306 [client]u ...

  8. Conservation Vs Non-conservation Forms of conservation Equations

    What does it mean? The reason they are conservative or non-conservative has to do with the splitting ...

  9. IndexError: list index out of range的错误原因

    第1种可能情况list[index]index超出范围 第2种可能情况list是一个空的 没有一个元素进行list[0]就会出现该错误 ————————————————版权声明:本文为CSDN博主「m ...

  10. 【CF1257E】The Contest【线段树】

    题意:给定三个序列abc,问最少操作几次使得满足a<b<c 题解:将三个序列合并起来,设cnt[i][1/2/3]表示前i个数有几个是来自序列1/2/3的. 枚举第一个序列要到i,此时对于 ...