学习笔记——测试进阶之路 工作笔记:Jenkins+Allure+ 钉钉推送的接口自动化测试
大海
·
June 19, 2020
·
2233 hits
「All right reserved, any unauthorized reproduction or transfer is prohibitted」
EXCEL 数据源
代码结构
代码逻辑(举个例子)
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
@File : Test_08_解除用户绑定.py
@Time : 2020/06/18
@Author : xxx
@Email : xxx
"""
import json
import subprocess
import pytest
import allure
import requests
import pandas as pd
def GetExcelValue(filepath, sheet_name):
"""
keep_default_na : bool, default True
如果指定na_values参数,并且keep_default_na=False,那么默认的NaN将被覆盖,否则添加。
:param filepath: Excel地址
:param sheet_name: sheet名称
:return: 返回表格内容
"""
data = pd.read_excel(filepath, sheet_name=sheet_name, keep_default_na=False)
return data
@allure.step("获取userid值: 第{0}行, 第{1}列")
def GetUserId(x, y):
data = GetExcelValue("D:/QCC_NewApiAutomation/DataSource/RemoveWechatNotice.xlsx", "RemoveWechatNotice")
userId = data.iloc[x, y]
allure.attach(userId, "userId值", allure.attachment_type.TEXT)
return userId
@allure.step("接口请求开始")
def check_result(x, y):
baseurl = "http://xxxxxx/Risk/removeWechatNotice"
# 添加URL信息
allure.attach(baseurl, "URL地址", allure.attachment_type.TEXT)
# 传值列表
params = {"userId": GetUserId(x, y)}
new_params = json.dumps(params, ensure_ascii=False)
# 添加参数信息
allure.attach(new_params, "参数列表", allure.attachment_type.JSON)
# 将url和params进行http传递,发送请求
# post(url, data=None, json=None, **kwargs)
res = requests.post(url=baseurl, data=params)
# JSON文件转为字典格式
resp_data = json.loads(res.text)
return resp_data
@allure.feature("解除用户绑定")
class TestRemoveWechatNotice:
@allure.tag('userId')
@allure.title('解除用户绑定: userid为空')
@allure.story('userid为空')
@allure.severity(allure.severity_level.CRITICAL)
def test_01_RemoveWechatNotice(self, enter, start):
"""
用例描述:userid为空
:return:
"""
with allure.step("查看接口返回值"):
# 获取接口返回值,字典格式展示
data = check_result(0, 2)
# 字典转为JSON格式,作为附件内容加入报告中
new_data_value = json.dumps(data, ensure_ascii=False)
allure.attach(new_data_value, "返回值内容", allure.attachment_type.JSON)
with allure.step("查看status状态值"):
# json格式数据转换为字典,获取返回值中的status值
status_value = json.loads(new_data_value, strict=False)["status"]
data = {"status": status_value}
new_data = json.dumps(data, ensure_ascii=False)
allure.attach("500", "status期望值", allure.attachment_type.TEXT)
allure.attach(new_data, "status实际值", allure.attachment_type.JSON)
with allure.step("查看message信息值"):
# json格式数据转换为字典,获取返回值中的message值
message_value = json.loads(new_data_value)["message"]
# 字典转为JSON格式,作为附件内容加入报告中
# json.dumps():将汉字转为unicode编码
# json默认会进行字符转换,添加ensure_ascii=False,让汉字不转为unicode编码
data = json.dumps(message_value, ensure_ascii=False)
# 添加日志信息
allure.attach("userId是必填项", "message期望值", allure.attachment_type.TEXT)
allure.attach(data, "message实际值", allure.attachment_type.JSON)
# 判断状态是否一致
with allure.step("判断状态是否一致"):
assert status_value == 500
# 判断必填项的提示信息是否存在
with allure.step("判断是否有必填项的提示信息"):
assert message_value == "userId是必填项"
@allure.tag('userId')
@allure.title('解除用户绑定: userid传值')
@allure.story('userid传值')
@allure.severity(allure.severity_level.CRITICAL)
def test_02_RemoveWechatNotice(self, enter, start):
"""
用例描述:userid传值
:return:
"""
with allure.step("查看接口返回值"):
# 获取接口返回值,字典格式展示
data = check_result(1, 2)
# 字典转为JSON格式,作为附件内容加入报告中
new_data_value = json.dumps(data, ensure_ascii=False)
allure.attach(new_data_value, "返回值内容", allure.attachment_type.JSON)
with allure.step("查看status状态值"):
# json格式数据转换为字典,获取返回值中的status值
status_value = json.loads(new_data_value, strict=False)["Status"]
data = {"status": status_value}
new_data = json.dumps(data, ensure_ascii=False)
allure.attach("200", "status期望值", allure.attachment_type.TEXT)
allure.attach(new_data, "status实际值", allure.attachment_type.JSON)
# 判断状态是否一致
with allure.step("判断状态是否一致"):
assert status_value == 200
if __name__ == '__main__':
pytest.main(['--alluredir=D:/QCC_NewApiAutomation/Result/allure_results'])
subprocess.check_output("allure serve allure_report")
Allure 环境配置
Jenkins 平台集成
跑所有的接口
跑指定的接口
配置钉钉推送
安装钉钉插件
Configure System
项目配置
进行钉钉推送
TesterHome 为用户提供「保留所有权利,禁止转载」的选项。
除非获得原作者的单独授权,任何第三方不得转载标注了「All right reserved, any unauthorized reproduction or transfer is prohibitted」的内容,否则均视为侵权。
具体请参见TesterHome 知识产权保护协议。
如果觉得我的文章对您有用,请随意打赏。您的支持将鼓励我继续创作!
No Reply at the moment.