python学习笔记(接口自动化框架 V1.0)
之前是利用python自带的unittest测试框架
这次自己设计一个 之后再一点点往里面加功能
(ps:当然这个框架真的是很简单。。很简单。。。很简单。。。)
excel文件格式:

#!/usr/bin/env python
# -*- coding: utf_8 -*- import xlrd
import json class CreateExcel:
def __init__(self):
pass @classmethod
def open_excel(cls):
path = "testcase.xls"
workbook = xlrd.open_workbook(path)
table = workbook.sheets()[0]
return table
# 获取sheet @classmethod
def get_nrows(cls, table):
nrows = table.nrows
return nrows
# 获取行号 @classmethod
def get_name(cls, table, nrows):
testname = []
for i in range(1, nrows):
testname.append(table.cell(i, 0).value)
return testname
# 获取用例name @classmethod
def get_data(cls, table, nrows):
testdata = []
for i in range(1, nrows):
data = json.loads(table.cell(i, 1).value)
testdata.append(data)
return testdata
# 获取data接口参数 @classmethod
def get_url(cls, table, nrows):
testurl = []
for i in range(1, nrows):
testurl.append(table.cell(i, 2).value)
return testurl
# 获取接口测试url @classmethod
def get_method(cls, table, nrows):
testmethod = []
for i in range(1, nrows):
testmethod.append(table.cell(i, 3).value)
return testmethod
# 获取接口测试method @classmethod
def get_pattern(cls, table, nrows):
testpattern = []
for i in range(1, nrows):
testpattern.append(table.cell(i, 4).value)
return testpattern
# 获取接口期望响应结果 @classmethod
def get_report(cls, table, nrows):
testreport = []
for i in range(1, nrows):
testreport.append(table.cell(i, 5).value)
return testreport
# 获取用例期望的运行结果 if __name__ == "__main__":
CreateExcel()
上面代码是处理excel文档的
下面代码是测试平台
#!/usr/bin/env python
# -*- coding: utf_8 -*- import requests
import re
from createexcel import CreateExcel class CreateTest:
def __init__(self):
pass @classmethod
def test_api(cls, method, url, data):
global results
if method == "post":
results = requests.post(url, data)
if method == "get":
results = requests.get(url, data)
return results @classmethod
def test_on(cls):
print "用例执行开始" @classmethod
def test_close(cls):
print "用例执行结束" @classmethod
def test_result(cls, ra, rb):
if ra == rb:
print "测试结果: 测试通过"
else:
print "测试结果: 测试失败" @classmethod
def test_http(cls, code):
if code == 200:
print "测试请求: 请求通过" @classmethod
def test_main(cls):
global report
table = CreateExcel.open_excel()
nrows = CreateExcel.get_nrows(table)
for i in range(0, nrows - 1):
testname = CreateExcel.get_name(table, nrows)[i]
testdata = CreateExcel.get_data(table, nrows)[i]
testurl = CreateExcel.get_url(table, nrows)[i]
testmethod = CreateExcel.get_method(table, nrows)[i]
testpattern = CreateExcel.get_pattern(table, nrows)[i]
testreport = CreateExcel.get_report(table, nrows)[i]
CreateTest.test_on()
print "测试用例:", testname
try:
testresults = CreateTest.test_api(testmethod, testurl, testdata)
CreateTest.test_http(testresults.status_code)
pattern = re.compile(testpattern)
match = pattern.search(testresults.url)
if match.group() == testpattern:
report = "pass"
CreateTest.test_result(testreport, report)
except AttributeError:
report = "no"
CreateTest.test_result(testreport, report)
except Exception.__base__:
print "测试请求: 请求失败"
report = None
CreateTest.test_result(testreport, report)
CreateTest.test_close() if __name__ == '__main__':
CreateTest()
python学习笔记(接口自动化框架 V1.0)的更多相关文章
- python学习笔记(接口自动化框架 V2.0)
这个是根据上次框架版本进行的优化 用python获取excel文件中测试用例数据 通过requets测试接口.并使用正则表达式验证响应信息内容 生成xml文件测试报告 版本更新内容: 1. 整理了Cr ...
- ython学习笔记(接口自动化框架 V2.0)
这个是根据上次框架版本进行的优化 用python获取excel文件中测试用例数据 通过requets测试接口.并使用正则表达式验证响应信息内容 生成xml文件测试报告 版本更新内容: 1. 整理了Cr ...
- python学习笔记之——unittest框架
unittest是python自带的单元测试框架,尽管其主要是为单元测试服务的,但我们也可以用它来做UI自动化测试和接口的自动化测试. unittest框架为我们编写用例提供了如下的能力 定义用例的能 ...
- Python学习笔记_04:Django框架简介
目录 1 什么是Django? 2 Django框架的开发环境搭建 3 Django操作MySql数据库简介 4 功能强大的Django管理工具应用 1 什么是Django? Django是应用于We ...
- python+requests+excel 接口自动化框架
一.项目框架如图: 1.common :这个包都是一些公共的方法,如:手机号加解密,get/post接口请求的方法封装,接口鉴权,发邮件,读写excel文件方法等等 2.result:存放每次运行的l ...
- webdriver(python)学习笔记七——多层框架定位与智能等待
多层框架或窗口定位: switch_to_frame() switch_to_window() 智能等待: implicitly_wait() 现在web应用中经常会遇到框架如(frame)或窗口(w ...
- Python学习笔记:Unittest框架了解
Unittest单元测试框架不仅可以适用于单元测试,还可以适用于自动化测试用来的开发与执行,该测试框架可执行测试用例,并提供丰富的断言方法,最终生成测试报告. 一.Unittest常用方法 1.Tes ...
- 纯python自研接口自动化脚本更新版本,让小白也能实现0到1万+的接口自动化用例
查看完整文章点击原文链接:纯python自研接口自动化脚本更新版本,让小白也能实现0到1万+的接口自动化用例 你是否还在用postman\jmeter做接口自动化吗?用python的开源框架[unit ...
- 接口自动化 [授客]基于python+Testlink+Jenkins实现的接口自动化测试框架V3.0
基于python+Testlink+Jenkins实现的接口自动化测试框架V3.0 by:授客 QQ:1033553122 博客:http://blog.sina.com.cn/ishou ...
随机推荐
- Apache Lucene评分机制的内部工作原理
Apache Lucene评分机制的内部工作原理' 第5章
- LIMIT Query Optimization
LIMIT limitFrom , perPageNum LIMIT offset, size MySQL :: MySQL 8.0 Reference Manual :: 13.2.10 SELEC ...
- jq封装选项卡写法
jq普通选项卡写法: var tabTag=$('#tabon'); var tabon=tabTag.find('li');//菜单栏 var tabCon=$(".hidden" ...
- 实战docker,编写Dockerfile定制tomcat8镜像,实现web应用在线部署
最初在tomcat上部署web应用的方式,是通过maven的maven-compiler-plugin插件先打成war包,再将war包复制到tomcat的webapps目录下,后来用上了tomcat7 ...
- Perceptual Generative Adversarial Networks for Small Object Detection
Perceptual Generative Adversarial Networks for Small Object Detection 感知生成对抗网络用于目标检测 论文链接:https://ar ...
- Linux学习笔记(5)磁盘分区(parted)
Linux学习笔记(5)磁盘分区(parted) .演示: ()parted /dev/sdb :进入parted 分区命令(可以使用help来查看命令详细描述)(2)p :列出当前磁盘分区信息,可以 ...
- (4.3)ODBC/OLE DB/ADO概念与使用情况
一.ODBC ODBC的由来 1992年Microsoft和Sybase.Digital共同制定了ODBC标准接口,以单一的ODBC API来存取各种不同的数据库.随后ODBC便获得了许多数据库厂 ...
- Android View体系 系列文章
http://www.cnblogs.com/Free-Thinker/p/6768783.html
- window7+wamp环境配置Oracle数据库连接
最近开发需要使用的oracle数据库!翻看了PHP手册,也在网上找了些帖子!功夫不负有心人,花费了四五个小时的时间,终于找到了Oracle的配置方法.下面就讲解下如何配置Oracle数据库连接吧! 附 ...
- Docker 网络之端口绑定
外部访问容器 容器中可以运行一些网络应用,要让外部也可以访问这些应用,可以通过 -P 或 -p 参数来指定端口映射. -P 标记时 Docker 会随机映射一个 49000~49900 的端口到内部容 ...