python web自动化测试框架搭建(功能&接口)——接口公共方法
接口公共方法有:数据引擎、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自动化测试框架搭建(功能&接口)——接口用例实现
测试用例基类: # coding=utf-8 import unittest import Logger log = Logger.Loger() class BaseCase(unittest.Te ...
- python web自动化测试框架搭建(功能&接口)——接口测试模块
Python接口测试采用python读取excel的方法,通过requests库发送请求和接收响应.模块有: Data:用于存放excel用例的,用例格式: iutil: 接口公共方法,数据引擎.ht ...
- python web自动化测试框架搭建(功能&接口)——功能测试模块
功能测试使用selenium,模块有: 1.futil: 公共方法,如元素高亮显示 # coding=utf-8 """高亮显示元素""" ...
- python web自动化测试框架搭建(功能&接口)——测试用例执行和结果收集
由于unittest框架中结果收集在不同文件中,所以此处重写结果收集方法,加入执行时间,失败信息,失败截图等 TestRunner.py # coding=utf-8 import sys impor ...
- python web自动化测试框架搭建(功能&接口)——通用模块
1.通用模块: config.conf: 公共配置文件,配置报告.日志.截图路径,以及邮件相关配置 [report] reportpath = E:\workspace\WebAutomation\s ...
- Python web自动化测试框架搭建(功能&接口)——unittest介绍
Python UnitTest测试框架介绍 1) TestCase:所有测试用例类继承的基本类, TestCase的实例就是测试用例 2) TestSuite:测试套件 ...
- python web自动化测试框架搭建(功能&接口)——环境搭建
自动化测试框架一般需要实现以下通用功能 执行前准备 结束后清理 执行步骤输出 执行结果输出 错误.失败截图 测试报告 发送邮件 日志 需要的软件和python第三方库有: 通用: JDK Eclips ...
- 基于python的自动化测试框架搭建
滴~ 今日打卡! 好多天没来打卡了.博主最近一直在把碎片化知识转化为知识体系的过程中挣扎.Python语言.selenium.unittest框架.HTMLTestRunner框架都有所了解,也写 ...
- selenium +python web自动化测试环境搭建
基础框架搭建 1.安装python 2.安装selenium cmd输入pip install selenium 问题:在python中输入from selenium import webdriver ...
随机推荐
- JEECG 深度使用培训班 周六周日公开课(一期班)
版权声明:本文为博主原创文章,未经博主同意不得转载. https://blog.csdn.net/zhangdaiscott/article/details/25411023 广大技术爱好者: ...
- linux相关(find/grep/awk/sed/rpm)
如何查找特定的文件: find :在指定目录下查找文件 find -name "filename" :从当前目录查找文件 find / -name "filename&q ...
- 25.conda 下载安装与运用
转载:https://www.cnblogs.com/gandoufu/p/9748841.html https://blog.csdn.net/tuzixini/article/details/81 ...
- Echarts数据可视化grid直角坐标系(xAxis、yAxis)详解:
mytextStyle={ color:"#333", //文字颜色 fontStyle:"normal", //italic斜体 oblique倾斜 font ...
- 实现单选框点击label标记中的文字也能选中
实例: <label for="man"> <input type="radio" value="男" name=&quo ...
- linux安装 inotify
[root@rsync-client-inotify ~]# yum install make gcc gcc-c++ [root@rsync-client-inotify ~]# wget http ...
- vue的class和style的绑定
<div class="input-search" :class="{input-search-focus : iscur == 1}"> 在原本有 ...
- error: must use ‘class’ tag to refer to type ‘XXX’ in this scope
开发环境: Qt Creator 4.8.2 在写程序的时候,遇到了编译器报错 error: must use 'class' tag to refer to type 'XXX' in this s ...
- Springboot 默认cache
1:Springboot 默认缓存为ConcurrentMapCacheManager(spring-context) 2:再启动类上开启缓存 @SpringBootApplication //相当于 ...
- 原生jdbc操作
1:加入dbcp连接池依赖 <dependency> <groupId>org.apache.commons</groupId> <artifactId> ...