我正在为使用 Geb 的站点编写一个小测试框架。作为我的报告功能的一部分,我希望能够在运行时指定reportsDir所在的位置。我不是开发人员,所以请原谅这个问题中的任何遗漏。
到目前为止我读到的所有内容都表明这只能通过项目的配置或构建适配器来设置。但是,Geb 的 Configuration 类有一个setReportsDir方法,我可以从浏览器对象访问它:
def currentConfig = pageBrowser.getConfig()
def reportLocation = "target/runtime_reports_dir"
def reportFile = new File(reportLocation)
reportFile.mkdirs()
File newTarget = new File(reportLocation)
currentConfig.setReportsDir(newTarget)
不幸的是,虽然这似乎改变了浏览器配置对象中的reportsDir,但实际输出仍然出现在我的配置定义的目录中。
这可能吗?我可以改写 GebReportingTest 中的setupReporting方法吗(我也没有发现任何建议如何做到这一点的东西)?
--- 编辑 1 ---
我试过了
class MyTest extends GebReportingTest {
def pageBrowser
def setup() {
this.pageBrowser = new Browser()
this.pageBrowser.config.reportsDir = new File( 'target/runtime_reports_dir' )
}
@Test
void runTestSet() {
setup()
this.pageBrowser....
}
}
在蒂姆的评论之后,但到目前为止我还没有感到高兴。调用 setup() 方法后,pageBrowser 的配置对象返回我在代码中定义的 reportsDir。但是,“report”命令的所有实例都将屏幕截图等存储在 GebConfig.groovy 中定义的目录中。