GebConfig.groovy seems to be parsed for each and every test class -- why?

172 views
Skip to first unread message

steve....@synergistcomputing.com

unread,
Jun 2, 2017, 7:48:59 AM6/2/17
to Geb User Mailing List
Hello.  I notice that each test class results in a re-loading of my GebConfig.groovy configuration.  We have multiple environments, and one of them (called "local") has some code that looks for the user's profile.  When it finds the profile, it prints "Using ${profile} profile" and then creates a new FirefoxDriver(profile) in the driver = {} closure.  I am seeing this output once before every test class runs.  Should this be happening each and every time?

Thanks,
Steve

Marcin Erdmann

unread,
Jun 4, 2017, 12:52:12 PM6/4/17
to Geb User Mailing List
Hi Steve,

Yes, the behaviour you're describing is as expected. This is due to the fact that there is an instance of geb.Browser created before the first test in each test class (e.g. for Spock integration https://github.com/geb/geb/blob/d25f58566f8da2bf6397f43dfa5672547100f09b/module/geb-spock/src/main/groovy/geb/spock/GebSpec.groovy#L43). Browser needs an instance of geb.Configuration which is loaded using geb.ConfigurationLoader (https://github.com/geb/geb/blob/d25f58566f8da2bf6397f43dfa5672547100f09b/module/geb-spock/src/main/groovy/geb/spock/GebSpec.groovy#L34) which executes the config script.

If you do not wish to execute the config script once for each test class then you could for example create a base specification, load the configuration into a static field of that base specification and override GebSpec.createConf() method (https://github.com/geb/geb/blob/d25f58566f8da2bf6397f43dfa5672547100f09b/module/geb-spock/src/main/groovy/geb/spock/GebSpec.groovy#L33) to return that static field.

Hope that helps,
Marcin

--
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/91a1e543-972f-4a6e-b44a-fb612a2aa506%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages