python - 接口自动化测试 - TestRecharge - 充值接口测试用例

# -*- coding:utf-8 -*- '''
@project: ApiAutoTest
@author: Jimmy
@file: test_recharge.py
@ide: PyCharm Community Edition
@time: 2018-12-27 10:07
@blog: https://www.cnblogs.com/gotesting/ '''
import unittest
import os
from ddt import ddt,data
from Common.http_request import HttpRequest
from Common.read_excel import ReadExcel
from Common.read_config import ReadConfig
from Common.contants import *
from Common.basic_data import DoRegex,Context
from Common.get_logger import GetLog
import json # 读取配置文件,获取当前URL前缀,用于灵活更换测试服务器地址
read_config = ReadConfig()
url_pre = read_config.get_config_str('api','url_pre') # 读取excel,获取login测试数据
data_dir = os.path.join(data_dir,'test_data.xlsx')
read_excel = ReadExcel(data_dir)
recharge_cases = read_excel.get_cases('recharge') get_log = GetLog() @ddt
class TestRecharge(unittest.TestCase): def setUp(self):
print('Test Start') def tearDown(self):
print('Test End') @data(*recharge_cases)
def test_recharge(self,case):
url = url_pre + case.url # 通过正则表达式 查找/替换,将excel读出来的${normal_user}及${normal_pwd}替换为配置文件中读取出的normal_user及normal_pwd的值
data = DoRegex.replace(case.data)
# 将替换后的字符串转换成字典
data = json.loads(data) # 判断Context中是否存在登录成功的cookies,若存在,则获取cookie,用于接口请求;若不存在,赋值为None
if hasattr(Context,'cookies'):
cookies = getattr(Context,'cookies')
else:
cookies = None # 记录当前测试case信息
get_log.log_info('''Test Case Info:
case_id : {0}
title : {1}
method : {2}
url : {3}
data : {4}
expected: {5}
'''.format(case.case_id,case.title,case.method,url,data,case.expected)) response = HttpRequest(method=case.method,url=url,data=data,cookies=cookies)
# 判断接口请求响应是否存在cookies,若存在,放入Context中
if response.get_cookies():
setattr(Context,'cookies',response.get_cookies())
actual = response.get_json()['msg'] # 记录当前测试case接口响应信息
get_log.log_info('''Test Case Request Response Result:
response : {0}
actual : {1}
'''.format(response.get_json(),actual)) try:
self.assertEquals(case.expected,actual)
read_excel.write_result('recharge',case.case_id,actual,'Pass')
get_log.log_info('Test Result is Passed ! case_id is {0},title is {1} '.format(case.case_id,case.title))
except Exception as e:
read_excel.write_result('recharge',case.case_id,actual,'Fail')
get_log.log_info('Test Result is Failed ! case_id is {0},title is {1} '.format(case.case_id,case.title))
get_log.log_error('Error msg :{0}'.format(e))
raise e
python - 接口自动化测试 - TestRecharge - 充值接口测试用例的更多相关文章
- 使用python进行接口自动化测试,批量执行测试用例
工作中,使用python的requests库进行接口自动化测试是一个比较不错的选择,今天就以某网站的免费接口为例,展示以get请求进行批量执行测试用例.话不多说直接开讲 分析一下接口信息, 请求地址: ...
- python - 接口自动化测试 - TestLogin - 登录接口测试用例
# -*- coding:utf-8 -*- ''' @project: ApiAutoTest @author: Jimmy @file: test_login.py @ide: PyCharm C ...
- python - 接口自动化测试 - TestRegister - 注册接口测试用例
# -*- coding:utf-8 -*- ''' @project: ApiAutoTest @author: Jimmy @file: test_register.py @ide: PyChar ...
- python web自动化测试框架搭建(功能&接口)——测试用例执行和结果收集
由于unittest框架中结果收集在不同文件中,所以此处重写结果收集方法,加入执行时间,失败信息,失败截图等 TestRunner.py # coding=utf-8 import sys impor ...
- python web自动化测试框架搭建(功能&接口)——接口用例实现
测试用例基类: # coding=utf-8 import unittest import Logger log = Logger.Loger() class BaseCase(unittest.Te ...
- python web自动化测试框架搭建(功能&接口)——接口公共方法
接口公共方法有:数据引擎.http引擎.Excel引擎 1.数据引擎:获取用例.结果检查.结果统计 # -*- coding:utf-8 -*- from XlsEngine import XlsEn ...
- python web自动化测试框架搭建(功能&接口)——接口测试模块
Python接口测试采用python读取excel的方法,通过requests库发送请求和接收响应.模块有: Data:用于存放excel用例的,用例格式: iutil: 接口公共方法,数据引擎.ht ...
- python web自动化测试框架搭建(功能&接口)——功能测试模块
功能测试使用selenium,模块有: 1.futil: 公共方法,如元素高亮显示 # coding=utf-8 """高亮显示元素""" ...
- python web自动化测试框架搭建(功能&接口)——通用模块
1.通用模块: config.conf: 公共配置文件,配置报告.日志.截图路径,以及邮件相关配置 [report] reportpath = E:\workspace\WebAutomation\s ...
随机推荐
- 【MATLAB】设定坐标的轴的范围
set(gca,'XLim',[0 1.5]);%X轴的数据显示范围set(gca,'XTick',[0:0.1:1.5]);%设置要显示坐标刻度set(gca,'XTickLabel',[0:0.1 ...
- 初学树套树:线段树套Treap
前言 树套树是一个十分神奇的算法,种类也有很多:像什么树状数组套主席树.树状数组套值域线段树.\(zkw\)线段树套\(vector\)等等. 不过,像我这么弱,当然只会最经典的 线段树套\(Trea ...
- EL和JSTL表达式学习记录
EL.JSTL表达式EL:1.EL使用目的:代替jsp页面中java脚本编写 2.EL作用:(1)从域中取出数据(最重要)(2)EL的内置对象(11个)(3)EL可以执行表达式运算 JSTL(JSP标 ...
- 关于后台获取不到HiddenField值的有关问题
服务器加载aspx程序时,首先要执行后台cs文件中的page_load等方法中的代码,其它按钮事件等是不执行的,生成页面发送到客户端.客户端执行时会响应js脚本,提交到服务器后除了执行page_loa ...
- React后台管理系统-商品列表搜索框listSearch组件
1.商品列表搜索框 2.搜索框页面的结构为 <div className="row search-wrap"> <div classN ...
- 模板引擎原理及underscore.js使用
为什么要使用模板引擎 DOM结构简单,完全可以使用DOM方法创建DOM树.$("<td></td").appendTo(); 当页面比较复杂的时候,下面的程序中红 ...
- vue2.0父子组件以及非父子组件通信
官网API: https://cn.vuejs.org/v2/guide/components.html#Prop 一.父子组件通信 1.父组件传递数据给子组件,使用props属性来实现 传递普通字符 ...
- ASIHTTPRequest的使用
本文转自csdn ASIHTTPRequest对CFNetwork API进行了封装,并且使用起来非常简单,用Objective-C编写,可以很好的应用在Mac OS X系统和iOS平台的应用程序中. ...
- mysql update 多表关联更新
UPDATE new_schedules_spider_static_schedule s join new_scac_port p on p.`PORT` = s.`PORT` and p.SCAC ...
- 项目实战8.1—tomcat企业级Web应用服务器配置与会话保持
分类: Linux架构篇 tomcat企业级Web应用服务器配置与实战 环境背景:公司业务经过长期发展,有了很大突破,已经实现盈利,现公司要求加强技术架构应用功能和安全性以及开始向企业应用.移动A ...