在您的情况下,您可以使用 Galen 生成 HTML 报告,就像使用它运行测试时通常所做的那样。尽管您必须管理 GalenTestInfo 对象的创建。
以下是 HTML 报告生成的工作原理。想象一下,您在某处定义了 obtainAllTests 方法,该方法返回所有已执行测试的列表。
List<GalenTestInfo> tests = obtainAllTests();
new HtmlReportBuilder().build(tests, "target/galen-html-reports");
您可以在代码中的某个位置创建GalenTestInfo 并将其添加到某个集合中:
GalenTestInfo testInfo = GalenTestInfo.fromString("Here goes the name of your test");
完成布局检查并获得LayoutReport 对象后,您可以将此报告添加到测试报告中。以下是你可以做到的:
LayoutReport layoutReport = Galen.checkLayout(driver,
specPath, includedTags, null,
new Properties(), null);
testInfo.getReport().layout(layoutReport, "A title for your layout check");
您可以在此项目https://github.com/galenframework/galen-sample-java-tests 中找到更多见解。它为 Java + TestNG + Maven 中的 Galen 测试提供了基本设置。其中的报告收集在一个单独的GalenReportsContainer 中。在GalenReportingListener 中还实现了一个报告器,它从GalenReportsContainer 获取所有这些测试并生成 HTML 报告。