从0开始python学习-35.allure报告企业定制

目录

1. 搭建allure环境

2. 生成报告

3. logo定制

4. 企业级报告内容或层级定制

5. allure局域网查看


1. 搭建allure环境

1.1 JDK,使用PyCharm

  1. 找到pycharm安装目录
  2. 找到java.exe
  3. 记下jbr目录的完整路径,eg: C:\Program Files\JetBrains\PyCharm Community Edition 2022.3\jbr\bin
  4. 将地址添加进入环境变量
  5. 重启

1.2 allure程序

  1. 下载地址:https://github.com/allure-framework/allure2/releases
  2. 解压到指定路径。eg: D:\study\allure-2.25.0\allure-2.25.0\bin
  3. 执行allure
  4. Path 追加allure安装路径
  5. 验证是否安装成功:在dos窗口和Pycharm(需要重启加载环境变量)中都需要验证:allure --version

2. 生成报告

2.1 生成临时的json格式的报告

addopts = -vs --alluredir=./temps --clean-alluredir
; --clean-alluredir生成临时报告并清除

2.2 生成HTML的allure报告

if __name__ == "__main__":pytest.main(['./test_study/test_fixture.py'])os.system("allure generate ./temps -o ./reports --clean") # -o 指定输出测试报告路径# --clean 清空历史数据# ./temps 表示用来生成html的JSON临时文件目录# ./reports 表示html文件生成目录

3. logo定制

3.1 在D:\study\allure-2.25.0\allure-2.25.0\config目录下的allure.yml中配置自定义的logo插件【- custom-logo-plugin】

3.2 重新运行并生成allue报告

3.3 增加一个自己的logo文件并修改D:\study\allure-2.25.0\allure-2.25.0\plugins\custom-logo-plugin\static路径下的styles.css文件里面的样式(最好将需要修改的logo也放在custom-logo-plugin目录下)

.side-nav__brand {background: url('1.png') no-repeat left center !important; //将你需要的logo图片地址放在这里margin-left: 22px; //调整方位height: 90px; //调整大小background-size: contain !important;
}
//去掉图片后边 allure 文本
.side-nav__brand-text{display: none; 
}
//配置logo 后面的字体样式与字体大小
.side-nav__brand:after {content: "测试测试";margin-left: 18px;height: 20px;font-family: Arial;font-size: 13px;
}

 注:logo图片和文字可以同时存在,也可以只要一个

4. 企业级报告内容或层级定制

左边:

1. 项目名称(史诗):@allure.epic("测试报告")

2. 模块名称(特性):@allure.feature("测试模块")

3. 接口名称(分组):@allure.story("测试接口")

@allure.epic('测试报告')
@allure.feature('测试模块')
class TestA:@allure.story('测试1')def test_1(self):print('11111')@allure.story('测试2')def test_2(slef):print('22222')

 将多个用例写到一个组:

@allure.story('测试1')
@allure.title('用例1')
def test_1(self):print('11111')@allure.story('测试1')
def test_2(slef):allure.dynamic.title('用例2')print('22222')

4. 用例标题:@allure.title("用例1") or allure.dynamic.title('用例2') 两种方法都可以实现

@allure.title('用例1') //方法1
def test_1(self):print('11111')@allure.story('测试2')
def test_2(slef):allure.dynamic.title('用例2') //方法2print('22222')

 右边:

1. 测试用例严重级别:@allure.severity(allure.severity_level.BLOCKER) //BLOCKER(致命),CRITICAL(严重),NORMAL(一般),MINOR(提示),TRIVIAL(轻微),一般默认为NORMAL

@allure.severity(allure.severity_level.TRIVIAL)
@allure.story('测试3')
def test_3(slef):print('33333')

 2. 测试用例的描述:@allure.description("测试用例的描述")

@allure.description("测试用例的描述方法1")
@allure.title('测试4')
def test_4(slef):print('44444')@allure.title('测试5')
def test_5(slef):allure.dynamic.description("测试用例的描述方法2")print('55555')

3. 接口访问链接:@allure.link("接口链接")

4. BUG链接:@allure.issue("bug链接")

5. 测试用例链接:@allure.testcase("用例链接")

@allure.story('测试6')
@allure.link('https://www.baidu.com/0',name='接口链接')
@allure.issue('https://www.baidu.com/',name='bug链接')
@allure.testcase('https://www.baidu.com/',name='用例链接')
def test_6(slef):print('66666')

6. 测试用例的操作步骤:allure.step("第"+str(i)+"步"):

@allure.story('测试1')
def test_7(self):for i in range(0,10):with allure.step("第"+str(i)+"步"):pass

7. 测试附件:allure.attach(body=content,name="错误截图",attachment_type=allure.attachment_type.PNG) //一般用于错误截图(常用于web自动化测试)

@allure.story('测试1')
def test_8(self):# 附件上传需要使用二进制,可以是图片,可以是文本,可以是其它文件with open(r'D:\study\allure-2.25.0\allure-2.25.0\plugins\custom-logo-plugin\static\1.png',mode='rb') as f:content = f.read()allure.attach(body=content,name='错误截图',attachment_type=allure.attachment_type.PNG)

8. 文本内容的定制:一般应用于接口自动化

@allure.story('测试1')
def test_9(self):# 请求allure.attach('https://www.baidu.com/0',name='接口地址',attachment_type=allure.attachment_type.TEXT)allure.attach('接口参数,一般从yaml中获取',name='接口参数',attachment_type=allure.attachment_type.TEXT)allure.attach('请求方式:get/post',name='请求方式',attachment_type=allure.attachment_type.TEXT)allure.attach('请求头,一般从yaml中获取',name='请求头',attachment_type=allure.attachment_type.TEXT)# 响应allure.attach('响应文本,一般从yaml中获取', name='响应文本', attachment_type=allure.attachment_type.TEXT)allure.attach('执行结果:成功/失败', name='执行结果', attachment_type=allure.attachment_type.TEXT)

9. 数据驱动:

@allure.story('测试1')
@pytest.mark.parametrize('x', ['这是第1个测试值', "这是第2个测试值"])
def test_a(self,x):print(f'test_a中的X值为{x}')

 由于使用数据驱动,用例标题会展示参数数据化驱动中的所有参数,若不想要显示则需要修改allure配置

# 修改前
test_result.parameters.extend([Parameter(name=name, value=represent(value)) for name, value in params.items()if name not in current_param_names])# 修改后 (将列表内容去除即可)     
test_result.parameters.extend([])

5. allure局域网查看

局域网(内网):allure open ./reports

if __name__ == "__main__":pytest.main(['./test_study/test_allure.py'])os.system("allure generate ./temps -o ./reports --clean")os.system("allure open ./reports")

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/383319.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

grep 常用命令

这个--include选项,可以这样使用: grep -rn --include*.c --include*.h re . 可以指定多次, 如果真是上面的这种情况, 其实可以用 grep -rn --include*.[ch] re . 但是, 如果源文件中含有C源代码,上面的方法就不凑效了, 因为[]中只能放一个字符. grep -rn --include*.{cp…

c++中友元函数详解

友元 友元分为:友元函数和友元类 友元提供了一种突破封装的方式,有时提供了便利。但是友元会增加耦合度,破坏了封装,所以友元不宜多 用。 全局函数做友元函数 全局函数写到类中做声明 并且最前面写关键字 friend 友元函数可访问…

Linux时间函数札记

关于gmtime、gmtime_r、localtime、localtime_r 测试环境:vmware 7 Redhat5.5,系统时间使用UTC,时区为上海。 1、函数功能介绍 使用man gmtime或man localtime都可以的得到这几个函数的介绍。原型如下: struct tm *gmtime(const …

c++实现顺序表的相关操作

Myarray.h文件 #pragma once#include<iostream>using namespace std;class MyArray { public:MyArray();//默认构造 默认100容量MyArray(int capacity);MyArray(const MyArray& array);~MyArray();//尾插法void Push_Back(int val);//根据索引获取值int getData(int…

系统架构札记

什么是高内聚、低耦合&#xff1f; 起因&#xff1a;模块独立性指每个模块只完成系统要求的独立子功能&#xff0c;并且与其他模块的联系最少且接口简单&#xff0c;两个定性的度量标准――耦合性和内聚性。 耦合性也称块间联系。指软件系统结构中各模块间相互联系紧密程度的一…

c++中运算符重载(加号运算,左移运算,前置后置++运算符,赋值运算,关系运算,函数运算)

运算符重载注意 重载的运算符要易读内置的数据类型的表达式的运算符是不可以改变的不要重载&& 和 | | 运算符&#xff0c;[]和->运算符只能通过成员函数进行重载<<和>>只能通过全局函数配合友元函数进行重载 加号运算符重载 如果想让自定义数据类型 进…

linux fstab解读

fstab这个文件挺有用的。 从左到右&#xff1a; /dev/device mount-point type rules dump fsck 1. /dev/device: 不用说了吧&#xff1f;例如&#xff0c;/dev/hda1为M$-Win9x下的c:盘。 2. mount-point: 挂载点。例如&#xff0c;把/dev/hda1挂到/mnt/mywinc下。 3. type: ex…

c++实现字符串类的封装

MyString.h文件 #define _CRT_SECURE_NO_WARNINGS#pragma once#include<iostream>#include<string>using namespace std;class MyString{friend ostream & operator<<(ostream & cout, MyString & str);friend istream & operator>>(…

c++中的继承--1(引出,继承方式,继承的对象模型)

继承的引出 概念&#xff1a; 继承(inheritance)机制是面向对象程序设计使代码可以复用的最重要的手段&#xff0c;它允许程序员在保持原有类特 性的基础上进行扩展&#xff0c;增加功能&#xff0c;这样产生新的类&#xff0c;称派生类。继承呈现了面向对象程序设计的层次结构…

Makefile经典教程(掌握这些足够)

makefile很重要 什么是makefile&#xff1f;或许很多Winodws的程序员都不知道这个东西&#xff0c;因为那些Windows的IDE都为你做了这个工作&#xff0c;但我觉得要作一个好的和professional的程序员&#xff0c;makefile还是要懂。这就好像现在有这么多的HTML的编辑器&#xf…

c++中的继承--2(继承中的析构函数和构造函数,继承中同名成员,继承中静态成员)

继承中的构造函数和析构函数 继承中的构造和析构顺序 子类创建对象时&#xff0c;先调用父类的构造&#xff0c;然后调用自身构造析构顺序与构造顺序相反子类不会继承父类的构造函数和析构函数如果父类中没有合适默认构造&#xff0c;那么子类可以利用初始化列表的方式显示的…

Linux锁机制和线程安全

锁机制是多线程编程中最常用的同步机制&#xff0c;用来对多线程间共享的临界区进行保护。 1. 互斥锁&#xff1a;pthread_mutex&#xff0c;属于sleep-waiting类型的锁 pthread_mutex_t *mutex; int pthread_mutex_int(mutex, attr) //以动态方式创建互斥锁&#xff0c;参…

c++中的继承--3(多继承问题,菱形继承)

继承中的多继承 #include<iostream>using namespace std;class Base1 { public:Base1(){m_A 10;} public:int m_A;};class Base2 { public:Base2(){m_A 10;} public:int m_B;int m_A;};class Son :public Base1, public Base2 {public:int m_C;int m_D; };void test01…

c++中的多态---1(多态概念,静态联编和动态联编,多态原理解析,重载,重写,重定义的对比)

多态的基本概念 多态是面向对象设计语言数据抽象和继承之外的第三个基本特征多态性(polymorphism)提供接口与具体实现之间的另一层隔膜&#xff0c;从而将“what”和“how”分离开来&#xff0c;多态性改善了代码的可读和组织性&#xff0c;同时也使创建的程序具有可扩展性&am…

Ubuntu下各种服务搭建及操作技巧

Ubuntu下搭建TFTP 1、安装软件包 sudo apt-get install tftpd tftp xinetd 2、建立配置文件 在/etc/xinetd.d/下建立一个配置文件tftp sudo vi /etc/xinetd.d/tftp 内容如下 service tftp { socket_type dgram protocol udp wait yes user root …

c++多态--2(计算器,纯虚函数和抽象类)

为什么要用多态 早期方法不利于扩展开闭原则 开闭原则 对扩展开放 对修改关闭利用多态实现—利于后期扩展&#xff0c;结构性非常好&#xff0c;可读性高&#xff0c;效率稍微低&#xff0c;发生多态内部结构复杂 多态成立的条件 又继承 子类重写父类虚函数的函数&#xff1…

使用Automake和Autoconf生成Makefile

automake 所产生的 Makefile 除了可以做到程序的自动编译和链接 外&#xff0c;还可以用来生成各种文档&#xff08;如manual page、info文件&#xff09;&#xff0c;可以将源代码文件包装起来以供发布。所以程序源代码所存放的目录 结构最好符合GNU的标准惯例。下面以hello.…

c++中多态---3(虚析构和纯虚析构,向上类型转化和向下类型转化)

虚析构和纯虚析构 虚析构virtual ~类名(){}类内声明&#xff0c;类内实现解决问题&#xff1a;通过父类指针指向子类对象释放时候不干净的问题 纯虚析构 写法 virtual ~类名(){}0; 类内声明 类外实现 如果出现了纯虚析构函数&#xff0c;这个类也算是抽象类&#xff0c;不可…

嵌入式开发硬件知识札记

三态逻辑 1. 概念 三态指其输出既可以是一般二值逻辑电路&#xff0c;即正常的高电平&#xff08;逻辑1&#xff09;或低电平&#xff08;逻辑0&#xff09;&#xff0c;又可以保持特有的高阻抗状态。高阻态相当于隔断状态&#xff08;电阻很大&#xff0c;相当于开路&#xff…

《凡人修仙传》中打斗场景(c++多态实现)

我们 要实现打斗场景&#xff0c;第一&#xff0c;我们需要有打斗的双方&#xff0c;一个是英雄&#xff0c;一个是怪物&#xff0c;他们都有自己的属性&#xff0c;比如攻击&#xff0c;防御&#xff0c;血量。其次我们的英雄还会有武器。武器上有一些加成属性&#xff0c;可以…