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 ...
随机推荐
- iOS论App推送方案
1.APNS介绍(原生推送实现原理) 在iOS平台上,大部分应用是不允许在后台运行并连接网络的.在应用没有被运行的时候,只能通过 Apple Push Notification Service (AP ...
- window异常处理——except_handler4以及栈展开分析
以前在15pb学习时候在看雪论坛发的一篇精华帖. 主要是分析在try块中发生嵌套异常时候堆栈是如何平衡的. 就不复制过来了,给个链接http://bbs.pediy.com/showthread.ph ...
- Qt 使用 lambda 表达式做为槽函数时为什么使用 QObject::sender() 获取到的发送信号对象指针为空?
/*! Returns a pointer to the object that sent the signal, if called in a slot activated by a signal; ...
- js身份证号有效性验证
1.简述 最近做的系统有用到实名验证的,起初对于用户身份证号只是简单地使用正则表达式进行验证, 很多无效的身份证号就成了漏网之鱼. 导致后台存表里很多无效的身份证号,随便输入用户名和身份证号就可以实名 ...
- Django组件 - cookie、session、用户认证组件
一.cookie 1.会话跟踪技术 1)什么是会话跟踪技术 我们需要先了解一下什么是会话!可以把会话理解为客户端与服务器之间的一次会晤,在一次会晤中可能会包含多次请求和响应.例如你给10086打个电话 ...
- redis的数据类型与应用场景(二)
1. 如何学习 redis有好多数据类型,有这么多数据类型,我们不可能每个都记得完完全全.但是我们必须知道它有哪些数据类型,每个数据类型是怎样的,有什么作用.redis的每一个数据类型都有一大堆命令, ...
- django重写用户模型
重写一个UserProfile继承自带的AbstractUser # -*- coding: utf-8 -*- from __future__ import unicode_literals fro ...
- [Python] Send emails to the recepients specified in Message["CC"]
Recently, I'm working on a small program which needs to send emails to specific accounts. When I wan ...
- NHibernate MappingException. No Persister
在另一个Visual Studio项目(议会mm.k.Infrastructure)我有我的映射文件(一个映射目录),我的hibernate.cfg.xml和一些仓库. 这是我的映射文件: <? ...
- c#的yield return
4.1 迭代器块 一个迭代器块(iterator block)是一个能够产生有序的值序列的块.迭代器块和普通语句块的区别就是其中出现的一个或多个yield语句. yield return语句产生迭代的 ...