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. 牛客NOIP提高组(二)题解

    心路历程 预计得分:100 + 40 + 30 = 170 实际得分:100 + 30 + 0 = 130 T2有一个部分分的数组没开够RE了. T3好像是思路有点小问题.. 思路没问题,实现的时候一 ...

  2. hadoop完全分布式模式搭建和hive安装

    简介 Hadoop是用来处理大数据集合的分布式存储计算基础架构.可以使用一种简单的编程模式,通过多台计算机构成的集群,分布式处理大数据集.hadoop作为底层,其生态环境很丰富. hadoop基础包括 ...

  3. vim的命令

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

  4. datatables添加长按事件

    长按事件 $.fn.longPress = function (fn) { var timeout = undefined; var $this = this; for (var i = 0; i & ...

  5. ansible 任务委派 delegate_to

    ansible 任务委派功能delegate_to run_noce: true  在一个主机上面只执行一次一个任务. ,如果没有这个参数的话,每个playbook中的组的主机都会执行一次. 我们有的 ...

  6. Spring多种方式实现依赖注入

    平常的Java开发中,程序员在某个类中需要依赖其它类的方法. 通常是new一个依赖类再调用类实例的方法,这种开发存在的问题是new的类实例不好统一管理. Spring提出了依赖注入的思想,即依赖类不由 ...

  7. Linux运维笔记--第四部

    第四部 3. Linux扩展正则表达式实战 扩展的正则表达式:ERE(主要用于egrep或grep  -E) +      重复一个或一个以上前面的字符. (*是0或多个) ?     重复0个或一个 ...

  8. ssh整合思想初步 struts2与Spring的整合 struts2-spring-plugin-2.3.4.1.jar下载地址 自动加载Spring中的XML配置文件 Struts2下载地址

    首先需要JAR包 Spring整合Structs2的JAR包 struts2-spring-plugin-2.3.4.1.jar 下载地址 链接: https://pan.baidu.com/s/1o ...

  9. 简单的Datable转List方法

    public static class DataTableUtils<T> where T : new() { public static List<T> ConvertToM ...

  10. python queue - 同步队列类

    参考 官网 queue 模块 queue 模块实现多生产者,多消费者队列. 当必须在 ==多个线程之间安全地交换信息== 时,它在线程编程中特别有用. 此模块中的Queue类实现了所有必需的锁定语义. ...