【问题标题】:How to attach screenshots to the allure-behave html report? For pytest it runs fine but 'behave' , no attachment gets added如何将屏幕截图附加到 allure-behave html 报告?对于 pytest,它运行良好,但 'behave' 没有添加附件
【发布时间】:2017-08-22 05:53:31
【问题描述】:

我正在使用allure framework 为我的 pytest 测试和行为 (BDD) 测试生成报告。在 pytest 中的代码是:

import allure
from allure.constants import AttachmentType

#use the below statement to attach the screenshot
allure.attach('screenshot', self.driver.get_screenshot_as_png(), type=AttachmentType.PNG)

但是,我无法找到类似的方式将屏幕截图附加到我的 html 报告中

【问题讨论】:

标签: pytest allure python-behave


【解决方案1】:

你需要安装allure-pytest 然后:

from allure_commons._allure import attach
from allure_commons.types import AttachmentType


attach(
    self.driver.get_screenshot_as_png(), 
    name="Screenshot", 
    attachment_type=AttachmentType.PNG
)

【讨论】:

    【解决方案2】:

    您可以使用如下代码附加一些内容:

    import allure
    from behave import given
    
    @given(u'passed step')
    def step_impl(*args, **kwargs):
        allure.attach(driver.get_screenshot_as_png(), name='screenshot', attachment_type=allure.attachment_type.PNG)
    

    【讨论】:

    • 我试过了,报错AttributeError: module 'allure' has no attribute 'attachment_type'
    • 你有一个 pytest-allure-adaptor 1.xx 导入的 allure 它不是来自 allure-python-commons 包。迁移到 allure_pytest 2.xx 并卸载旧适配器。
    【解决方案3】:
    from behave import *
    
    from allure_commons._allure import attach
    from allure_commons.types import AttachmentType
    
    @Then(u'passed step')
    def step_impl(*args, **kwargs):
        driver.save_screenshot('screenshot.png')
    
        try:
          allure.attach('screenshot.png', name='screenshot', attachment_type=allure.attachment_type.PNG)
    except Exception as e:
        print(e)
    

    可能您不必使用“尝试”,请在此处查看状态: https://github.com/allure-framework/allure-python/issues/431

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-08-16
      • 1970-01-01
      • 1970-01-01
      • 2020-12-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-10-15
      相关资源
      最近更新 更多