接口公共方法有:数据引擎、http引擎、Excel引擎

1、数据引擎:获取用例、结果检查、结果统计

# -*- coding:utf-8 -*-
from XlsEngine import XlsEngine_rd
import os '''获取用例'''
def getCase():
filepath = os.path.abspath('.')
filename = filepath + "/interfacetest/Data/InterfaceData.xlsx"
data = XlsEngine_rd(filename)
data.xlrd_open()
sheet = data.xlrd_object.sheet_by_index(0)
rows = sheet.nrows
domain = sheet.cell_value(1,1)
header_temp = sheet.cell_value(2,1)
header=eval(header_temp)
case_list=[]
for i in range(3,rows):
case_list.append(sheet.row_values(i))
return domain,case_list,header '''结果检查'''
def resultCheck(actual_result, expect_result):
result = "Failed"
actualre = actual_result.content
area = (expect_result.split(':'))[0]
expect = (expect_result.split(':'))[1]
if area == "response_code":
if str(actual_result.status_code) == expect:
result = "Pass"
actualre = "response_code:"+expect
if area == "content":
expect = expect_result.replace("content:","").encode('utf-8')
actual = actual_result.content
if expect in str(actual):
result = "Pass"
actualre = expect
return result,actualre '''结果统计'''
def countResult(resultlist):
passcount=0
failcount=0
for result in resultlist:
if result[5] == 'Pass':
passcount+=1
else:
failcount+=1
return passcount,failcount

2、http引擎,用于发送请求和响应接收,提供登录方法,供需要登录的接口调用

# -*- coding:utf-8 -*-
import requests def getData(s, url, data, header, method):
re=object
isexcept = False
if method == "post":
try:
re = s.post(url, headers=header, data=data)
except requests.exceptions.ConnectionError,e:
re = e
isexcept = True if method == "get":
try:
re = s.get(url, headers=header, data=data)
except requests.exceptions.ConnectionError,e:
re = e
isexcept = True if method == "delete":
try:
re = s.delete(url+"/"+data)
except requests.exceptions.ConnectionError,e:
re = e
isexcept = True if method == "put":
try:
re = s.put(url)
except requests.exceptions.ConnectionError,e:
re = e
isexcept = True return re,isexcept def login():
s=object
isexcept = False
try:
url="http://baidu.com/login"
header = {"Referer": "http://baidu.com"}
data={"username":"admin", "password":"xxx"}
s=requests.Session()
s.post(url, headers=header, data=data)
except requests.exceptions.ConnectionError,e:
s=e
isexcept = True
return s, isexcept

3、Excel引擎:excel文件操作

# coding=utf-8
import xlrd
import xlwt class XlsEngine_rd(): def __init__(self, filename):
self.xls_name = filename
self.xlrd_object = None
self.xlwt_object = None
self.isopenfailed = True def xlrd_open(self):
try:
#xlrd.Book.encoding="utf-8"
self.xlrd_object = xlrd.open_workbook(self.xls_name)
self.isopenfailed = False
except Exception,e:
self.isopenfailed = True
self.xlrd_object = None
print(e)
return [self.isopenfailed, self.xlrd_object]

Python web功能&接口自动化测试框架搭建——接口用例实现

Python web功能&接口自动化测试框架搭建——接口公共方法

Python web功能&接口自动化测试框架搭建——接口测试模块

Python web功能&接口自动化测试框架搭建——功能测试模块

Python web功能&接口自动化测试框架搭建——测试用例执行和结果收集

Python web功能&接口自动化测试框架搭建——通用模块

Python web功能&接口自动化测试框架搭建——unittest介绍

Python web功能&接口自动化测试框架搭建——环境搭建

python web自动化测试框架搭建(功能&接口)——接口公共方法的更多相关文章

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

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

  2. python web自动化测试框架搭建(功能&接口)——接口测试模块

    Python接口测试采用python读取excel的方法,通过requests库发送请求和接收响应.模块有: Data:用于存放excel用例的,用例格式: iutil: 接口公共方法,数据引擎.ht ...

  3. python web自动化测试框架搭建(功能&接口)——功能测试模块

    功能测试使用selenium,模块有: 1.futil: 公共方法,如元素高亮显示 # coding=utf-8 """高亮显示元素""" ...

  4. python web自动化测试框架搭建(功能&接口)——测试用例执行和结果收集

    由于unittest框架中结果收集在不同文件中,所以此处重写结果收集方法,加入执行时间,失败信息,失败截图等 TestRunner.py # coding=utf-8 import sys impor ...

  5. python web自动化测试框架搭建(功能&接口)——通用模块

    1.通用模块: config.conf: 公共配置文件,配置报告.日志.截图路径,以及邮件相关配置 [report] reportpath = E:\workspace\WebAutomation\s ...

  6. Python web自动化测试框架搭建(功能&接口)——unittest介绍

    Python UnitTest测试框架介绍 1)         TestCase:所有测试用例类继承的基本类, TestCase的实例就是测试用例 2)         TestSuite:测试套件 ...

  7. python web自动化测试框架搭建(功能&接口)——环境搭建

    自动化测试框架一般需要实现以下通用功能 执行前准备 结束后清理 执行步骤输出 执行结果输出 错误.失败截图 测试报告 发送邮件 日志 需要的软件和python第三方库有: 通用: JDK Eclips ...

  8. 基于python的自动化测试框架搭建

    滴~ 今日打卡!   好多天没来打卡了.博主最近一直在把碎片化知识转化为知识体系的过程中挣扎.Python语言.selenium.unittest框架.HTMLTestRunner框架都有所了解,也写 ...

  9. selenium +python web自动化测试环境搭建

    基础框架搭建 1.安装python 2.安装selenium cmd输入pip install selenium 问题:在python中输入from selenium import webdriver ...

随机推荐

  1. Sentinel整合Dubbo限流实战(分布式限流)

    之前我们了解了 Sentinel 集成 SpringBoot实现限流,也探讨了Sentinel的限流基本原理,那么接下去我们来学习一下Sentinel整合Dubbo及 Nacos 实现动态数据源的限流 ...

  2. ex3 多分类和神经网络

    介绍 在本练习中,您将实现一对多逻辑回归和神经识别手写数字的网络.在开始编程之前练习,我们强烈建议观看视频讲座并完成相关主题的复习问题.要开始练习,您需要下载起始代码并将其内容解压缩到要完成练习的目录 ...

  3. grunt默认只允许localhost和访问,如何设置外部IP地址访问

    转载请注明出处: 猩猩队长  http://www.cnblogs.com/wayns/p/access_grunt_server_from_outside.html 使用Yeoman生成器创建web ...

  4. SSH学习笔记(二)

    # 1. 关于 SSH Server 的整体设定,包含使用的 port 啦,以及使用的密码演算方式 Port 22 # SSH 预设使用 22 这个 port,您也可以使用多的 port ! # 亦即 ...

  5. JavaScript、ES6中的类的继承

    类的继承 extends  connstructor  super 例1: class Father { constructor(){} money(){ console.log("1000 ...

  6. nginx location配置讲解

    location语法:表示uri方式定位 基础语法有三种: location = pattern {} 精准匹配 location pattern {} 一般匹配 location ~ pattern ...

  7. C++ CMake 入门实战[转载]

    C++ CMake 入门实战 2016-11-05 CMake用于跨平台的编译系统,对于通常的c/c++工程,都是通过make来进行编译的,CMake可以通过指令生成Makefile文件来指导整个项目 ...

  8. CentOS 7系统安装nginx+php

    安装介绍1.系统环境CentOS7 2.nginx版本1.12 3.PHP版本7.2 下载地址 4.MySQL版本5.7 安装nginx添加centos7的 nginx yum源 然后执行安装 sud ...

  9. neuoj1472 yuki的氪金之旅(倒置树状数组

    这题一直re不造为啥..后来yww大神把树状数组“倒过来”就过了,倒过来的好处是算sum(d[i]+1)就行,不涉及除法,不用求逆元. 题意:初始手牌颜值是0,一共抽卡n次,第i次抽卡有pi的概率能抽 ...

  10. root登录

    ,编辑/etc/lightdm/lightdm.conf: gedit /etc/lightdm/lightdm.conf [Seat:*] autologin-guest=false autolog ...