2017-08-22 4 views
1

J'utilise allure framework pour générer des rapports pour mes tests de pytest et mes tests de comportement (BDD). En pytest le code est:Comment attacher des captures d'écran au rapport html d'allure-sehave? Pour pytest il fonctionne bien mais «se comporte», aucune pièce jointe n'est ajoutée

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) 

Cependant, je ne peux pas trouver un moyen similaire se comporte pour fixer les captures d'écran à mon rapport html

+2

double possible de [Comment un dd une capture d'écran pour attirer le rapport avec python?] (https://stackoverflow.com/questions/29929244/how-to-add-a-screenshot-to-allure-report-with-python) –

Répondre

1

Vous pouvez attacher quelque chose à l'étape avec le code comme ceci:

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) 
+0

J'ai essayé, il jette un erreur AttributeError: le module 'allure' n'a pas d'attribut 'attachment_type' –

+0

Vous avez un adaptateur pytest-allure 1.xx Allure importée ce n'est pas un paquet allure-python-commons. Migrez vers allure_pytest 2.xx et désinstallez l'ancien adaptateur. – thistle

0

Vous devez installer allure-pytest puis:

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 
)