python - 如何使用 python 添加屏幕截图以吸引报告?

标签 python webdriver pytest allure

我有这个代码:

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


@pytest.yield_fixture(scope='session')
def driver():
    _driver = webdriver.PhantomJS()
    yield _driver
    _driver.quit()


def test_ya(driver):
    with allure.step('open ya.ru and take screenshot'):
        driver.get('http://ya.ru/')            
        allure.attach('screenshot', driver.get_screenshot_as_png(), type='png')

然后我尝试截屏并将其保存到诱惑报告中, 执行后我有:

>       with self._attachfile("%s-attachment.%s" % (uuid.uuid4(), attach_type.extension)) as f:
            if isinstance(body, text_type):
E           AttributeError: 'str' object has no attribute 'extension'

我该如何解决这个问题?

最佳答案

诱惑2

from allure_commons.types import AttachmentType

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

关于python - 如何使用 python 添加屏幕截图以吸引报告?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29929244/

相关文章:

python - 为什么当我先打开要写入的文件时,无法使用 Python 中的 File.open 读取任何内容?

python - 使用 OpenCV 自动调整一张纸的彩色照片的对比度和亮度

java - 如何验证是否选择了 WebElement

python - Pytest 和 Django 设置运行时更改

python - pytest-cov 不与 tox 一起使用

Python:类型化方法参数

python - 使用 iloc 和 bool 掩码设置数据帧(数据帧中多个不同索引(行)值的掩码)

webdriver - Java WebDriver 等待页面加载

java - 返回空指针异常 - Java Selenium Webdriver

python-3.6 - QApplication 实例/qtbot fixture 导致 travis-ci 中止和核心转储