Our team has been looking at making our functional tests better by improving the way in which we use Geb.
In this post, I want so summarize some useful configuration parameters for working with Grails, Geb and IntelliJ idea.
Specify a specific browser version.
To avoid having to rewrite all your tests whenever a new firefox version is released, you can specify a separate firefox bin file. We use 6.0.2 downloaded from http://download.mozilla.org/?product=firefox-6.0.2&os=linux&lang=en-US
After unzipping this file in a location in your machine, you can then tell Geb to run tests using this file by pointing to the firefox bin file.
Chrome driver has a similar mechanism.
Specify a profile in your testing
If you want to use a firefox profile ( that included Firebug, for example ), you can set this by first calling
Then, you can specify the profile being used via
Specify a baseUrl for JUnit tests
When running Geb tests as unit tests via IntelliJ idea, you can tell Geb the base url by setting the following environment variable:
To use this, just run your grails app with grails test run-app
Make IntelliJ read your geb configuration file
In order for IntelliJ to load your configuration files, you need to add it as a single module entry library.
- Add your Geb configuration file to your project. We put ours in the /test/functional directory.
- Add this file to your IntelliJ project dependencies via Project Structure -> Modules -> Dependencies
- Add a new ‘Single Module Entry Library’
- Select your functional directory. Save.
Now all your tests will be able to use the configuration file you have specified.
Alternatively, you can manually edit your project’s .iml file and add the following to the <component> element:
<orderEntry type="module-library" scope="TEST"> <library> <CLASSES> <root url="file://$MODULE_DIR$/test/functional" /> </CLASSES> <JAVADOC /> <SOURCES /> </library> </orderEntry>
( Based on a mailing list posting by Antony Jones / @antony. Credit to most of this is to Donovan Frew and Michael Stogowski ).