2

我正在为使用 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 中定义的目录中。

4

1 回答 1

1

Geb 将在类路径的根目录中查找 GebConfig.groovy

你可以在那里设置reportsDir

见: http ://www.gebish.org/manual/0.6.2/configuration.html#reports_dir

编辑:

你有没有尝试过:

class MyTest extends GebReportingTest {
  void setUp() {
    browser.config.reportsDir = new File( 'target/runtime_reports_dir' )
  }

  @Test
  void runTestSet() {
    // Do testing
  }
}
于 2013-01-23T12:16:32.793 回答