reusing configuration for multiple urls

45 views
Skip to first unread message

Samuel Rossinovic

unread,
Jan 16, 2018, 10:14:55 PM1/16/18
to Geb User Mailing List
Hi. 
Trying to reuse geb stuff across multiple web apps (different urls). In particular, I'd like to reuse config in GebConfig.groovy.
My GebConfig currently contains:
* baseUrl
* misc configuration (waiting, clear cookies, reportsDir, etc)
* environments (per-browser), as-well as some utility methods for those envs.

Would be good if I was able to extract everything other than the baseUrl to a common config ancestor, and have separate projects, each with a config that only defines its URL, and inheriting the rest from the common one.

Appreciate some guidance on this...

Roman Tretyak

unread,
Jan 17, 2018, 3:48:01 AM1/17/18
to Geb User Mailing List
Why can't you just change the baseUrl for certain test/set of tests? Have a separate 'parent' test for each web app which will set the baseUrl. For example by setting browser.setBaseUrl(..) or by overriding createConf method (only for geb-spock I guess).

-Roman

среда, 17 января 2018 г., 5:14:55 UTC+2 пользователь Samuel Rossinovic написал:

Samuel Rossinovic

unread,
Jan 17, 2018, 6:33:37 PM1/17/18
to Geb User Mailing List
I could do that, but rather not, as it seems to me to be more a workaround than a solution. Creating a base class for specifications just to allow them to override a configuration value seems wrong, and I am concerned that it might come back to bite me later-on in the development (e.g if I'd actually want these specs to inherit behavior from existing base-specs, like common pre/post behaviour). I'd be happier confining specifications to deal w/test cases, and assign configuration to config files.

Marcin Erdmann

unread,
Jan 21, 2018, 9:31:26 AM1/21/18
to Geb User Mailing List
Hi Samuel,

One of the ways to achieve it would be to extend ConfigurationLoader class and use your new implementation in GebSpec.createConf() instead of the current one. In your new configuration loader class you will then need to override ConfigurationLoader#createConf(ConfigObject, GroovyClassLoader). Assuming you will have BaseGebConfig.groovy resource file with all configuration apart from the url and project specific GebConfig.groovy resource files the following should be sufficient:

    protected createConf(ConfigObject rawConfig, GroovyClassLoader classLoader) {
        def baseRawConfig = loadRawConfig(classLoader.getResource('BaseGebConfig.groovy'), classLoader)
        baseRawConfig.merge(rawConfig)
        new Configuration(baseRawConfig, properties, createBuildAdapter(classLoader), classLoader)
    }

--
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/9ecc26e9-558f-458c-9db5-5e7651f6ab4d%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages