fixed dingtalk report style and sheet_filelds

This commit is contained in:
chenyongzhiaaron 2023-08-22 09:44:59 +08:00
parent 15398493c1
commit fa63068e7c
15 changed files with 1407 additions and 94 deletions

File diff suppressed because one or more lines are too long

View File

@ -23,6 +23,8 @@ paho-mqtt = "*"
ddddocr = "*"
crypto = "*"
jinja2 = "*"
prettytable = "*"
Crypto = "*"
[dev-packages]

1224
Pipfile.lock generated

File diff suppressed because it is too large Load Diff

Binary file not shown.

View File

@ -66,6 +66,7 @@ class DingTalk:
sign = None
try:
requests.post(url=self.url, json=notice_content, params=sign)
print("The dingtalk has been sent successfully")
except Exception as e:
print("发送钉钉异常", e)

View File

@ -65,10 +65,17 @@ class SendEmail:
def send_mail(self, content, file_path=None):
"""发送邮件"""
try:
s = smtplib.SMTP_SSL(self.host, self.port)
# s.starttls()
# s = smtplib.SMTP_SSL(self.host, self.port)
s = smtplib.SMTP(self.host, self.port)
s.starttls() # 尝试启用TLS/SSL连接
s.login(self.user, self.password)
s.sendmail(self.sender, self.receivers, self.content(content, file_path))
s.quit()
print("The email has been sent successfully")
except Exception as e:
print("发送邮件异常", e)
if __name__ == '__main__':
s = SendEmail()
s.send_mail()

View File

@ -101,9 +101,13 @@ class WeChat:
"""
try:
self.send_markdown()
print("The weChat_markdown has been sent successfully")
except Exception as e:
print("发送markdown信息异常", e)
try:
self.send_file(self.file_lists)
print("The weChat_file has been sent successfully")
except Exception as e:
print("发送企业微信附件异常", e)

View File

@ -118,7 +118,6 @@ class Action(Extractor, LoadScript, Validator):
"""
获取基础信息
"""
print(item)
sheet = item.pop(FieldNames.SHEET)
item_id = item.pop(FieldNames.ITEM_ID)
condition = item.pop(FieldNames.RUN_CONDITION)

View File

@ -45,7 +45,6 @@ def request_retry_on_exception(retries=2, delay=1.5):
nonlocal e
for i in range(retries):
try:
print(f"| 第{i + 1}次未处理过得请求参数:{args} -- {kwargs}")
response = func(*args, **kwargs)
print(f"| 请求地址 --> {response.request.url}")
print(f"| 请求方法 --> {response.request.method}")
@ -55,7 +54,7 @@ def request_retry_on_exception(retries=2, delay=1.5):
print(f"| 接口耗时--> {response.elapsed}")
print(f"| 接口响应--> {response.text}")
except Exception as error:
print(f"| 第{i + 1}次请求参数:{args} -- {kwargs}")
e = error
time.sleep(delay)
else:

View File

@ -13,49 +13,47 @@ import os
class Config:
# 根目录路径
# *****************************************************************
BASE_URL = os.path.dirname(__file__)
# *****************************************************************
BASE_URL = os.path.abspath(os.path.dirname(__file__))
# 父目录路径
PARENT_DIR = os.path.dirname(BASE_URL)
# 测试数据所在路径
# *****************************************************************
TEMPLATES = os.path.join(BASE_URL, "../cases", "templates", "template.xlsx") # 用例模板文件
TEST_CASE = os.path.join(BASE_URL, "../cases", "cases", "test_cases.xlsx")
TEST_FILES = os.path.join(BASE_URL, '../cases', 'files') # 用来上传文件的文件夹
# *****************************************************************
TEMPLATES = os.path.join(PARENT_DIR, "cases", "templates", "template.xlsx") # 用例模板文件
TEST_CASE = os.path.join(PARENT_DIR, "cases", "cases", "test_cases.xlsx")
TEST_FILES = os.path.join(PARENT_DIR, 'cases', 'files') # 用来上传文件的文件夹
# 测试用例脚本目录
# *****************************************************************
SCRIPT = os.path.join(BASE_URL, "../test_script")
SCRIPTS_DIR = os.path.join(BASE_URL, "../scripts")
# *****************************************************************
SCRIPT = os.path.join(PARENT_DIR, "test_script")
SCRIPTS_DIR = os.path.join(PARENT_DIR, "scripts")
# 测试报告及 logger 所在路径
# *****************************************************************
TEST_REPORT = os.path.join(BASE_URL, "../OutPut", "reports")
TEST_REPORT_FILE = os.path.join(BASE_URL, "../OutPut", "reports", "report.html")
LOG_PATH = os.path.join(BASE_URL, "../OutPut", "log")
TEST_REPORT = os.path.join(PARENT_DIR, "OutPut", "reports")
TEST_REPORT_FILE = os.path.join(PARENT_DIR, "OutPut", "reports", "report.html")
LOG_PATH = os.path.join(PARENT_DIR, "OutPut", "log")
# 邮件配置信息
MAIL_NOTICE = {
"host": "smtp.qq.com", # 邮件服务地址
"user": "262667641@qq.com", # 用户名
"password": "ztvqsnikiupvbghe", # 密码(部分邮箱为授权码)# 密码
"sender": "262667641@qq.com", # 发送人
"user": "xxxxx@qq.com", # 用户名
"password": "xxxxx", # 密码(部分邮箱为授权码)# 密码
"sender": "xxxxx@qq.com", # 发送人
"port": 465, # smtp 端口号
"receivers": ['262667641@qq.com', '125109524@qq.com'] # 接收方的邮箱
"receivers": ['262667641@qq.com'] # 接收方的邮箱
}
# 企业微信机器人配置信息
WeChat_NOTICE = {
"send_url": "https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=8b1647d4-dc32-447c-b524-548acf18a938",
"upload_url": "https://qyapi.weixin.qq.com/cgi-bin/webhook/upload_media?type=file&key=8b1647d4-dc32-447c-b524-548acf18a938",
"file_lists": [TEST_REPORT_FILE, TEST_CASE] # 需要推送的文件的路径
}
# 钉钉机器人配置信息
DINGTALK_NOTICE = {
"url": "https://oapi.dingtalk.com/robot/send?access_token=7d1e11079e00a4ca9f11283f526349abd5ba3f792ef7bcb346909ff215af02de",
"secret": "SEC441dbbdb8dbe150e5fc3e348bb449d3113b1be1a90be527b898ccd78c51566c1",
"key": "", # 安全关键字
"atMobiles": "18127813600", # 需要@指定人员的手机号
"atMobiles": "xxxxx", # 需要@指定人员的手机号
"isAtAll": True, # 是否@ 所有人
"except_info": False # 是否发送测试不通过的异常数据
}
@ -64,7 +62,6 @@ class Config:
if __name__ == '__main__':
test = Config()
print(test.BASE_URL)
print(test.TEST_CASE)
print(test.TEST_REPORT)
print(test.TEST_CASE)
print(test.SCRIPTS_DIR)
print("测试用例", test.TEST_CASE)
print("测试报告", test.TEST_REPORT)
print("测试脚本", test.SCRIPTS_DIR)

File diff suppressed because one or more lines are too long

8
run.py
View File

@ -2,7 +2,7 @@
# @Time : 2019/11/18 15:32
# @Author : kira
# @Email : 262667641@qq.com
# @File : run_main.py
# @File : run.py
# @Desc : 程序执行入口文件
import sys
import unittest
@ -19,11 +19,15 @@ from common.utils.decorators import install_dependencies
@install_dependencies
def run():
test_report = Config.TEST_REPORT
print(Config.BASE_URL)
print(test_report)
print(Config.SCRIPT)
test_case = unittest.defaultTestLoader.discover(Config.SCRIPT, pattern="test_*.py")
runner = TestRunner(test_case, report_dir=test_report, title="接口自动化测试报告", templates=2, tester="kira",
desc="自动化测试")
runner.run()
# get_failed_test_cases = runner.get_failed_test_cases()
# # get_failed_test_cases = runner.get_failed_test_cases()
# runner.email_notice()
runner.dingtalk_notice()
runner.weixin_notice()

View File

@ -2,24 +2,24 @@
## **请相关同事注意,及时跟进!**
#### 项目名称:<font color='#009933'>{{title}}</font><br/>
#### 测试人员:<font color='#009933'>{{tester}}</font><br/>
#### 开始时间:<font color='#009933'>{{begin_time}}</font><br/>
#### 运行时间:<font color='#009933'>{{runtime}}</font><br/>
> 测试用例总数:**<font color='#009933'>{{all}}</font><br/>**
> 测试用例通过率:**<font color='#009933'>{{pass_rate}}%</font><br/>**
> 成功数: **<font color='#009933'>{{success}}</font><br/>**
> 失败数:**<font color='#FF6666'>{{fail}}</font><br/>**
> 跳过数:**<font color='#009999'>{{skip}} </font><br/>**
> 错误数:**<font color='#CC0066'>{{error}}</font><br/>**
#### 项目名称:<font color='#009933'>{{ title }}</font><br/>
#### 测试人员:<font color='#009933'>{{ tester }}</font><br/>
#### 开始时间:<font color='#009933'>{{ begin_time }}</font><br/>
#### 运行时间:<font color='#009933'>{{ runtime }}</font><br/>
> 测试用例总数:**<font color='#009933'>{{ all }}</font><br/>**
> 测试用例通过率:**<font color='#009933'>{{ pass_rate }}%</font><br/>**
> 成功数: **<font color='#009933'>{{ success }}</font><br/>**
> 失败数:**<font color='#FF6666'>{{ fail }}</font><br/>**
> 跳过数:**<font color='#009999'>{{ skip }} </font><br/>**
> 错误数:**<font color='#CC0066'>{{ error }}</font><br/>**
##### **报告链接:** [jenkins报告,请点击后进入查看](report_url)
**----------------上一次运行结果----------------**<br/>
> 测试用例总数: **<font color='#009933'>{{ history[-1]['all'] }}</font><br/>**
> 测试用例通过率:**<font color='#009933'>{{history[-1]['pass_rate']}}%</font><br/>**
> 成功数:**<font color='#009933'>{{history[-1]['success']}}</font><br/>**
> 失败数:**<font color='#FF6666'>{{history[-1]['fail']}}</font><br/>**
> 跳过数:**<font color='#009999'>{{history[-1]['skip']}}</font><br/>**
> 错误数:**<font color='#CC0066'>{{history[-1]['error']}}</font><br/>**
> 测试用例总数: **<font color='#009933'>{{ history[-2]['all'] }}</font><br/>**
> 测试用例通过率:**<font color='#009933'>{{ history[-2]['pass_rate'] }}%</font><br/>**
> 成功数:**<font color='#009933'>{{ history[-2]['success'] }}</font><br/>**
> 失败数:**<font color='#FF6666'>{{ history[-2]['fail'] }}</font><br/>**
> 跳过数:**<font color='#009999'>{{ history[-2]['skip'] }}</font><br/>**
> 错误数:**<font color='#CC0066'>{{ history[-2]['error'] }}</font><br/>**
##### **报告链接:** [jenkins报告,请点击后进入查看](report_url)

View File

@ -1,21 +1,21 @@
# **提醒!自动化测试反馈**
## **请相关同事注意,及时跟进!**
> 项目名称:<font color='info'>{{title}}</font>
> 测试人员:<font color='info'>{{tester}}</font>
> 开始时间:<font color='info'>{{begin_time}}</font>
> 运行时间:<font color='info'>{{runtime}}</font>
> 测试用例总数:<font color='info'>{{all}}</font>
> 测试用例通过率:<font color='info'>{{pass_rate}}%</font>
> 成功数: <font color='info'>{{success}}</font>
> 失败数:<font color='warning'>{{fail}}</font>
> 跳过数:<font color='info'>{{skip}}, </font>
> 错误数:<font color='comment'>{{error}}</font>
> **--------------------上一次运行结果--------------------**
> 测试用例总数: <font color='info'>{{ history[-1]['all'] }}</font>
> 测试用例通过率:<font color='info'>{{history[-1]['pass_rate']}}%</font>
> 成功数:<font color='info'>{{history[-1]['success']}}</font>
> 失败数:<font color='warning'>{{history[-1]['fail']}}</font>
> 跳过数:<font color='info'>{{history[-1]['skip']}}</font>
> 错误数:<font color='comment'>{{history[-1]['error']}}</font>
> ##### **报告链接:** [jenkins报告,请点击后进入查看](report_url)
> 项目名称:<font color='info'>{{ title }}</font>
> 测试人员:<font color='info'>{{ tester }}</font>
> 开始时间:<font color='info'>{{ begin_time }}</font>
> 运行时间:<font color='info'>{{ runtime }}</font>
> 测试用例总数:<font color='info'>{{ all }}</font>
> 测试用例通过率:<font color='info'>{{ pass_rate }}%</font>
> 成功数: <font color='info'>{{ success }}</font>
> 失败数:<font color='warning'>{{ fail }}</font>
> 跳过数:<font color='info'>{{ skip }}, </font>
> 错误数:<font color='comment'>{{ error }}</font>
##### **报告链接:** [jenkins报告,请点击后进入查看](report_url)
**--------------------上一次运行结果--------------------**
> 测试用例总数: <font color='info'>{{ history[-2]['all'] }}</font>
> 测试用例通过率:<font color='info'>{{ history[-2]['pass_rate'] }}%</font>
> 成功数:<font color='info'>{{ history[-2]['success'] }}</font>
> 失败数:<font color='warning'>{{ history[-2]['fail'] }}</font>
> 跳过数:<font color='info'>{{ history[-2]['skip'] }}</font>
> 错误数:<font color='comment'>{{ history[-2]['error'] }}</font>