How to add a screenshot to allure report with python?

后端 未结 3 1763
悲&欢浪女
悲&欢浪女 2020-12-16 23:58

I have this code:

# coding: utf-8
from selenium import webdriver
import pytest
import allure


@pytest.yield_fixture(scope=\'session\')
def driver():
    _dr         


        
相关标签:
3条回答
  • 2020-12-17 00:42

    in your conftest.py add the following, make sure you already have a driver fixture as well:

    codeblock

    0 讨论(0)
  • 2020-12-17 00:56

    Instead of setting the type as a string png, you need to use allure module attachment type constant, which is an Enum with extension attribute defined:

    from allure.constants import AttachmentType
    
    allure.attach('screenshot', driver.get_screenshot_as_png(), type=AttachmentType.PNG)
    
    0 讨论(0)
  • 2020-12-17 00:59

    For allure 2

    from allure_commons.types import AttachmentType
    
    allure.attach(driver.get_screenshot_as_png(), name="Screenshot", attachment_type=AttachmentType.PNG)
    
    0 讨论(0)
提交回复
热议问题