文章目录
1. Allure 简单介绍
Allure是一个美化报告的工具。支持pytest, robot framework和junit等多种测试框架。
2. windows 安装allure
- gitlab 下载解压
- 进入bin目录, 点击allure.bat运行批处理文件
- 将bin目录添加到系统环境变量中
- 打开cmd, 输入allure --help查看是否安装成功
3. robot framework中使用allure
- 使用pip install allure-robotframework -i https://mirrors.aliyun.com/pypi/simple
3.1. robot framework 中两种方法使用allure-robotframework
- 运行robot文件时添加listener参数
- 通过RobotSettings添加listener参数
3.2. 运行robot文件时添加参数
- 默认路径: robot --listener allure_robotframework test.robot
- 保存到report路径: robot --listener allure_robotframework;report test.robot
3.3. RobotSettings配置listener参数
先看看官网的例子, 会默认在本地路径生成三个文件
# 官网: https://robot-framework.readthedocs.io/en/latest/autodoc/robot.running.html
# 默认会在当前目录生成三个文件: output, log和report
from robot.api import TestSuite
from robot.api import ResultWriter
suite = TestSuite('Activate Skynet')
suite.resource.imports.library('OperatingSystem')
test = suite.tests.create('Should Activate Skynet', tags=['smoke'])
test.keywords.create('Set Environment Variable', args=[
'SKYNET', 'activated'], type='setup')
test.keywords.create('Environment Variable Should Be Set', args=['SKYNET'])
result = suite.run(critical='smoke', output='skynet.xml')
# Report and xUnit files can be generated based on the result object.
ResultWriter(result).write_results(report='skynet.html', log='skynet-log.html')
3.3.1 RobotSettings配置options
3.3.1.1 增加option字典, 添加listener参数
- 配置allure report路径: “listener”: “allure_robotframework;{}”.format(’/xxx/xxx’)
- 默认allure路径: “listener”: “allure_robotframework”
from robot.conf import RobotSettings
path = "allure-reports"
options = {
"listener": "allure_robotframework;{}".format(path)
}
settings = RobotSettings(options)
suite.configure(**settings.suite_config)
3.3.1.2 suite.run()中增加settings参数
完整代码如下:
from robot.api import TestSuite
from robot.api import ResultWriter
from robot.conf import RobotSettings
suite = TestSuite('Activate Skynet')
suite.resource.imports.library('OperatingSystem')
test = suite.tests.create('Should Activate Skynet', tags=['smoke'])
test.keywords.create('Set Environment Variable', args=[
'SKYNET', 'activated'], type='setup')
test.keywords.create('Environment Variable Should Be Set', args=['SKYNET'])
path = "allure-reports"
options = {
"listener": "allure_robotframework;{}".format(path)
}
settings = RobotSettings(options)
suite.configure(**settings.suite_config)
result = suite.run(settings, critical='smoke', output='skynet.xml')
# Report and xUnit files can be generated based on the result object.
ResultWriter(result).write_results(report='skynet.html', log='skynet-log.html')
3.3.2 使用allure serve查看报告
- 打开cmd
- allure serve .\allure-reports\
4. 回顾
- 第一步: windows安装allure
- 第二步: pip install allure-robotframework -i https://mirrors.aliyun.com/pypi/simple
- 第三步: 两种方法在robot中添加listener: allure_robotframework
allure其他使用技巧请参见官网和allure --help