【问题标题】:More information about successful tests?有关成功测试的更多信息?
【发布时间】:2021-11-09 08:04:54
【问题描述】:

我如何提供有关通过测试的其他信息?

console.log 不起作用,因为输出被覆盖,因为工具记录了它自己的有关测试的信息。 (也许这是一个错误?)最终,除非测试失败,否则我们不能依赖任何输出使其进入最终屏幕。理想情况下,我想将一个对象(可能还有屏幕截图)推送到旨在收集有关测试信息的东西上,然后将其与测试相关联并通过测试的输出进行访问。

构建自定义对象不起作用,因为 playwright 具有内部功能,例如重试测试。

这是一个典型场景:在访问网站时,可能会创建一条记录(工作订单 ID 或采购订单编号,以及在此过程中可能遇到的各种其他信息)。

理想情况下,我正在寻找一些对象,例如:

test.addInfo( someObject )

也许在测试结束时,这会被丢弃,或者可供报告工具使用。

【问题讨论】:

    标签: playwright


    【解决方案1】:

    这是开箱即用的。见https://playwright.dev/docs/api/class-testinfo#test-info-annotations

    有一个可选的第二个参数专门用于此。记者必须处理这个问题(json 可以工作,但 list、dot 等不会)。

    test("Some test", async ({ page }, testInfo) => {
    //                                 ^ add this object
    
    // Add arbitrary infomation like this:
       let someObject = ({ additionalTestInformation: "here" })
       testInfo.annotations.push({type:"info", description: someObject });
    
    // Add screenshots or other files as well:
       testInfo.attachments.push({ name: "screenshot", path, contentType: "image/png"}) 
    });
    

    【讨论】:

      猜你喜欢
      • 2021-12-03
      • 1970-01-01
      • 1970-01-01
      • 2010-11-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多