目录:导读
前言
1、Allure安装教程以及遇到的坑
安装过程:
1)安装 pytest
版本:pytest == 5.4.2
python
pip install pytest==5.4.2 --index-url https://pypi.douban.com/simple
2)安装 allure-pytest
版本: allure-pytest == 2.8.16
python
pip install allure-pytest==2.8.16 --index-url https://pypi.douban.com/simple
安装完成后,打开一个pytest脚本进行验证一下,如果报错:AttributeError:module 'allure' has no attribute...
这样的报错是之前安装的 pytest-allure-adaptor 这个插件发生了冲突,这两个插件是不能共存的,去卸掉 pytest-allure-adaptor 这个就行了 ( pip uninstall pytest-allure-adaptor)
3)安装 allure
版本:allure == 2.13.3
这是一个命令行的插件,需要去下载:
推荐下载地址之一: https://github.com/allure-framework/allure2/releases
下载后解压到自己的文件夹中;
配置环境变量
将 allure.bat 文件(图一)所在路径添加到系统的环境变量path中(图二)


4)进入cmd中执行allure命令
如果结果是下图,恭喜你搞定了:

如果是下图,恭喜你环境出问题了

因为allure是基于java环境运行的,提示的意思是JAVA_HOME的地址出问题了 ,找原因很麻烦,解决办法很简单 ,尽管你去执行java、javac、java -version都是正常的,但是执行allure就是报错的。
解决办法: 就是把java的JAVA_HOME的这个地址环境变量重新填写一下,注意最后不要有空格。如下图

就这个东西,然后重新打开一个cmd,再次执行allure命令。都正常了
2、Allure 自动化测试报告使用详解
allure生成的报告和其他五花八门的报告对比了一下,它的可读性是最好、最直观的。
1)Allure相关的内容

总共主要的就以上这些,常用的大概有一半吧 。
2)对于这其中常用的做一些使用实例
代码结构:

登录是一个前置操作 ,拿出来后单独存放,loging.py文件内容:
python
# __*__coding:utf-8 __*__
import allure
@allure.step("操作步骤: 登录")
def longin():
'''登录操作'''
print("这个是登录的接口")
conftest.py这个文件主要放一些公共的内容
python
# __*__coding:utf-8 __*__
import pytest
from common_contion.loging import longin
@pytest.fixture(scope="session")
def login_fixture():
longin()
print("这个是前置操作:登录")
case----test_case.py文件主要存放一些测试用例,内容如下:
python
# __*__coding:utf-8 __*__
import pytest
import allure
from common_contion.dome_Interface import *
@allure.severity("blocker")
@allure.epic("项目名称: 会所资源管理系统")
@allure.issue("http://149.335.82.12:8080/zentao/bug-view-1.html") # 禅道bug地址
@allure.testcase("http://149.335.82.12:8080/zentao/testcase-view-5-1.html") # 禅道用例连接地址
@allure.feature("房间管理模块")
class Testdome1(object):
def test_dome_1(self,login_fixture):
'''用例一的用例描述: 我是第一个用例,我只有一个步骤'''
print("第一个测试用例")
jieko_dome_1()
def test_dome_2(self,login_fixture):
'''用例二的用例描述: 我是第二个用例,我只有一个步骤'''
print("第二个测试用例")
jieko_dome_2()
@allure.severity("critical")
@allure.epic("项目名称: 会所资源管理系统")
@allure.feature("资源管理模块")
@allure.story("用例的标题: 对会所资源进行增、删、改、查")
@allure.issue("http://149.335.82.12:8080/zentao/bug-view-1.html") # 禅道bug地址
@allure.testcase("http://149.335.82.12:8080/zentao/testcase-view-5-1.html") # 禅道用例连接地址
class Testdome3(object):
def test_dome_3(self,login_fixture):
'''用例三的用例描述: 我是第三个用例,我是有多个步骤;'''
print("第三个测试用例")
f = jieko_dome_3()
f.jieko_dome_3_1()
f.jieko_dome_3_2()
f.jieko_dome_3_3()
f.jieko_dome_3_4()
common_contion----dome_Interface.py文件主要存放用例相关的接口内容:
python
# __*__coding:utf-8 __*__
import allure
def jieko_dome_1():
'''用例描述: 用例一的接口'''
print("这个是第一个用例对应的接口")
def jieko_dome_2():
'''用例描述: 用例二的接口'''
print("这个是第二个用例对应的接口")
@allure.feature("资源管理模块")
class jieko_dome_3(object):
'''这个是一个模块的测试'''
@allure.step("操作步骤: 新增资源个人信息")
def jieko_dome_3_1(self):
'''用例描述: 用例三的新增内容接口'''
print("这个是第三个用例对应的接口一")
@allure.step("操作步骤: 查询资源在线信息")
def jieko_dome_3_2(self):
'''用例描述: 用例三的查询内容接口'''
print("这个是第三个用例对应的接口二")
@allure.step("操作步骤: 修改资源身份信息")
def jieko_dome_3_3(self):
'''用例描述: 用例三的编辑内容接口'''
print("这个是第三个用例对应的接口三")
@allure.step("操作步骤: 删除资源全部信息")
def jieko_dome_3_4(self):
'''用例描述: 用例三的删除内容接口'''
print("这个是第三个用例对应的接口四")
3)执行测试用例:
命令行模式执行用例
python
pytest --alluredir ./reopore/allure_row_1
执行结果:

会在工程中生成一个 /reopore/allure_row_1的文件,如图:

python
dome>allure serve reopore/allure_row_1
执行命令后将收集的数据加载到allure报告中,执行结果:

会自动使用默认浏览器打开报告
报告样式展示如下:



以上就是allure的各种装饰器加载后展示的报告的样式了。
|-------------------------------------|
| 下面是我整理的2023年最全的软件测试工程师学习知识架构体系图 |
一、Python编程入门到精通

二、接口自动化项目实战

三、Web自动化项目实战

四、App自动化项目实战

五、一线大厂简历

六、测试开发DevOps体系

七、常用自动化测试工具

八、JMeter性能测试

九、总结(尾部小惊喜)
只有拥有激情和毅力,才能逆袭人生,让自己的人生变得更加精彩。不要停下脚步,勇往直前,你一定能够实现自己的梦想!
人生的巅峰不是等待你去征服它,而是需要你去攀登它。坚定信念,迈出脚步,你就能够超越自我,收获无限的美好与荣耀!
困难是前行路上的催化剂,失败是成功的前奏曲。不要畏惧挑战,勇往直前,只有经历磨砺,才能成就辉煌的人生舞台!