Thursday, March 27, 2014

Geb Browser Automation Quick Start Windows

How to Stand Up a Geb Sample Application in Windows

This guide will show you step-by-step how to setup a simple Geb app to get started using the automated testing framework.  This guide focuses on using the Chrome browser for testing.  Please update chrome to the most recent version available because chromedriver only works with versions 12.0.712.0 and higher.

If you are trying to setup geb on Linux please use the following link instead:

Pull a copy of the Geb Sample App

 First, pull the Geb sample application from Github:


Ensure you have Chrome.exe installed in the expected location

OSExpected Location of Chrome executable 
Mac/Applications/Google\\ Chrome
Windows XP%HOMEPATH%\Local Settings\Application Data\Google\Chrome\Application\chrome.exe
Windows VistaC:\Users\%USERNAME%\AppData\Local\Google\Chrome\Application\chrome.exe

1 For Linux systems, the ChromeDriver expects /usr/bin/google-chrome to be a symlink to the actual Chrome binary. See also the section on overriding the Chrome binary location .

Download and Install Chrome Driver

Download the latest version of Chrome Driver:

As of 3/27/2014 the latest version for Windows is:  Download chromedriver 2.9 for Windows

For other platforms please use the list of all downloads here:

You will want to unzip the file for your respective OS).  I unzipped mine into the C:/ drive base directory.

Picture of the location and contents of the chromedriver folder
The chromedriver directory will contain only the chromedriver.exe executable

You will then either want to add the chromedriver location to your system path or as a VM argument.

Adding chromedriver to your system path

Windows 7:  Start -> Right-click "computer" -> Advanced system settings -> Environment Variables -> Select the PATH User variable -> Edit -> Add "C:\chromedriver_win32" or wherever you installed it to the end of your path value.

Setting the path as a VM argument

Add the running to your run configuration in your IDE:\chromedriver_win32

You may have to restart your computer for these changes to be recognized

Try restarting your PC if the chromedriver executable is not being found.

For additional info, you can review the ChromeDriver Documentation here: 

The "Need Help" section contains solutions for many common problems you may encounter.

For IntelliJ IDEA users only:

There is a bug where forked tests are enabled by default which causes an issue.  Please see the following blog post on how to resolve that issue:

Run the application

It's now time to try running the Geb sample application.  

Add the following VM argument:


Then run the command:

grails test-app

You should see something in the logs similar to the following if successful:

Starting ChromeDriver (v2.9.248315) on port 3826

Sample of geb app test run logs
Successful run of Geb test application

A separate instance of Chrome should start automatically with several actions such as users being added and deleted being performed.

Screen capture of Geb automated testing on Chrome
Chromedriver in action performing automated testing

Additional Resources

Related links
Geb Home Page
Geb Github
Book of Geb

Slideshare Presentation on Geb

Software Development Blogs - BlogCatalog Blog Directory

Tuesday, March 25, 2014

Run Forked Tests in Grails on IntelliJ IDEA

How to resolve issues with Running Forked Tests in Grails on IntelliJ IDEA

When trying to run test-app on a Grails project in Intellij you may see a error similar to the following:

| Error Error running forked test-app: Could not load grails build listener class
java.lang.RuntimeException: Could not load grails build listener class
    at org.codehaus.groovy.grails.cli.fork.ForkedGrailsProjectClassExecutor.createEventListener(ForkedGrailsProjectClassExecutor.groovy:102)
    at org.codehaus.groovy.grails.cli.fork.testing.ForkedGrailsTestRunner.createInstance(ForkedGrailsTestRunner.groovy:93)
    at org.codehaus.groovy.grails.cli.fork.ForkedGrailsProjectClassExecutor.initializeProjectInstance(ForkedGrailsProjectClassExecutor.groovy:85)
    at org.codehaus.groovy.grails.cli.fork.testing.ForkedGrailsTestRunner.main(ForkedGrailsTestRunner.groovy:75)
Caused by: java.lang.ClassNotFoundException: org.jetbrains.groovy.grails.rt.GrailsIdeaTestListener
    at Method)
    at java.lang.ClassLoader.loadClass(
    at groovy.lang.GroovyClassLoader.loadClass(
    at groovy.lang.GroovyClassLoader.loadClass(
    at groovy.lang.GroovyClassLoader.loadClass(
    ... 7 more
| Error Error running forked test-app: Could not load grails build listener class

Tests can execute in so-called forked mode. In this mode a separate JVM is started with an independent classpath from the Grails build system. 

If you want to run tests in forked mode from within IntelliJ IDEA you'll get an error:
Error running forked test-app: Could not load grails build listener class (Use --stacktrace to see the full trace)

To make run tests in forked mode work with IntelliJ IDEA we must add the grails-rt.jar file to the lib folder of the project directory.
In a basic Windows 7 install you will find the file in a location similar to:
C:\Program Files (x86)\JetBrains\IntelliJ IDEA 13.0.2\plugins\Grails\lib

How to find the grails-rt.jar file to fix forked tests in Intellij IDEA using Grails projects
Add grails-rt.jar file to run forked tests in Intellij IDEA for Grails projects

Now your Grails forked tests from within IntelliJ IDEA should run correctly. 
Add the option --debug-fork to the Run Configuration to the test to help debug.

Another option:  Disabled forked mode
Disable the forked mode for tests:
set grails.project.fork.test = false in grails-app/conf/BuildConfig.groovy

There is currently an open bug ticket for this issue:

Software Development Blogs - BlogCatalog Blog Directory