当前位置:网站首页>Pytest+request+allure+excel interface automatic construction from 0 to 1 [five nails / flying Book notice]
Pytest+request+allure+excel interface automatic construction from 0 to 1 [five nails / flying Book notice]
2022-07-07 09:08:00 【Song_ Lun】
Preface
Usually, the formal company processes such as sending test reports through email , But there are also many companies that use nails / Flying books and other office software . It must be necessary to communicate at work . Then send the test report directly to nailing / Flying books Can't everyone see ? After all, email won't be followed all the time .
obtain Jenkins Report record
Using automatic notification we will use jenkins Integrate , My other files have installation records , You can read it by yourself
utilize jenkins After the construction is completed, a construction record will be generated , Just nail the nail / Fly book can push this record .
The code needs to be installed before it starts jenkins
Dependency package
pip3 install jenkins
import jenkins
import time
# Define a constructor Get before each execution
def __init__(self):
self.errorMsg = ""
self.tile = time.strftime("%Y-%m-%d %H:%M:%S")
try:
""" Catch link exceptions or read exception information """
self.jenkins_url = con.jenkins_url # jenkins Address I'm encapsulated in the configuration file
self.server = jenkins.Jenkins(self.jenkins_url, username=con.jenkins_name, password=con.jenkins_passwd) # Connect jenkins service
# obtain jenkins_url
self.job_name = "job/autotest/" # Splicing job name
self.job_url = self.jenkins_url + self.job_name # job Of url Address
# Get the last build
self.job_last_number = self.server.get_info(self.job_name)['lastBuild']['number']
# # Get the report address
self.report_url = self.job_url + str(self.job_last_number) + '/allure' # Report address
log.debug("jenkins Address :%s" % self.report_url)
except Exception as e:
self.errorMsg = str(e)
log.info("jenkins Abnormal connection %s" %e)
Code finished Remember to simulate Whether the latest build record can be obtained normally !
Flybook notice
The record is built Next, you can write a push notice
Nail open platform : Nail open platform
Create nail swarm robots
Add custom robots to group chat , Set robot name and customization key word
After setting up have access to postman Simulate push notifications !
url = 'hhttps://oapi.dingtalk.com/robot/send?access_token=xxx' # url = Webhook Direct copy
data = {
"msgtype": "markdown",
"markdown": {
"title": " Project interface test report ",
"text": "<font color=\'#FFA500\'>[ notice ] </font> Code quality inspection report \n\n --- \n\n <font color=\'#778899\' size=2> Project name : test markdown Style item </font> \n\n <font color=\'#708090\' size=2> Project address :[ Click jump details ](https://ding-doc.dingtalk.com/doc#/serverapi2/qf2nxq)</font> \n\n <font color=\'#708090\' size=2> Detection branch :master</font> \n\n <font color=\'#708090\' size=2>bug Number :</font><font color=\'#FF0000\' size=2>3</font> \n\n <font color=\'#708090\' size=2> Relevant personnel :@13282148187</font> \n\n --- \n\n ** Broadcast time :2020-12-20 13:55:00**" # Use H5 Format writing style
},
"at": {
"atMobiles": [
" The mobile number of someone in the Group "
],
"isAtAll": false
}
}
If the group message gets the notification That means it's ok .
obtain Allure Execution data
Integrate the information obtained by the interface and the notification information
# Read allure In the report file "prometheusData.txt" file , Loop through to get the required value .
def dd_test_group():
# Get current date
tile = time.strftime("%Y-%m-%d %H:%M:%S")
d = {
}
proDir = "/Users/xxxx/jenkins/workspace/xxxx/bin" # Project path
f = open(proDir + '/allure-report/export/prometheusData.txt', 'r') # prometheusData The full path
for lines in f:
for c in lines:
launch_name = lines.strip('\n').split(' ')[0]
num = lines.strip('\n').split(' ')[1]
d.update({
launch_name: num})
f.close()
retries_run = d.get('launch_retries_run') # Total number of runs
status_passed = d.get('launch_status_passed') # Passing quantity
status_failed = d.get('launch_status_failed') # Fail quantity
status_broken = d.get('launch_status_broken') # Number of exceptions
url = "https://oapi.dingtalk.com/robot/send"
querystring = {
"access_token":"Webhook value "}
data = {
"msgtype": "markdown",
"markdown": {
"title": " Project interface test report ",
"text": "<font color=\'#FFA500\'>[ notice ] </font> Project interface test report \n\n --- \n\n"+
" Project name : Energy storage api Interface data report \n\n "+
" Report links :%s" % jenkins_data() +"\n\n"+
" Monitor branches :dev \n\n"+"\n\n" +
" Total number of runs :%s" % retries_run +"\n\n"+
" Passing quantity :%s" % status_passed +"\n\n"+
" Number of exceptions :%s" % status_broken + "\n\n"
" Fail quantity :%s" % status_failed +"\n\n"+
" Relevant personnel : @ The mobile number of someone in the Group " +"\n\n"+
"</font> \n\n --- \n\n ** The elapsed time :** %s" %tile
},
"at": {
"atMobiles": [
" The mobile number of someone in the Group "
],
"isAtAll": False
}
}
json_str = json.dumps(data)
headers = {
'content-type': "application/json"
}
response = requests.request("POST", url, data=json_str, headers=headers, params=querystring)
print(response.text)
Nail notification
The record is built Next, you can write a push notice
Flying book open platform : Flying book open platform
Create flying Book Robots
The method is similar to nail
postman Test push
url = 'https://open.feishu.cn/open-apis/bot/v2/hook/xxxxx'
data = {
"mobiles": " The mobile number of someone in the Group ",
"msg_type": "post",
"content": {
"post": {
"zh_cn": {
"title": " Project interface test report ",
"content": [
[
{
"tag": "text",
"text": " Project name : "
},
{
"tag": "text",
"text": " test \n"
},
{
"tag": "text",
"un_escape": true,
"text": " Report links : "
},
{
"tag": "a",
"text": " link \n",
"href": "https://www.baidu.com/"
},
{
"tag": "text",
"text": " Monitor branches : "
},
{
"tag": "text",
"text": "dev\n"
},
{
"tag": "text",
"text": " Total number of runs : "
},
{
"tag": "text",
"text": "100\n"
},
{
"tag": "text",
"text": " Passing quantity : "
},
{
"tag": "text",
"text": "89\n"
},
{
"tag": "text",
"text": " Number of exceptions : "
},
{
"tag": "text",
"text": "1\n"
},
{
"tag": "text",
"text": " Fail quantity : "
},
{
"tag": "text",
"text": "10\n"
},
{
"tag": "text",
"text": " The elapsed time : "
},
{
"tag": "text",
"text": "2021-04-14 15:26:56\n"
}
]
]
}
}
}
}
obtain Allure Execution data
Similar to nails …
边栏推荐
- PMP experience learning and sharing process
- H3C vxlan configuration
- LeetCode 736. LISP syntax parsing
- Alibaba P8 teaches you how to realize multithreading in automated testing? Hurry up and stop
- NVIC中断优先级管理
- JVM garbage collection detailed learning notes (II)
- 如何统计项目代码行数
- systemd
- C语言指针(习题篇)
- UnityShader入门精要个人总结--基础篇(一)
猜你喜欢
Interview question: general layout and wiring principles of high-speed PCB
What are the conditions for applying for NPDP?
LeetCode 736. LISP syntax parsing
[istio introduction, architecture, components]
Reading notes of pyramid principle
How to pass the PMP Exam in a short time?
JVM 内存结构 详细学习笔记(一)
Reflections on the way of enterprise IT architecture transformation (Alibaba's China Taiwan strategic thought and architecture practice)
PPT模板、素材下载网站(纯干货,建议收藏)
NVIC中断优先级管理
随机推荐
Reading notes of pyramid principle
STM32串口寄存器库函数配置方法
The longest ascending subsequence model acwing 1017 Strange thief Kidd's glider
LeetCode 736. LISP syntax parsing
Skills that testers must know: Selenium's three waiting ways are interpreted clearly
2020 year end summary
PPT模板、素材下载网站(纯干货,建议收藏)
RuntimeError: Calculated padded input size per channel: (1 x 1). Kernel size: (5 x 5). Kernel size c
go mod module declares its path as: gtihub. com/xxx-xx but was required as:xx-xx
Simulation volume leetcode [general] 1609 Parity tree
寄存器地址名映射
H3C vxlan configuration
硬核分享:硬件工程师常用工具包
Panel display technology: LCD and OLED
Output a spiral matrix C language
面板显示技术:LCD与OLED
How to realize sliding operation component in fast application
NVIC中断优先级管理
徽商期货公司评级是多少?开户安全吗?我想开户,可以吗?
What are the suggestions for PMP candidates?