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 ...
随机推荐
- 判断 checkbox 是否选中以及 设置checkbox选中
//判断checkbox 是否选中 $("#id").is(":checked");//选中,返回true,没选中,返回false //设置checkbox为选 ...
- Taylor's theorem
w https://en.wikipedia.org/wiki/Taylor_series
- MySQL中的共享锁与排他锁
MySQL中的共享锁与排他锁 在MySQL中的行级锁,表级锁,页级锁中介绍过,行级锁是Mysql中锁定粒度最细的一种锁,行级锁能大大减少数据库操作的冲突.行级锁分为共享锁和排他锁两种,本文将详细介绍共 ...
- Vue(4)- 获取原生的DOM的方式、DIY脚手架、vue-cli的使用
一.获取原生的DOM的方式 在js中,我们可以通过id.class或者标签获取DOM元素,vue中也为我们提供了获取原生DOM的方法,就是给标签或者组件添加ref属性,通过this.$refs获取,如 ...
- Django的模型层(1)- 单表操作(下)
一.查询表记录 在学习查询表记录之前,先了解一下QuerySet,这是一种类似列表的数据类型,是由ORM创建的.我们学习查询表记录的方法时,一定要明确哪些方法返回了QuerySet类型,哪些方法返回m ...
- Android开发中string.xml文件的使用
为什么需要把应用中出现的文字单独存放在string.xml文中呢? 一:是为了国际化,Android建议将在屏幕上显示的文字定义在strings.xml中,如果今后需要进行国际化,比如我们开发的应用本 ...
- Kotlin 初级读本
第一部分——快速上手第一章·启程 第二章·基本语法第三章·Kotlin 与 Java 混编 第二部分——开始学习 Kotlin第四章·Kotlin 的类特性(上)第四章·Kotlin 的类特性(下)第 ...
- PHP数组的创建
案例: 仔细看代码,PHP创建数组 <?php $names[0]='Peter'; $names[1]='Minot'; $names[2]='Smith'; echo $names[0].' ...
- SqlServer分页总结-摘抄
sqlserver2008不支持关键字limit ,所以它的分页sql查询语句将不能用mysql的方式进行,幸好sqlserver2008提供了top,rownumber等关键字,这样就能通过这几个关 ...
- GIT如何使用:大杀器!所有常用指令整理
1 pwd 显示当前目录2 mkdir 创建目录 cd 进入文件3 git init 变成Git可以管理的仓库(千万不要修改目录下的.git隐藏文件夹)4 ls -ah 可以把.git文件显示出来5 ...