当前位置:网站首页>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 …
边栏推荐
- C language pointer (Part 2)
- LED模拟与数字调光
- External interrupt to realize key experiment
- Register address name mapping
- 2021 year end summary
- Analysis of abnormal channel number information before and after AGC re signature service
- Unity shader beginner's Essentials (I) -- basic lighting notes
- Screen automatically generates database documents
- 为不同类型设备构建应用的三大更新 | 2022 I/O 重点回顾
- LeetCode 736. LISP syntax parsing
猜你喜欢
Druid monitoring - Introduction to JMX usage and principle
C language pointer (special article)
串口实验——简单数据收发
Recommended by Alibaba P8, the test coverage tool - Jacobo is very practical
【Istio Network CRD VirtualService、Envoyfilter】
Register address name mapping
How long does the PMP usually need to prepare for the exam in advance?
Led analog and digital dimming
2022-06-30 Unity核心8——模型导入
寄存器地址名映射
随机推荐
GoLand set goproxy
STM32串口寄存器库函数配置方法
硬核分享:硬件工程师常用工具包
C语言指针(特别篇)
LED模拟与数字调光
OpenGL帧缓冲
Analysis of abnormal channel number information before and after AGC re signature service
What are the suggestions for PMP candidates?
What is the rating of Huishang futures company? Is it safe to open an account? I want to open an account, OK?
[chaosblade: node disk filling, killing the specified process on the node, suspending the specified process on the node]
Simulation volume leetcode [general] 1557 The minimum number of points that can reach all points
C language pointer (Part 2)
RuntimeError: Calculated padded input size per channel: (1 x 1). Kernel size: (5 x 5). Kernel size c
Synchronized underlying principle, volatile keyword analysis
平台化,强链补链的一个支点
[istio introduction, architecture, components]
Original collection of hardware bear (updated on June 2022)
selenium自动化集成,八年测试经验软测工程师,一篇文章带你学懂
Leetcode刷题记录(数组)组合总和、组合总和 II
寄存器地址名映射