【问题标题】:Pytest Selenium Allure report : Report multiple failures inside a same testPytest Selenium Allure 报告:报告同一测试中的多个失败
【发布时间】:2021-06-30 05:20:22
【问题描述】:

我想要实现的目标:如果我必须验证同一页面中的多个元素,那么我想在同一个测试下编写多个断言,而不是编写多个测试来打开浏览器并导航到为每个断言一次又一次地翻页。是否可行,我们如何实现?

我正在使用但不起作用的解决方案我正在使用魅力报告。当我在这两种情况下都使用 assert False 或 pytest.fail 时,我的魅力报告会捕获失败,但测试用例会停止,并且在该测试中未执行进一步的断言或代码行。当我使用 pytest_check 时,它无法通过测试,但失败不会在诱惑报告中捕获。它只是以绿色显示步骤,以红色显示测试。

【问题讨论】:

    标签: python selenium pytest allure


    【解决方案1】:

    如果你从allure.step内部做某事,块失败将被标记为红色或黄色(取决于失败原因)>标志

    with allure.step(description):
        do_something()
    

    【讨论】:

    • 这只有在我们执行 assert Falseallure.fail() 时才有效。但在这两种情况下,它都会停止执行并且不会继续。我希望报告软断言并在 python pytest 中标记测试步骤失败,诱惑。
    【解决方案2】:

    您可以使用自己的装饰器 (@soft_step) 而不是诱惑器 (@step)。

    def soft_step(step_title: str):
        def decorator(func):
            @wraps(func)
            def wrapper(*args, **kwargs):
                try:
                    with allure.step(step_title):
                        func(*args, **kwargs)
                except:
                    allure.attach(browser.driver.get_screenshot_as_png(), 
                    attachment_type=AttachmentType.PNG)
            return wrapper
    
        return decorator
    

    注意:报告中的测试用例不会失败。

    【讨论】:

      猜你喜欢
      • 2018-04-05
      • 1970-01-01
      • 2016-05-17
      • 1970-01-01
      • 2017-05-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多