当前位置:网站首页>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 Exam Preparation experience systematically improve project management knowledge through learning
- Goldbach conjecture C language
- Several stages of PMP preparation study
- The longest ascending subsequence model acwing 1017 Strange thief Kidd's glider
- 测试人一定要会的技能:selenium的三种等待方式解读,清晰明了
- RuntimeError: Calculated padded input size per channel: (1 x 1). Kernel size: (5 x 5). Kernel size c
- [chaosblade: node disk filling, killing the specified process on the node, suspending the specified process on the node]
- Synchronized underlying principle, volatile keyword analysis
- C语言指针(习题篇)
- 【ChaosBlade:节点磁盘填充、杀节点上指定进程、挂起节点上指定进程】
猜你喜欢

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

2022-07-06 Unity核心9——3D动画

硬核分享:硬件工程师常用工具包

2022-06-30 unity core 8 - model import

Screen automatically generates database documents

Reflections on the way of enterprise IT architecture transformation (Alibaba's China Taiwan strategic thought and architecture practice)

Do you have any certificates with high gold content?

C语言指针(中篇)

Summary of PMP learning materials

Systick tick timer
随机推荐
2022-07-06 Unity核心9——3D动画
MAC OSX php dyld: Library not loaded: /usr/local/xxxx. dylib
阿里p8推荐,测试覆盖率工具—Jacoco,实用性极佳
Why is access to the external network prohibited for internal services of the company?
模拟卷Leetcode【普通】1706. 球会落何处
NVIC中断优先级管理
Enterprise manager cannot connect to the database instance
ChaosBlade:混沌工程简介(一)
徽商期货公司评级是多少?开户安全吗?我想开户,可以吗?
Hard core sharing: a common toolkit for hardware engineers
JVM 垃圾回收 详细学习笔记(二)
Count the number of words C language
The longest ascending subsequence model acwing 1017 Strange thief Kidd's glider
Serial port experiment - simple data sending and receiving
Druid monitoring - Introduction to JMX usage and principle
Alibaba P8 teaches you how to realize multithreading in automated testing? Hurry up and stop
PMP experience learning and sharing process
Skills that testers must know: Selenium's three waiting ways are interpreted clearly
Panel display technology: LCD and OLED
Port occupation troubleshooting