Skip to content

Commit

Permalink
更新说明文档
Browse files Browse the repository at this point in the history
  • Loading branch information
Louis-me committed Nov 4, 2016
1 parent f4d1178 commit 8389fc4
Show file tree
Hide file tree
Showing 8 changed files with 317 additions and 257 deletions.
217 changes: 97 additions & 120 deletions .idea/workspace.xml

Large diffs are not rendered by default.

Binary file modified COMMON/__pycache__/http_param.cpython-34.pyc
Binary file not shown.
1 change: 0 additions & 1 deletion COMMON/http_param.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ def str_get_param(self, dict_param, param):
result = "?"
if dict_param["must"] == "1": # 如果参数是必填
result += dict_param["name"] + "=" + dict_param["value"] + "&"
# result += dict_param["name"] + "=" + str(self.str_to(dict_param["type"], dict_param["value"])) + "&"
return self.str_sub(0, len(result)-1, result) + "&" + self.for_dict(param)
# 合并dict
def for_dict(self, d):
Expand Down
Binary file modified DAL/__pycache__/Dhttpbase.cpython-34.pyc
Binary file not shown.
198 changes: 64 additions & 134 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,143 +1,27 @@
#基于python3实现的http接口自动化测试
#项目名及简介
基于python3的自动化接口测试框架

##开发环境
# 功能
* Win7 64,python 3,Pycharm. unittest
* 读取配置文件--读取测试用例--执行测试用例--记录测试结果--生成html结果文件
* xml管理用例
* 邮件发送测试结果

##框架简介
* 支持常见是HTTP中的post和get方法
* 测试案例驱动用excel管理,注意的地方是为每个案例新增自定义检查函数(更新为了生成器为xml管理)
* 根据需要配置,可以运行部分用例,全部用例
* 测试结合最后生成了html文件,方便查看。


##模块类的设计说明
* Httpbase.py 读取http的域名和端口
* Config.py http方法的封装,可以支持多协议扩展,get,post
# 用法
* Runner_m.py 核心代码。run_case是程序的入口
* Htmlreport.py 结果生成html文件
![结果生成报表](img/report.png "结果生成报表")

##主要更新历史:

###2015-8-3 更新历史
* 自动化接口测试框架完成
* 第三方包:pyh(生成结果html文件), config.ini设置信息 excel管理用例
![testCaseExcel.xlsl](img/testCaseExcel.png "testCaseExcel.xlsl")
``` 配置文件
Case_config.ini
[DEFAULT]
index = [1001,1002] 配置运行部分用例id
host = 192.168.1.249
port = 10003
```

![结果生成报表](img/report.png "结果生成报表")

###2016-1-5 更新日志
* 更新了使用了requests模块,可以自定义扩展成get,post,put,delete,head,options等方法,同时支持上传图片
* 更新脱离excel来管理测试用例,使用html生成xml接口文件后,给python来解析.

###2016-1-8 更新日志
* 修复了支持指定测试接口测试id

###2016-1-9 更新日志
* 优化在html线生成xml接口,只要填入接口名字,参数,方法,自定义函数就可以了


###2016-1-12 更新日志
* 去掉自动化函数,节省大量代码,只需在接口xml生成器上指定预期结果就可以了

###2016-1-23 更新日志
* 更新了预期结果偶尔无法检测成功的bug
* 更新了需要登陆后的id或者token联合使用接口

###2016-3-22 更新日志
* 优化了检查点。如果实际结果包含了嵌套层,检查点只要检查实际结果中嵌套层的第一个对象。如:data[{"a":b},{"a":"c"}].只要检查{"a":"b"}
* 一级检查点和二级检查点(嵌套层,只是检查key是否存在)
* 二级检查主要用的是list set差集的方式
* 更新了html接口生成器

* 生成器代码参考:https://github.com/284772894/SaveXML

### 2016-7-21

* 代码简单优化了下
* 主要更新了对比规则,第一层对比code的状态,第二层全字段对比,之前想复杂了

```
def compare(exJson,factJson):
if factJson["appStatus"]["errorCode"] == 0:
return exJson==factJson
else:
print("接口请求失败")
return False
```


### 2016-7-30 更新日志
* 修改对比规则,如果有嵌套层,首页对比第一层的code,然后对比其他嵌套层的value,不进行其他嵌套层的全字段匹配
* 配置xml

```
def compare(exJson,factJson,isList=0):
isFlag = True
if exJson.get("appStatus") == factJson.get("appStatus"):
if isList== False: # 如果没有嵌套层
return isFlag
data2 = exJson.get("content")
data3 = factJson.get("content")
for item2 in data2:
for item3 in data3:
keys2 = item2.keys()
keys3 = item3.keys()
if keys2 == keys3: # 如果嵌套层的key完全相等
for key in keys2:
value2 = item2.get(key)
value3 = item3.get(key)
if type(value3)==type(value2):# 对比嵌套层的value的type值
pass
else:
isFlag = False
break
else:
isFlag = False
break
else:
isFlag = False
print(isFlag)
return isFlag
```

### 2016-8-22 更新日志

* 测试报告改用控制excel的显示方式

![test_mark.png](img/test_mark.png "test_mark.png")

![test_detail.png](img/test_detail.png "test_detail.png")

### 2016-8-23 更新日志

* 测试报告以发送邮件的方式通知

### 2016-9-7
* 三层架构重构整个系统

### 2016-9-8
* 新增接口测试扩展
* 检查参数是否必填
* 检查参数的值类型是否正确

### 2016-9-9
* 实现检查参数是否必填
* 检查参数的值类型是否正确
* 把http_code的值合并到实际结果

```
<params>
<name type="str">account</name> # type=str表示字符类型
<value>18576759587</value>
<must>1</must> # 1表示必填,0非必填
<root>
<title>接口测试</title>
<host>ddd.XX.com</host>
<port>80</port>
<No>[1001]</No> # 不填,就是运行下面所有用例
<header>{"Accept":"text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8","User-Agent":"Mozilla/5.0 (Windows NT 6.1; rv:29.0) Gecko/20100101 Firefox/29.0"}</header>
<InterfaceList>
<params>
<name type="str">account</name>
<value>1361212121</value>
<must>1</must>
</params>
<params>
<name type="str">password</name>
Expand All @@ -149,6 +33,52 @@ def compare(exJson,factJson,isList=0):
<value>0</value>
<must>1</must>
</params>
<isList>0</isList>
<id>1001</id>
<name>登陆</name>
<method>POST</method>
<url>Login</url>
<hope>{"appStatus":{"errorCode":0,"message":"操作...</hope>
<login>user_id</login> # 登陆后需要返回的信息给其他接口调用,比如userid,token等
<isList>0</isList>
</InterfaceList>
<InterfaceList>
<params>
<name type="int">lookerId</name>
<value>2</value>
<must>1</must>
</params>
<id>1002</id>
<name>个人主页</name>
<method>GET</method>
<url>GetPersonalHomePage1</url>
<hope>{"appStatus":{"errorCode":0,"message":"操作成功"},"content":[{"business_name":"坤达点子","notice_img":"\/product\/20160718184134_321.jpg","user_type":1,"user_id":2,"goods":[{"good_price":45211.0,"good_id":12,"good_name":"艾欧","banner_picture1":"\/product\/20160719165135_8977.png"},{"good_price":199.0,"good_id":14,"good_name":"麒麟瓜1","banner_picture1":"\/product\/20160720102028_5352.jpg"},{"good_price":452.0,"good_id":6,"good_name":"实力产品","banner_picture1":"\/product\/20160718165448_2602.png"},{"good_price":99898.0,"good_id":11,"good_name":"越南芒果","banner_picture1":"\/product\/20160720100057_5877.jpg"}],"shop_img":"\/product\/20160718120144_3196.jpg","head_picture":"http:\/\/dgm.boweixin.com\/\/product\/20160718134528_4744.jpg","notice_id":1}]}</hope>
<login>1</login> # 需要登陆后的参数
<isList>1</isList> # 有嵌套层
</InterfaceList>
</root>
注意这里,如果想验证这里的值的类型或者非必填参数,预期值注意变化
<params>
<name type="str">account</name> # type=str表示字符类型
<value>18576759587</value>
<must>1</must> # 1表示必填,0非必填
</params>
```

## 关于检查点

有嵌套层。检查机制是,检查第一层的code,第二层list的key是否相等,list的value的值的type是否相等

# 使用报告

![test_mark.png](img/test_mark.png "test_mark.png")

![test_detail.png](img/test_detail.png "test_detail.png")

# 其他

* 更多信息查看我的[更新日志](channel_log.md)
* 之前写的[接口用例生成器](https://github.com/284772894/SaveXML)生产xml
154 changes: 154 additions & 0 deletions channel_log.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
#基于python3实现的http接口自动化测试

##开发环境
* Win7 64,python 3,Pycharm. unittest
* 读取配置文件--读取测试用例--执行测试用例--记录测试结果--生成html结果文件

##框架简介
* 支持常见是HTTP中的post和get方法
* 测试案例驱动用excel管理,注意的地方是为每个案例新增自定义检查函数(更新为了生成器为xml管理)
* 根据需要配置,可以运行部分用例,全部用例
* 测试结合最后生成了html文件,方便查看。


##模块类的设计说明
* Httpbase.py 读取http的域名和端口
* Config.py http方法的封装,可以支持多协议扩展,get,post
* Runner_m.py 核心代码。run_case是程序的入口
* Htmlreport.py 结果生成html文件
![结果生成报表](img/report.png "结果生成报表")

##主要更新历史:

###2015-8-3 更新历史
* 自动化接口测试框架完成
* 第三方包:pyh(生成结果html文件), config.ini设置信息 excel管理用例
![testCaseExcel.xlsl](img/testCaseExcel.png "testCaseExcel.xlsl")
``` 配置文件
Case_config.ini
[DEFAULT]
index = [1001,1002] 配置运行部分用例id
host = 192.168.1.249
port = 10003
```

![结果生成报表](img/report.png "结果生成报表")

###2016-1-5 更新日志
* 更新了使用了requests模块,可以自定义扩展成get,post,put,delete,head,options等方法,同时支持上传图片
* 更新脱离excel来管理测试用例,使用html生成xml接口文件后,给python来解析.

###2016-1-8 更新日志
* 修复了支持指定测试接口测试id

###2016-1-9 更新日志
* 优化在html线生成xml接口,只要填入接口名字,参数,方法,自定义函数就可以了


###2016-1-12 更新日志
* 去掉自动化函数,节省大量代码,只需在接口xml生成器上指定预期结果就可以了

###2016-1-23 更新日志
* 更新了预期结果偶尔无法检测成功的bug
* 更新了需要登陆后的id或者token联合使用接口

###2016-3-22 更新日志
* 优化了检查点。如果实际结果包含了嵌套层,检查点只要检查实际结果中嵌套层的第一个对象。如:data[{"a":b},{"a":"c"}].只要检查{"a":"b"}
* 一级检查点和二级检查点(嵌套层,只是检查key是否存在)
* 二级检查主要用的是list set差集的方式
* 更新了html接口生成器

* 生成器代码参考:https://github.com/284772894/SaveXML

### 2016-7-21

* 代码简单优化了下
* 主要更新了对比规则,第一层对比code的状态,第二层全字段对比,之前想复杂了

```
def compare(exJson,factJson):
if factJson["appStatus"]["errorCode"] == 0:
return exJson==factJson
else:
print("接口请求失败")
return False
```


### 2016-7-30 更新日志
* 修改对比规则,如果有嵌套层,首页对比第一层的code,然后对比其他嵌套层的value,不进行其他嵌套层的全字段匹配

```
def compare(exJson,factJson,isList=0):
isFlag = True
if exJson.get("appStatus") == factJson.get("appStatus"):
if isList== False: # 如果没有嵌套层
return isFlag
data2 = exJson.get("content")
data3 = factJson.get("content")
for item2 in data2:
for item3 in data3:
keys2 = item2.keys()
keys3 = item3.keys()
if keys2 == keys3: # 如果嵌套层的key完全相等
for key in keys2:
value2 = item2.get(key)
value3 = item3.get(key)
if type(value3)==type(value2):# 对比嵌套层的value的type值
pass
else:
isFlag = False
break
else:
isFlag = False
break
else:
isFlag = False
print(isFlag)
return isFlag
```

### 2016-8-22 更新日志

* 测试报告改用控制excel的显示方式

![test_mark.png](img/test_mark.png "test_mark.png")

![test_detail.png](img/test_detail.png "test_detail.png")

### 2016-8-23 更新日志

* 测试报告以发送邮件的方式通知

### 2016-9-7
* 三层架构重构整个系统

### 2016-9-8
* 新增接口测试扩展
* 检查参数是否必填
* 检查参数的值类型是否正确

### 2016-9-9
* 实现检查参数是否必填
* 检查参数的值类型是否正确
* 把http_code的值合并到实际结果

```
<params>
<name type="str">account</name> # type=str表示字符类型
<value>18576759587</value>
<must>1</must> # 1表示必填,0非必填
</params>
<params>
<name type="str">password</name>
<value>222222</value>
<must>1</must>
</params>
<params>
<name type="int">type</name>
<value>0</value>
<must>1</must>
</params>
```


Binary file modified report.xlsx
Binary file not shown.
4 changes: 2 additions & 2 deletions test4.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<title>导购码接口测试</title>
<host>dgm.boweixin.com</host>
<port>80</port>
<No>[1001]</No>
<No>[1001,1002]</No>
<header>{"Accept":"text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8","User-Agent":"Mozilla/5.0 (Windows NT 6.1; rv:29.0) Gecko/20100101 Firefox/29.0"}</header>
<InterfaceList>
<params>
Expand Down Expand Up @@ -39,7 +39,7 @@
<id>1002</id>
<name>个人主页</name>
<method>GET</method>
<url>GetPersonalHomePage1</url>
<url>GetPersonalHomePage</url>
<hope>{"appStatus":{"errorCode":0,"message":"操作成功"},"content":[{"business_name":"坤达点子","notice_img":"\/product\/20160718184134_321.jpg","user_type":1,"user_id":2,"goods":[{"good_price":45211.0,"good_id":12,"good_name":"艾欧","banner_picture1":"\/product\/20160719165135_8977.png"},{"good_price":199.0,"good_id":14,"good_name":"麒麟瓜1","banner_picture1":"\/product\/20160720102028_5352.jpg"},{"good_price":452.0,"good_id":6,"good_name":"实力产品","banner_picture1":"\/product\/20160718165448_2602.png"},{"good_price":99898.0,"good_id":11,"good_name":"越南芒果","banner_picture1":"\/product\/20160720100057_5877.jpg"}],"shop_img":"\/product\/20160718120144_3196.jpg","head_picture":"http:\/\/dgm.boweixin.com\/\/product\/20160718134528_4744.jpg","notice_id":1}]}</hope>
<login>1</login>
<isList>1</isList>
Expand Down

0 comments on commit 8389fc4

Please sign in to comment.