python web自动化测试框架搭建(功能&接口)——接口用例实现
测试用例基类:
# 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('<','<').replace('>','>') 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自动化测试框架搭建(功能&接口)——接口公共方法
接口公共方法有:数据引擎.http引擎.Excel引擎 1.数据引擎:获取用例.结果检查.结果统计 # -*- coding:utf-8 -*- from XlsEngine import XlsEn ...
- python web自动化测试框架搭建(功能&接口)——接口测试模块
Python接口测试采用python读取excel的方法,通过requests库发送请求和接收响应.模块有: Data:用于存放excel用例的,用例格式: iutil: 接口公共方法,数据引擎.ht ...
- python web自动化测试框架搭建(功能&接口)——功能测试模块
功能测试使用selenium,模块有: 1.futil: 公共方法,如元素高亮显示 # coding=utf-8 """高亮显示元素""" ...
- python web自动化测试框架搭建(功能&接口)——测试用例执行和结果收集
由于unittest框架中结果收集在不同文件中,所以此处重写结果收集方法,加入执行时间,失败信息,失败截图等 TestRunner.py # coding=utf-8 import sys impor ...
- python web自动化测试框架搭建(功能&接口)——通用模块
1.通用模块: config.conf: 公共配置文件,配置报告.日志.截图路径,以及邮件相关配置 [report] reportpath = E:\workspace\WebAutomation\s ...
- Python web自动化测试框架搭建(功能&接口)——unittest介绍
Python UnitTest测试框架介绍 1) TestCase:所有测试用例类继承的基本类, TestCase的实例就是测试用例 2) TestSuite:测试套件 ...
- python web自动化测试框架搭建(功能&接口)——环境搭建
自动化测试框架一般需要实现以下通用功能 执行前准备 结束后清理 执行步骤输出 执行结果输出 错误.失败截图 测试报告 发送邮件 日志 需要的软件和python第三方库有: 通用: JDK Eclips ...
- 基于python的自动化测试框架搭建
滴~ 今日打卡! 好多天没来打卡了.博主最近一直在把碎片化知识转化为知识体系的过程中挣扎.Python语言.selenium.unittest框架.HTMLTestRunner框架都有所了解,也写 ...
- selenium +python web自动化测试环境搭建
基础框架搭建 1.安装python 2.安装selenium cmd输入pip install selenium 问题:在python中输入from selenium import webdriver ...
随机推荐
- JAVA总结--多线程
一.概念 1.进程:一个具有一定独立功能的程序,关于某些数据集合,一次运行活动. 两点:1.有自己的空间存储数据:2.一个程序. 进程,是系统 进行 资源分配 和 调度 的基础单位.动态性 ...
- 详解 HiveUDF 函数
更多精彩原创内容请关注:JavaInterview,欢迎 star,支持鼓励以下作者,万分感谢. Hive 函数 相信大家对 Hive 都不陌生,那么大家肯定用过 Hive 里面各种各样的函数.可能大 ...
- VUE:v-for获取列表前n个数据、中间范围数据、末尾n条数据的方法
说明: 1.开发使用的UI是mintUI, 要求: 1.获取6到13之间的数据:items.slice(6,13) <mt-cell v-for="(item,index) in it ...
- Java JNA (四)—— void**、void*、char**、char*、int*等类型映射关系及简单示例
ByReference类有很多子类,这些类都非常有用. ByteByReference.DoubleByReference.FloatByReference. IntByReference.LongB ...
- Cocos2d-x视频教程
目录 1. 我的技术专栏 2. 相关推荐 3. 下载链接 4. cocos2d-xx Lua+JS+C++教学视频 5. 杨丰盛Cocos2D-X游戏课程 6. [Cocos2d-x]塔防游戏开发实战 ...
- C# 获取一个文件的MD5值
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Tex ...
- Android App渗透测试工具汇总
网上搜集了一些App安全学习教程及工具,项目地址:https://github.com/Brucetg/App_Security 一. drozer简介 drozer(以前称为Mercury)是一款A ...
- 关于BFC的总结
虽然工作这么多年了,但是如果让我直接解释一下什么是BFC的时候,还是感觉有点不知道怎么准确的表达,下面就翻翻文档,总结一下,加深一下认识吧.大家也可以关注我的GitHub后续的更新 1.BFC的基本概 ...
- 【leetcode】1039. Minimum Score Triangulation of Polygon
题目如下: Given N, consider a convex N-sided polygon with vertices labelled A[0], A[i], ..., A[N-1] in c ...
- 【leetcode】816. Ambiguous Coordinates
题目如下: 解题思路:我的方案是先把S拆分成整数对,例如S='1230',先拆分成(1,230),(12,30),(123,0),然后再对前面整数对进行加小数点处理.比如(12,30)中的12可以加上 ...