Test configuration

41 views
Skip to first unread message

Samuel Rossinovic

unread,
Oct 13, 2017, 12:45:21 AM10/13/17
to Geb User Mailing List
Hi.
I'm looking for the recommended approach to add some test configuration. This would be arbitrary configuration (not geb's).
  1. Is GebConfig.groovy a good place for such configuration? Or am I expected to roll my own config resource?
  2. I noticed the following:
    1. browser.config.properties: provides System properties (would allow providing config from the command line, but not from file)
    2. browser.config.rawConfig: provides access to GebConfig 
    3. browser.config.rawConfig.properties: provides access to a properties closure in GebConfig
      
      Is rawConfig/properties documented parts of Geb's config API? If so, where can I read more about it?
  3. Is there a a way to have configuration properties such that it would have a default value (e.g. in GebConfig's top-level scope), a potential per-env override (under environments.foo) , and will also be overridable from command line?
Thanks,

Marcin Erdmann

unread,
Oct 14, 2017, 6:28:19 AM10/14/17
to Geb User Mailing List
There is nothing stopping you from using GebConfig.groovy for any arbitrary configuration but I personally wouldn't as I find it not a clean solution - you'd be mixing concerns. I wouldn't do it especially as it's relatively easy to roll your own config using the same mechanism Geb is using which is available in core Groovy, namely groovy.util.ConfigSlurper which has support for environment specific configuration. 

Rolling your own mechanism would also make it possible for you to have the behaviour you're asking in 3. You could create the following method at the top of your config script:

def propertyOrValue(String propertyName, value) {
    System.getProperty(propertyName) ?: value
}

And then you can use it like:

foo {
    bar = propertyOrValue('foo.bar', 'buzz')
}

environments {
    superDuper {
        foo {
            bar = propertyOrValue('foo.bar', 'bizz')
        }
    }
}

If you want to make the propertyOrValue() method reusable because you envisage having multiple configuration scripts then you could create a base script class (extends groovy.lang.Script), use groovy.lang.GroovyShell.parse() together with a custom compiler configuration (as shown by Mr. Haki at http://mrhaki.blogspot.co.uk/2011/11/groovy-goodness-create-our-own-script.html) to compile and initiate your config script with a custom base class and then pass it to ConfigSlurper.parse(Script).

--
You received this message because you are subscribed to the Google Groups "Geb User Mailing List" group.
To unsubscribe from this group and stop receiving emails from it, send an email to geb-user+unsubscribe@googlegroups.com.
To post to this group, send email to geb-...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/geb-user/0abfdf84-efaf-4ce7-9f35-2a6dbbc1bcbe%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages