当前位置:网站首页>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 …
边栏推荐
- Calculation s=1+12+123+1234+12345 C language
- 2022-07-06 unity core 9 - 3D animation
- 模拟卷Leetcode【普通】1609. 奇偶树
- Unity shader beginner's Essentials (I) -- basic lighting notes
- How long does the PMP usually need to prepare for the exam in advance?
- 模拟卷Leetcode【普通】1705. 吃苹果的最大数目
- JVM garbage collection detailed learning notes (II)
- MySQL master-slave delay solution
- Analysis of Hessian serialization principle
- C language pointer (special article)
猜你喜欢
STM32串口寄存器库函数配置方法
Led analog and digital dimming
What are the conditions for applying for NPDP?
LeetCode 736. Lisp 语法解析
2021 year end summary
Summary of PMP learning materials
The longest ascending subsequence model acwing 1017 Strange thief Kidd's glider
LeetCode 715. Range module
Calf problem
Ppt template and material download website (pure dry goods, recommended Collection)
随机推荐
Alibaba P8 teaches you how to realize multithreading in automated testing? Hurry up and stop
模拟卷Leetcode【普通】1705. 吃苹果的最大数目
使用Typora编辑markdown上传CSDN时图片大小调整麻烦问题
PMP experience learning and sharing process
Unity Shader入门精要初级篇(一)-- 基础光照笔记
Original collection of hardware bear (updated on May 2022)
Unityshader introduction essentials personal summary -- Basic chapter (I)
硬件大熊原创合集(2022/05更新)
年薪50w阿里P8亲自下场,教你如何从测试进阶
测试人一定要会的技能:selenium的三种等待方式解读,清晰明了
Simulation volume leetcode [general] 1557 The minimum number of points that can reach all points
[istio introduction, architecture, components]
Original collection of hardware bear (updated on June 2022)
2022-06-30 Unity核心8——模型导入
Esp32-ulp coprocessor low power mode RTC GPIO interrupt wake up
【Istio Network CRD VirtualService、Envoyfilter】
C语言指针(中篇)
Two schemes of unit test
Analysis of Hessian serialization principle
Synchronized underlying principle, volatile keyword analysis