首页 > 解决方案 > Allure 无法读取生成的 json 文件,并且附件未附加

问题描述

有这样一段代码:

import allure
from selenium.common.exceptions import TimeoutException
from SauceBasePage import *
from SauceProductsPage import *
from SauceCartPage import *

@allure.severity(allure.severity_level.NORMAL)
@allure.title('Removing')
def test_problem_user_remove_item(browse):
    user = StartPage(browse)
    with allure.step('Open start page'):
        user.start_page_open(browse)
    with allure.step('Input data'):
        user.problem_input()
    with allure.step('Login'):
        user.standard_login()
    user = ProductsPage(browse)
    with allure.step('Add product to cart'):
        user.add_product_to_cart()
    with allure.step('Remove'):
        try:
            user.remove_product()
            assert EC.visibility_of_element_located((By.ID, 'add-to-cart-sauce-labs-backpack'))
        except TimeoutException:
            allure.attach('Remove error', browse.get_screenshot_as_png(), attachment_type=allure.attachment_type.PNG)
            raise AssertionError('Removing failed')
    allure.dynamic.title('Remove successfull!')

代码按原样执行,但在执行命令之后:

allure generate

出现此消息: 在此处输入图像描述

消息的继续: 在此处输入图像描述

我该如何解决?

标签: python-3.xallure

解决方案


好吧,我发现错误。它在我的代码中。Шt 应该是这样的:

 allure.attach(browse.get_screenshot_as_png(), name="Remove fail" attachment_type=allure.attachment_type.PNG)

推荐阅读