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)的更多相关文章

  1. unittest 管理接口用例(数据分离-读取excel)

    1.公共模块 ---> login.xls """ common (package) ---> ReadFile.py """ ...

  2. unittest管理接口用例

    1.加入unittest框架 #coding=utf-8 import requests import unittest class TestApi(unittest.TestCase): def s ...

  3. python接口自动化测试--数据分离读取Excal指定单元格数据

    上一篇博客讲了怎么批量读取Excal单元格数据,现在咱们说一下怎么读取Excal指定单元格数据. 一.首先建一个Test_Main类 #!/usr/bin/python # -*- coding: U ...

  4. Jmeter 接口自动化-脚本数据分离实例

    一. 背景:  为了让大家更加的了解Jmeter,并且使用起来游刃有余.这篇我们主要讲一下,如何优雅的使用Jmeter一步步的实现接口自动化,完成脚本与数据分离,把可能对Jmeter脚本的维护转移到c ...

  5. Python 用load_workbook 读取excel某个单元格数据、读取excel行数、列数

    from openpyxl import load_workbook path = r'D:\pywork\12' # EXCEL信息所在文件夹 e= load_workbook(path + '/' ...

  6. requests,unittest——多接口用例,以及需要先登录再发报的用例

    之前写过最简单的接口测试用例,本次利用unittest进行用例管理,并出测试报告,前两个用例是两个不同网页的get用例,第三个是需要登录才能访问的网页A,并在其基础上访问一个需要在A页面点开链接才能访 ...

  7. python web自动化测试框架搭建(功能&接口)——接口用例实现

    测试用例基类: # coding=utf-8 import unittest import Logger log = Logger.Loger() class BaseCase(unittest.Te ...

  8. C#读取Excel数据操作大全

    苦丁茶 发表于 2014-02-10 12:58:00 | 分类标签: ASP.NET 读取Excel 本文介绍下,用C#读取excel数据的例子,包括读取整个工作薄的数据.读取工作薄选定区域中的数据 ...

  9. C# 读取Excel中的数据

    #region 读取Excel中的数据 /// <summary> /// 读取Excel中的数据 /// </summary> /// <param name=&quo ...

随机推荐

  1. C语言 按位异或实现加法

    /* C语言 按位异或实现加法 */ #include <stdio.h> #include <stdlib.h> #include <string.h> void ...

  2. asp.netcore 高并发下使用HttpClient的方法

    大家都知道,使用HttpClient,在并发量不大的情况,一般没有任何问题:但是在并发量一上去,如果使用不当,会造成很严重的堵塞的情况. 解决方案如下: 一.可以参考微软官方提供的方法:https:/ ...

  3. SpringBoot入门-集成mybatis(四)

    pom.xml <parent> <groupId>org.springframework.boot</groupId> <artifactId>spr ...

  4. python初级(302) 6 对象(五)

    一.复习 1.什么是多态 2.什么是继承 二.继承:向父母学习 在面向对象编程中,类可以从其他类继承属性和方法.这样就有了类的整个家族,这个家族中的每个类共享相同的属性和方法.这样一来,每次向家族增加 ...

  5. ireport5.6.0分组显示

    一,ireport中分组 二,java调用实现分组 一,ireport中分组: 1,新建模板文件,纸张随意,名称随意,路径随意 2,连接要分组的数据源 3,添加测试表和数据 CREATE TABLE ...

  6. python中实现延时回调普通函数示例代码

    python中实现延时回调普通函数示例代码 这篇文章主要给大家介绍了关于python中实现延时回调普通函数的相关资料,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的 ...

  7. python办公自动化(一)PPTX

    简介: python-pptx是python处理PPT的一个库,注重的是读和写,无法导出,没有渲染功能. 办公自动化,说的是大了一点,但是最常见的office三件套,word,excel,ppt.这还 ...

  8. Spring MVC -- 下载文件

    像图片或者HTML文件这样的静态资源,在浏览器中打开正确的URL即可下载,只要该资源是放在应用程序的目录下,或者放在应用程序目录的子目录下,而不是放在WEB-INF下,tomcat服务器就会将该资源发 ...

  9. TensorFlow 8 bit模型量化

    本文基本参考自这篇文章:8-Bit Quantization and TensorFlow Lite: Speeding up mobile inference with low precision ...

  10. GO语言 文件操作实例

    package main import ( "bufio" "fmt" "io/ioutil" "os" ) func ...