I’m writing a little test framework for a site using Geb. As part of my reporting functionality, I’d like to be able to specify at runtime where the reportsDir lives. I’m no developer so please excuse any omissions in this question.
Everything I’ve read so far suggests that this can only be set via the project’s configuration or the build adaptor. However, Geb’s Configuration class has a setReportsDir method which I can access from my browser object:
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)
Unfortunately, although this appears to change the reportsDir in the browser’s config object, the actual output still appears in the directory defined by my configuration.
Is this possible? Could I override the setupReporting method in GebReportingTest instead (I’ve not found anything suggesting how this might be done either)?
— Edit 1 —
I’ve tried
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....
}
}
after Tim’s comments but I’ve had no joy so far. After invoking the setup() method, the pageBrowser’s config object returns the reportsDir I’ve defined in code. However, all instances of the ‘report’ command store screenshots etc in the directory defined in GebConfig.groovy.
Geb will look for GebConfig.groovy in the root of the classpath
You can set reportsDir in there
See: http://www.gebish.org/manual/0.6.2/configuration.html#reports_dir
Edit:
Have you tried: