之前是利用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)的更多相关文章

  1. python学习笔记(接口自动化框架 V2.0)

    这个是根据上次框架版本进行的优化 用python获取excel文件中测试用例数据 通过requets测试接口.并使用正则表达式验证响应信息内容 生成xml文件测试报告 版本更新内容: 1. 整理了Cr ...

  2. ython学习笔记(接口自动化框架 V2.0)

    这个是根据上次框架版本进行的优化 用python获取excel文件中测试用例数据 通过requets测试接口.并使用正则表达式验证响应信息内容 生成xml文件测试报告 版本更新内容: 1. 整理了Cr ...

  3. python学习笔记之——unittest框架

    unittest是python自带的单元测试框架,尽管其主要是为单元测试服务的,但我们也可以用它来做UI自动化测试和接口的自动化测试. unittest框架为我们编写用例提供了如下的能力 定义用例的能 ...

  4. Python学习笔记_04:Django框架简介

    目录 1 什么是Django? 2 Django框架的开发环境搭建 3 Django操作MySql数据库简介 4 功能强大的Django管理工具应用 1 什么是Django? Django是应用于We ...

  5. python+requests+excel 接口自动化框架

    一.项目框架如图: 1.common :这个包都是一些公共的方法,如:手机号加解密,get/post接口请求的方法封装,接口鉴权,发邮件,读写excel文件方法等等 2.result:存放每次运行的l ...

  6. webdriver(python)学习笔记七——多层框架定位与智能等待

    多层框架或窗口定位: switch_to_frame() switch_to_window() 智能等待: implicitly_wait() 现在web应用中经常会遇到框架如(frame)或窗口(w ...

  7. Python学习笔记:Unittest框架了解

    Unittest单元测试框架不仅可以适用于单元测试,还可以适用于自动化测试用来的开发与执行,该测试框架可执行测试用例,并提供丰富的断言方法,最终生成测试报告. 一.Unittest常用方法 1.Tes ...

  8. 纯python自研接口自动化脚本更新版本,让小白也能实现0到1万+的接口自动化用例

    查看完整文章点击原文链接:纯python自研接口自动化脚本更新版本,让小白也能实现0到1万+的接口自动化用例 你是否还在用postman\jmeter做接口自动化吗?用python的开源框架[unit ...

  9. 接口自动化 [授客]基于python+Testlink+Jenkins实现的接口自动化测试框架V3.0

    基于python+Testlink+Jenkins实现的接口自动化测试框架V3.0   by:授客 QQ:1033553122     博客:http://blog.sina.com.cn/ishou ...

随机推荐

  1. boost:property_tree::ini_parser:::read_ini 读取ini时崩溃

    原因: 1 路径错误 2 配置文件中某一行缺少=,例如用// 做注释的,前面应该加";" 解决办法: 添加异常处理,实例代码如下: #include <boost/prope ...

  2. <2014 08 29> MATLAB的软件结构与模块、工具箱简示

    MATLAB的系统结构:三个层次.九个部分 ----------------------------------- 一.基础层 是整个系统的基础,核心内容是MATLAB部分. 1.软件主包MATLAB ...

  3. 第19章—后端分页(PageHelper)

    spring boot 系列学习记录:http://www.cnblogs.com/jinxiaohang/p/8111057.html 码云源码地址:https://gitee.com/jinxia ...

  4. 模块 - random/string/os/sys/shutil/zipfile/tarfile

    random 模块 方法: >>> random.randint(1,3) #会包含 1 2 3 3 >>> random.randrange(1,3) #会包含 ...

  5. struct 模块 把一个类型,如数字,转成固定长度的bytes

    该模块可以把一个类型,如数字,转成固定长度的bytes import struct headers=struct.pack('i',132333) print(headers,len(headers) ...

  6. 初识Locust---认识

    性 能测试工具: 基于Python的性能测试工具-locust 现在性能测试方面有很多测试工具,比如我们熟悉的loadrunner.jmeter.ab等,用过的也就是这几种,如果是学过这些工具的可能对 ...

  7. Linux学习笔记(11)linux网络管理与配置之一——配置路由与默认网关,双网卡绑定(5-6)

    Linux学习笔记(11)linux网络管理与配置之一——配置路由与默认网关,双网卡绑定(5-6) 大纲目录 0.常用linux基础网络命令 1.配置主机名 2.配置网卡信息与IP地址 3.配置DNS ...

  8. SCSS入门

    1. CSS预处理器 定义了一种新的专门的编程语言,编译后成正常的CSS文件.为CSS增加一些编程的特性,无需考虑浏览器的兼容问题,让CSS更加简洁,适应性更强,可读性更佳,更易于代码的维护等诸多好处 ...

  9. 清华教授谈人工智能:BAT还算不上伟大公司

  10. mysql如果主库宕机,如何解决?

    两种情况服务器down机,数据库down机 如果此时需要切从库 1.先show processlist\G,查看状态 如果看到两个状态,说明此时的从库和主库是同步的 state: waiting fo ...