书籍来源:房荔枝 梁丽丽《pytest框架与自动化测试应用》
一边学习一边整理老师的课程内容及实验笔记,并与大家分享,侵权即删,谢谢支持!
附上汇总贴:pytest框架进阶自学系列 | 汇总_热爱编程的通信人的博客-CSDN博客
要生成第一份报告,只需执行以下几个简单的步骤:
(1)下载并安装所需的Allure命令行应用程序(客户端)。
(2)查找要生成报告的测试执行数据。
(3)生成在线报告。
Allure在Windows系统下安装
官网提供的安装方式有点复杂,下面提供另一种安装方式。
在官网进入Download页面,自动跳转到GitHub上,下载安装包,如图6-9所示的标注。
图6-9 Allure下载安装的具体位置
将下载的文件夹及其内容存放到一个目录下,配置系统环境变量:在PATH路径中加入文件夹下的bin目录,如图6-10所示。
客户端安装完成后,使用下面命令安装与pytest配合的客户端:
这将安装allure-pytest和allure-python-commons程序包,以生成与Allure 2兼容的报告数据。如果安装了用于第一代Allure报告的早期版本,则首先需要将其卸载,这一点很重要。
验证安装完成,输入allure--version会显示版本信息:
图6-10 Allure配置系统环境变量
Allure在Linux环境下安装
Linux对于基于Debian的存储库,提供了PPA,命令如下:
如果使用的是CentOS系统,可以先安装Node.js,再使用npm进行安装,如图6-11所示。
执行Allure需要Java 1.8及以上版本。如果没有安装,则应按下述步骤安装。
图6-11 Linux下安装Allure客户端
yum -y list java*命令可以查看有哪些版本可供安装。选择一个正确的版本进行安装,如图6-12所示。
图6-12 Linux下安装所需的Java 1.8
验证Allure是否安装成功,输入allure --version,结果如图6-13所示,则表明安装成功。
图6-13 Linux下验证Allure是否安装成功
Allure在Mac OS系统下安装
对于Mac OS系统,可通过Homebrew进行自动安装,命令如下:
安装前确认已经安装homebrew。
如果没安装,则需要把下面命令粘贴到终端执行安装,在中国执行的方式如下所示:
之后会显示具体的安装步骤,如图6-14所示。
图6-14 Mac系统下使用brew安装
Allure的简单用法
收集结果
要使Allure侦听器能够在测试执行过程中收集结果,只需添加--alluredir选项并提供路径便可以存储结果。示例代码如下:
查看报告
要在测试完成后查看报告,需要使用Allure命令行实用程序从结果生成报告,命令如下:
此命令将在默认浏览器中显示所生成的报告。
Allure的帮助说明
通过帮助查看具体的用法。
结果及常用参数的解释,执行结果如下:
PS D:\SynologyDrive\CodeLearning\WIN\pytest-book> allure --help
Usage: allure [options] [command] [command options]
Options:
--help
Print commandline help.
-q, --quiet
Switch on the quiet mode.
Default: false
-v, --verbose
Switch on the verbose mode.
Default: false
--version
Print commandline version.
Default: false
Commands:
generate Generate the report
Usage: generate [options] The directories with allure results
Options:
-c, --clean
Clean Allure report directory before generating a new one.
Default: false
--config
Allure commandline config path. If specified overrides values from
--profile and --configDirectory.
--configDirectory
Allure commandline configurations directory. By default uses
ALLURE_HOME directory.
--profile
Allure commandline configuration profile.
-o, --report-dir, --output
The directory to generate Allure report into.
Default: allure-report
serve Serve the report
Usage: serve [options] The directories with allure results
Options:
--config
Allure commandline config path. If specified overrides values from
--profile and --configDirectory.
--configDirectory
Allure commandline configurations directory. By default uses
ALLURE_HOME directory.
-h, --host
This host will be used to start web server for the report.
-p, --port
This port will be used to start web server for the report.
Default: 0
--profile
Allure commandline configuration profile.
open Open generated report
Usage: open [options] The report directory
Options:
-h, --host
This host will be used to start web server for the report.
-p, --port
This port will be used to start web server for the report.
Default: 0
plugin Generate the report
Usage: plugin [options]
Options:
--config
Allure commandline config path. If specified overrides values from
--profile and --configDirectory.
--configDirectory
Allure commandline configurations directory. By default uses
ALLURE_HOME directory.
--profile
Allure commandline configuration profile.
PS D:\SynologyDrive\CodeLearning\WIN\pytest-book>
好文阅读
发表评论