Jenkins生成allure特色报告

一、插件安装

如下图所示,搜索插件allure安装。
在这里插入图片描述

二、插件配置

2.1 Jenkins的allure配置

①自行到网上下载allure客户端,②Jenkins进入Dashboard>>Manage Jenkins>>Global Tool Configuration.如图配置
在这里插入图片描述

2.2 在job中allure报告的配置

在这里插入图片描述

三、报告展示

3.1 代码示例

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# 2022/10/6 9:06
# Author : root
# File   : pytest_report.py
import os
import shutil

import pytest,allure,requests
import re
import io
import sys

sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8')  #防止输出乱码

@allure.feature("weather interfaces test report")
class TestWeather(object):

    def fun(self,data):
        z = data.replace("\n", "").split(";")
        data = {}
        for i in z:
            y = i.split("=")
            try:
                key = re.findall('data\["(.*?)"\]', y[0])[0]
                value = eval(y[1])
                data[key] = value
            except:
                pass
        return data

    @allure.step("天气接口断言")
    @allure.title("天气接口断言")
    @allure.story("天气接口测试")
    @allure.description("验证天气接口是否良好")
    @pytest.mark.parametrize(("city",),[("重庆",),("北京",),("上海",)])
    def test_01(self,city):
        url = "https://weathernew.pae.baidu.com/weathernew/pc"
        params = {"query":city+"天气","srcid":4982}
        res = requests.get(url,params=params).content.decode("unicode_escape")
        data = re.findall('data\["position"\]=[\s\S]*false;',res)[0]
        data = self.fun(data)
        #print(data)
        get_city = data["position"]["city"]
        assert get_city == city
        print(f"城市:{data['position']['city']}\n"
              f"体感信息:{data['weather']['bodytemp_info']}\n"
              f"风向:{data['weather']['wind_direction']}\n"
              f"天气:{data['weather']['weather']}\n"
              f"最低温:{data['weather']['dew_temperature']}度\n"
              f"是否下雪:{data['weather']['precipitation_type']}\n"
              f"风速:{data['weather']['wind_direction_num']}级\n"
              f"最高温:{data['weather']['temperature']}\n"
              f"风力等级:{data['weather']['wind_power']}\n"
              )

if __name__ == '__main__':
    report_path = r"./report"
    temp_path = report_path + "//allure-results"
    xml = report_path+"xml"
    report_path_report = report_path + "\\report"
    pytest.main(["pytest_report.py", "-s", f"--alluredir={temp_path}",
                f"--junitxml={xml}/result.xml"])

城市:重庆 体感信息:湿度大,体感湿凉 风向:西北风 天气:阴 最低温:13度 是否下雪:无降雨和降雪 风速:7级 最高温:16 风力等级:3级
城市:北京 体感信息:人体感觉天气较凉 风向:西南风 天气:晴 最低温:-2度 是否下雪:无降雨和降雪 风速:5级 最高温:17
风力等级:3级
城市:上海 体感信息:湿度大,体感湿凉 风向:西北风 天气:阴 最低温:15度 是否下雪:无降雨和降雪 风速:7级 最高温:18
风力等级:1级

3.2 在Jenkins中运行成功后展示

在这里插入图片描述

3.3 allure报告展示

可以查看历史和重试次数以及总览
在这里插入图片描述

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值