robot framework api使用allure

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

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值