1

I am using allure framework to generate reports for my pytest tests and behave (BDD) tests. In pytest the code is:

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)

However, I am unable to find a similar way in behave to attach the screenshots to my html report

  • 2
    Possible duplicate of [How to add a screenshot to allure report with python?](https://stackoverflow.com/questions/29929244/how-to-add-a-screenshot-to-allure-report-with-python) – Max Voitko Aug 22 '17 at 15:21

3 Answers3

2

You need install allure-pytest and then:

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
)
1

You can attach something to step with code like this:

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)
thistle
  • 414
  • 3
  • 6
  • I tried, it throws an error AttributeError: module 'allure' has no attribute 'attachment_type' – Vivek Bhardwaj Aug 22 '17 at 23:40
  • You have a pytest-allure-adaptor 1.xx Imported allure it is not form allure-python-commons package. Migrate to allure_pytest 2.xx and uninstall old adapter. – thistle Aug 23 '17 at 13:29
0
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)

Probably you dont have to use 'try', check the status here: https://github.com/allure-framework/allure-python/issues/431

Igor Z
  • 601
  • 6
  • 7