unittest管理接口用例(数据分离-读取excel)
1.简单读取
#coding=utf-8
#调用封装好的excel读取公共方法
from python_API.common.ReadExcel import ReadExcel
import requests
import json
#获取excel中的url
url = ReadExcel("d:\\dym.xls","Sheet1").getValue(1,1)
#获取excel中的请求方式
Method = ReadExcel("d:\\dym.xls","Sheet1").getValue(1,2)
#获取excel中的header
header = json.loads(ReadExcel("d:\\dym.xls","Sheet1").getValue(1,3))
#获取excel中的param
body = json.loads(ReadExcel("d:\\dym.xls","Sheet1").getValue(1,4))
response = requests.request(Method,url,headers=header,params=body)
print (response.json())
2.加上unitest框架管理用例生成测试报告
#coding=utf-8
from python_API.common.ReadExcel import ReadExcel
from python_API.common.WriteExcel import wrtel
import requests
import json
import unittest
import HTMLTestRunner
class Test(unittest.TestCase):
def setUp(self):
self.url = ReadExcel("d:\\dym.xls","Sheet1").getValue(1,1)
self.Method = ReadExcel("d:\\dym.xls","Sheet1").getValue(1,2)
self.header = json.loads(ReadExcel("d:\\dym.xls","Sheet1").getValue(1,3))
def test01(self):
body = json.loads(ReadExcel("d:\\dym.xls","Sheet1").getValue(1,4))
response = requests.request(self.Method,self.url,headers=self.header,params=body)
#调用写入excel内容公共方法,将返回的报文实际结果写入到excel中
wrtel("d:\\dym.xls",0,1,6,response.text)
#断言结果是否正确
self.assertEqual(response.json()[",msg="test01 error!")
def test02(self):
body = json.loads(ReadExcel("d:\\dym.xls","Sheet1").getValue(2,4))
response = requests.request(self.Method,self.url,headers=self.header,params=body)
wrtel("d:\\dym.xls",0,2,6,response.text)
self.assertIn(u"错误",response.json()["errorMsg"],msg="test02 error!")
def test03(self):
body = json.loads(ReadExcel("d:\\dym.xls","Sheet1").getValue(3,4))
response = requests.request(self.Method,self.url,headers=self.header,params=body)
wrtel("d:\\dym.xls",0,3,6,response.text)
self.assertIn(u"错误",response.json()["errorMsg"],msg="test02 error!")
if __name__ == '__main__':
suit = unittest.TestSuite()
testcases = [Test("test01"),Test("test02"),Test("test03")]
suit.addTests(testcases)
dir = "D:\work_doc\pycharm2\python_API\\result\\report.html"
path = open(dir,"wb")
runner =HTMLTestRunner.HTMLTestRunner(stream=path,title="TestReport",description="test desc")
runner.run(suit)
3.循环读取excel文件内的参数
#coding=utf-8
from python_API.common.ReadExcel import ReadExcel
import requests
import json
import unittest
class Test(unittest.TestCase):
def setUp(self):
self.url = ReadExcel("d:\\dym.xls","Sheet1").getValue(1,1)
self.Method = ReadExcel("d:\\dym.xls","Sheet1").getValue(1,2)
self.header = json.loads(ReadExcel("d:\\dym.xls","Sheet1").getValue(1,3))
def test01(self):
#调用读取excel类中的获取行数方法getRows(),获取有效行数
for row in range(ReadExcel("d:\\dym.xls","Sheet1").getRows()):
#因为第一行为标题,所以row为0时不能用来取值
if row >=1:
body = json.loads(ReadExcel("d:\\dym.xls","Sheet1").getValue(row,4))
response = requests.request(self.Method,self.url,headers=self.header,params=body)
if row == 1:
if response.json()["executeStatus"] == 0:
pass
else:
print ("case01 error!")
else:
if response.json()["executeStatus"] == 1:
pass
else:
print ("case02 error!")
if __name__ == '__main__':
unittest.main()
unittest管理接口用例(数据分离-读取excel)的更多相关文章
- unittest 管理接口用例(数据分离-读取excel)
1.公共模块 ---> login.xls """ common (package) ---> ReadFile.py """ ...
- unittest管理接口用例
1.加入unittest框架 #coding=utf-8 import requests import unittest class TestApi(unittest.TestCase): def s ...
- python接口自动化测试--数据分离读取Excal指定单元格数据
上一篇博客讲了怎么批量读取Excal单元格数据,现在咱们说一下怎么读取Excal指定单元格数据. 一.首先建一个Test_Main类 #!/usr/bin/python # -*- coding: U ...
- Jmeter 接口自动化-脚本数据分离实例
一. 背景: 为了让大家更加的了解Jmeter,并且使用起来游刃有余.这篇我们主要讲一下,如何优雅的使用Jmeter一步步的实现接口自动化,完成脚本与数据分离,把可能对Jmeter脚本的维护转移到c ...
- Python 用load_workbook 读取excel某个单元格数据、读取excel行数、列数
from openpyxl import load_workbook path = r'D:\pywork\12' # EXCEL信息所在文件夹 e= load_workbook(path + '/' ...
- requests,unittest——多接口用例,以及需要先登录再发报的用例
之前写过最简单的接口测试用例,本次利用unittest进行用例管理,并出测试报告,前两个用例是两个不同网页的get用例,第三个是需要登录才能访问的网页A,并在其基础上访问一个需要在A页面点开链接才能访 ...
- python web自动化测试框架搭建(功能&接口)——接口用例实现
测试用例基类: # coding=utf-8 import unittest import Logger log = Logger.Loger() class BaseCase(unittest.Te ...
- C#读取Excel数据操作大全
苦丁茶 发表于 2014-02-10 12:58:00 | 分类标签: ASP.NET 读取Excel 本文介绍下,用C#读取excel数据的例子,包括读取整个工作薄的数据.读取工作薄选定区域中的数据 ...
- C# 读取Excel中的数据
#region 读取Excel中的数据 /// <summary> /// 读取Excel中的数据 /// </summary> /// <param name=&quo ...
随机推荐
- 向net core 3.0进击——多平台项目发布与部署
前言 在经历过好多折腾后,总算是把部署走通了一遍,之前只是简单创建个工程在linux下部署,后来一直将这件事搁置,直到最近刚好团队入手一个小服务器,很显然是linux的,那就没啥说的了,Come On ...
- WebGL学习笔记(十三):拾取
目前为止,我们还没有涉及到交互相关的内容,实际上,我们是需要知道我们点击的地方下面的第一个物体的信息,这个过程称为拾取. 简单拾取实现 我们可以通过颜色来获取是否成功点击,具体方式如下: 场景中有一个 ...
- Java 学习大纲
1.java基础 1.1 Collection和Map (1)掌握Collection和Map的继承体系 (2)掌握ArrayList,LinkedList,Vector,Stack, ...
- spring 支持集中 bean scope?
Spring bean 支持 5 种 scope: Singleton - 每个 Spring IoC 容器仅有一个单实例. Prototype - 每次请求都会产生一个新的实例. Request - ...
- sublime的注册方法 非常好用
摘自:https://blog.csdn.net/weixin_42444922/article/details/81006107 转载 阿东的天空之城 发布于2018-07-11 20:03:43 ...
- C++ & OpenCV 零散学习总结
OpenCV中Mat基本用法: Mat类 (Matrix的缩写) 是OpenCV用于处理图像而引入的一个封装类.从功能上讲,Mat类在IplImage结构的基础上进一步增强,并且,由于引入C++高级编 ...
- maven 国内镜像
<mirrors> <!-- mirror | Specifies a repository mirror site to use instead of a given reposi ...
- Postgres-XL集群ERROR :Failed to get pooled connections原因说明
集群说明 6台服务器.其中1台(rt67-1)运行GTM,其余5台均运行1个GTM_PROXY.1个Coordinator node.3个Data node.每个服务器连接到3组网络中,每个Data ...
- Spring Initializr生成的demo测试404错误
体验Spring Initializr生成的spring boot工程,启动成功, 目录结构如下: 添加了一个简单的controller后,启动成功但访问报404错误: 原因: springboot默 ...
- MATLAB爬虫爬取股票数据
近年来,大数据盛行,有关爬虫的教程层次不穷.那么,爬虫到底是什么呢? 什么是爬虫? 百度百科是这样定义的: 网络爬虫(又被称为网页蜘蛛,网络机器人,在FOAF社区中间,更经常的称为网页追逐者),是一种 ...