work_20181203_httprequest.py:
import  requests
class http_request: def http_get(url,params):
res = requests.get(url,params)
return res def http_post(url,params,cookies = None):
res = requests.post(url,params,cookies = cookies)
return res
work_20181203_testcase.py:

#-*- coding:utf-8 -*-
# author:jiaxy
# datetime:2018/12/3 14:03
# file: work_20181203_testcase.py '''
登录 login='http://47.107.168.87:8080/futureloan/mvc/api/member/login'
login_data={'mobilephone':18688773467,'pwd':'123456'} 充值 recharge='http://47.107.168.87:8080/futureloan/mvc/api/member/recharge'
recharge_data={'mobilephone':18688773467,'amount':'1000'}
''' import unittest
from jiaxy.work_20181203_httprequest import http_request class Test(unittest.TestCase): login = 'http://47.107.168.87:8080/futureloan/mvc/api/member/login'
login_data={'mobilephone':18688773467,'pwd':'123456'}
recharge = 'http://47.107.168.87:8080/futureloan/mvc/api/member/recharge'
recharge_data={'mobilephone':18688773467,'amount':'1000'} def setUp(self):
print('开始测试...') def tearDown(self):
print('测试完成...') def test_001_login_nomobie(self):
login_url = self.login
login_data = {'mobilephone':'','pwd':'123456'}
login_msg = http_request.http_get(login_url,login_data)
try:
self.assertEquals('手机号不能为空',login_msg.json()['msg'])
print('test_001_login_nomobie 测试通过')
except Exception as e:
print('test_001_login_nomobie 测试不通过')
raise e def test_002_login_nopwd(self):
login_url = self.login
login_data = {'mobilephone':18688773467,'pwd':''}
login_msg = http_request.http_get(login_url,login_data)
try:
self.assertEquals('密码不能为空',login_msg.json()['msg'])
print('test_002_login_nopwd 测试通过')
except Exception as e:
print('test_002_login_nopwd 测试不通过')
raise e def test_003_login_errorpwd(self):
login_url = self.login
login_data = {'mobilephone':18688773467,'pwd':'12345'}
login_msg = http_request.http_get(login_url,login_data)
try:
self.assertEquals('用户名或密码错误',login_msg.json()['msg'])
print('test_003_login_errorpwd 测试通过')
except Exception as e:
print('test_003_login_errorpwd 测试不通过')
raise e def test_004_login_success(self):
login_url = self.login
login_data = self.login_data
login_msg = http_request.http_get(login_url,login_data)
try:
self.assertEquals('登录成功',login_msg.json()['msg'])
print('test_004_login_success 测试通过')
cookies = login_msg.cookies
except Exception as e:
print('test_004_login_success 测试不通过')
raise e
cookies = None
return cookies def test_005_recharge_success(self):
recharge_url = self.recharge
recharge_data = self.recharge_data
cookies = self.test_004_login_success()
recharge_msg = http_request.http_post(recharge_url,recharge_data,cookies = cookies)
try:
self.assertEquals('充值成功',recharge_msg.json()['msg'])
print('test_005_recharge_success 测试通过')
except Exception as e:
print('test_005_recharge_success 测试不通过')
raise e def test_006_recharge_nomobile(self):
recharge_url = self.recharge
recharge_data = {'mobilephone':'','amount':'1000'}
cookies = self.test_004_login_success()
recharge_msg = http_request.http_post(recharge_url,recharge_data,cookies = cookies)
try:
self.assertEquals('手机号不能为空',recharge_msg.json()['msg'])
print('test_006_recharge_nomobile 测试通过')
except Exception as e:
print('test_006_recharge_nomobile 测试不通过')
raise e def test_007_recharge_errmobile(self):
recharge_url = self.recharge
recharge_data = {'mobilephone':1868877346,'amount':'1000'}
cookies = self.test_004_login_success()
recharge_msg = http_request.http_post(recharge_url,recharge_data,cookies = cookies)
try:
self.assertEquals('手机号码格式不正确',recharge_msg.json()['msg'])
print('test_007_recharge_errmobile 测试通过')
except Exception as e:
print('test_007_recharge_errmobile 测试不通过')
raise e def test_008_recharge_nocharge(self):
recharge_url = self.recharge
recharge_data = {'mobilephone':18688773467,'amount':''}
cookies = self.test_004_login_success()
recharge_msg = http_request.http_post(recharge_url,recharge_data,cookies = cookies)
try:
self.assertEquals('请输入金额',recharge_msg.json()['msg'])
print('test_008_recharge_nocharge 测试通过')
except Exception as e:
print('test_008_recharge_nocharge 测试不通过')
raise e def test_009_recharge_toolargecharge(self):
recharge_url = self.recharge
recharge_data = {'mobilephone':18688773467,'amount':'10000000000000000000000'}
cookies = self.test_004_login_success()
recharge_msg = http_request.http_post(recharge_url,recharge_data,cookies = cookies)
try:
self.assertEquals('请输入范围在0到50万之间的正数金额',recharge_msg.json()['msg'])
print('test_009_recharge_toolargecharge 测试通过')
except Exception as e:
print('test_009_recharge_toolargecharge 测试不通过')
raise e
work_20181203_testrun.py:

#-*- coding:utf-8 -*-
# author:jiaxy
# datetime:2018/12/3 14:04
# file: work_20181203_testrun.py from jiaxy import work_20181203_testcase
import HTMLTestRunner
import unittest def runTest():
suite = unittest.TestSuite()
loader = unittest.TestLoader()
suite.addTest(loader.loadTestsFromModule(work_20181203_testcase))
with open('test_result.html','wb+') as file:
runner = HTMLTestRunner.HTMLTestRunner(
stream = file,
verbosity = 2
)
runner.run(suite) if __name__ == '__main__':
runTest() 测试报告:
 

ptyhon - 接口自动化测试实战case1的更多相关文章

  1. python - 接口自动化测试实战 - case1 - 再次优化版

    本次优化: 1.  各级分Package 2.  封装[ReadExcel]类 3.  封装[ReadConfig]类 4.  封装[GetLog]类 5.  引入ddt数据驱动测试,优化测试用例代码 ...

  2. python - 接口自动化测试实战 - case1 - 优化版

    题目: 基于以下两个接口和数据完成接口自动化测试,并生成测试报告: '''登录 login='http://47.107.168.87:8080/futureloan/mvc/api/member/l ...

  3. 面面俱到的Java接口自动化测试实战

    第1章 接口自动化测试整体认知了解什么是接口和为什么要做接口测试.并且知道接口自动化测试应该学习哪些技术以及接口自动化测试的落地过程. 1-1 导学章节 1-2 什么是接口 1-3 为什么要做接口测试 ...

  4. Python接口自动化测试实战-----附源码

    目录 1. 接口定义 2. 基本流程 3. 需求分析 4. 用例设计 5. 脚本开发 6. 结果分析 接口定义: 接口普遍有两种意思,一种是API(Application Program Interf ...

  5. Java接口自动化测试实战笔记

    综述 代码管理工具Git 测试框架 TestNG 测试报告 Mock 接口框架 HTTP 协议接口 测试框架 HttpClient SprintBoot 自动化测试开发 数据持久层框架 MyBatis ...

  6. 【三】Jmeter接口自动化测试系列之Http接口自动化实战

    作者:大虫 本文介绍 Jmeter 工具的 http 接口 自动化测试 实战! 为了通用性,就拿知乎 网站作为实战例子吧! 必备技能:http接口基础知识.抓包,本文不做详细介绍,不会的可以先百度恶补 ...

  7. 关于《Python自动化测试实战》

    作者有话说 笔者写这本书的初心是想通过自身经验分享一些在自动化测试领域中的实用技术,能够帮助那些正在从事自动化测试相关工作或者准备转型自动化测试的测试人员.任何一门技术涵盖的知识点都是非常广泛的,可能 ...

  8. Python接口自动化测试框架实战 从设计到开发

    第1章 课程介绍(不要错过)本章主要讲解课程的详细安排.课程学习要求.课程面向用户等,让大家很直观的对课程有整体认知! 第2章 接口测试工具Fiddler的运用本章重点讲解如何抓app\web的htt ...

  9. 性能测试学习之路 (四)jmeter 脚本开发实战(JDBC &JMS &接口脚本 & 轻量级接口自动化测试框架)

    1.业务级脚本开发 登录脚本->思路:在线程组下新建两个HTTP请求,一个是完成访问登录页,一个是完成登录的数据提交.   步骤如下: 1) 访问登录页 2) 提交登录数据的HTTP PS:对于 ...

随机推荐

  1. jquery中使用each遍历。

    一直知道each这个方法,但是就是不太明白到底怎么用,今天两个地方都使用了each.真的太高兴了,太有成就感了. 东钿微信平台订单列表页 全部订单之前是按照产调,评估,借款的顺序依次排下来,华总说要按 ...

  2. I Have a Dream(我有一个梦想)

    I Have a Dream by Martin Luther King, Jr. I am happy to join with you today in what will go down in ...

  3. 编译错误you should not run configure as root (set FORCE_UNSAFE_CONFIGURE=1 in environment to bypass this check)

    解决方法: export FORCE_UNSAFE_CONFIGURE=1

  4. vim的命令

    下面是从一个博客里摘抄出来的, 供自己学习使用.   在命令状态下对当前行用== (连按=两次), 或对多行用n==(n是自然数)表示自动缩进从当前行起的下面n行.你可以试试把代码缩进任意打乱再用n= ...

  5. 小白学phoneGap《构建跨平台APP:phoneGap移动应用实战》连载三(通过实例来体验生命周期)

    4.1.2  通过实例来亲身体验Activity的生命周期 上一小节介绍了Activity生命周期中的各个过程,本小节将以一个简单的实例来使读者亲身体验到Activity生命周期中的各个事件. 在Ec ...

  6. awk对列求和

    awk 'BEGIN{total=0}{total+=$1}END{print total}' 文件名

  7. python+selenium之多表单切换

    在Web应用中经常会遇到fram/iframe表单嵌套页面的应用,WebDriver只能在一个页面上对元素识别与定位,对于fram/iframe表单内嵌套页面上的元素无法直接定位.这是需要通过swit ...

  8. 【exFat】利用命令提示符在windows 7 及 windows server 2008 r2 中将卷(分区)格式化为exFAT

    步骤 运行cmd.exe: 查看磁盘信息.输入diskpart并回车: 选择磁盘.输入select disk 0(“0”代表要选择的磁盘号)并回车: 查看所选硬盘的分区.输入list partitio ...

  9. Android(java)学习笔记120:BroadcastReceiver之 应用程序安装和卸载 的广播接收者

    国内的主流网络公司(比如网易.腾讯.百度等等),他们往往采用数据挖掘技术获取用户使用信息,从而采用靶向营销.比如电脑上,我们浏览网页的时候,往往会发现网页上会出现我们之前经常浏览内容的商业广告,这就是 ...

  10. 查看numpy的类型

    查看一个变量的类型:type(img) 查看array中的数据值的类型:img.dtype 查看array的形状:img.shape