当前位置:网站首页>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 …
边栏推荐
- Interpretation of MySQL optimization principle
- Simulation volume leetcode [general] 1567 Length of the longest subarray whose product is a positive number
- With an annual salary of 50W, Alibaba P8 will come out in person to teach you how to advance from testing
- Golang etcdv3 reports an error. The attribute in grpc does not exist
- Original collection of hardware bear (updated on June 2022)
- What are the suggestions for PMP candidates?
- Several common database connection methods
- STM32的时钟系统
- Output a spiral matrix C language
- Enterprise manager cannot connect to the database instance
猜你喜欢

How long does the PMP usually need to prepare for the exam in advance?

使用Typora编辑markdown上传CSDN时图片大小调整麻烦问题

端口复用和重映像

串口實驗——簡單數據收發

Full link voltage test of the e-commerce campaign Guide

C language pointer (Part 1)

Register address name mapping

为不同类型设备构建应用的三大更新 | 2022 I/O 重点回顾

Two schemes of unit test

面试题:高速PCB一般布局、布线原则
随机推荐
LED模拟与数字调光
Simulation volume leetcode [general] 1705 The maximum number of apples to eat
Leetcode刷题记录(数组)组合总和、组合总和 II
channel. Detailed explanation of queuedeclare parameters
Problems encountered in the use of go micro
Digital triangle model acwing 1027 Grid access
Chaosblade: introduction to chaos Engineering (I)
Systick滴答定时器
阿里p8推荐,测试覆盖率工具—Jacoco,实用性极佳
On December 8th, 2020, the memory of marketing MRC application suddenly increased, resulting in system oom
模拟卷Leetcode【普通】1609. 奇偶树
How to use Arthas to view class variable values
面试题:高速PCB一般布局、布线原则
如何统计项目代码行数
Calculation s=1+12+123+1234+12345 C language
外部中断实现按键实验
Golang etcdv3 reports an error. The attribute in grpc does not exist
Simulation volume leetcode [general] 1609 Parity tree
MySQL主从延迟的解决方案
Output all composite numbers between 6 and 1000