问题背景
在使用Allure生成测试报告的过程中,Allure报告的首页 ENVIRONMENT 部分会显示"There are no environment variables",而我们经常需要在报告中展示测试环境的相关信息,如操作系统版本、测试框架版本、浏览器类型等。这些信息对于理解测试结果的上下文非常重要。
解决方案
方法1:使用environment.properties文件
- 在项目根目录,创建一个 environment.properties 文件,并在其中定义所需的环境变量。例如:
systemVersion=win10
pythonVersion=3.10.0
allureVersion=2.14.0
baseUrl=http://xxx.com
projectName=autotest
author=blues.C
blog=https://blog.csdn.net/weixin_48321392?type=blog
- 复制environment.properties环境变量文件
copy environment.properties .\your_report_path
- 生成报告
allure serve .\your_report_path
方法2:environment.xml
<environment>
<property>
<name>systemVersion</name>
<value>win10</value>
</property>
<property>
<name>pythonVersion</name>
<value>3.10.0</value>
</property>
<property>
<name>allureVersion</name>
<value>2.14.0</value>
</property>
<property>
<name>baseUrl</name>
<value>http://xxx.com</value>
</property>
<property>
<name>projectName</name>
<value>autotest</value>
</property>
<property>
<name>author</name>
<value>blues.C</value>
</property>
<property>
<name>blog</name>
<value>https://blog.csdn.net/weixin_48321392?type=blog</value>
</property>
</environment>