Talking testing, agility and automation... and anything else.

Aug 14

Running Geb Tests In Parallel

parallel linesBecause UI tests are inherently slow, running them in parallel–that is, running multiple tests, in multiple browsers concurrently–is all but a necessity.

Luckily, it’s hilariously easy to run Geb tests in parallel, using Maven… all you need do is add the following code to you Maven pom.xml:

And then run your tests via Maven. Eg. mvn test -Dgeb.env=chrome . You can try it for yourself by running my geb-example on GitHub.

This code will spread your tests between up to 4 threads/forks and run tests at the method (test) level. You can also swap out “methods” for “classes” if you’re prefer to run at the spec (class) level. Either way, you can dramatically speed up your automated tests with a few lines of code…

You did think about running tests in parallel when writing your tests… didn’t you?

Apr 14

Running Test Suites In Geb

sweetsMaybe you’re looking to run a number of tests against a new build, or perhaps you just can’t wait for the overnight Jenkins tests to run. Whatever the reason, running multiple Geb tests/specs from your IDE is a snap, thanks to JUnit’s sweet suite functionality.

To the code!

We use two annotations: @RunWith, to specify the runner to run the suite, and @Suite.SuiteClasses, that specifies an array of tests/specs we’d like to run. Just add any specs you’d like run in the array, with .class appended and separated with a comma.

Lastly, we have our actual class, which is left empty. All you need do is run the suite and all your specified tests will run.

I’ve added this code to my Geb examples project on GitHub, so you can play along at home!

Mar 14

Screencast: Creating Your First Test In Geb

In this screencast, I walk you through writing your first test using Geb and Spock. We’ll create a page object and a spec (test), and then run our new test on multiple browsers.

If you’re just getting started, you might want to take a peek at my Geb Quick Start and Project Overview screencasts.

Mar 14

Screencast: Geb Automation Quick Start

I created a screencast that demonstrates how to quickly get up and running with Geb. This demo assumes you have installed a Java JDK, IntelliJ CE and Safari, and we’ll make use of my geb-example project, available on GitHub.

And once you’re up and running, have a look at my Project Overview screencast…

Feb 14

Customize Page Navigation By Overriding Geb’s getPageUrl()

gebGeb’s page object pattern offers the ability to set a url for a page, that allows you to navigate directly to a page. The url is used when calling the to() method (eg. to myPage).

An application I’m working on includes dynamic elements in its urls; the urls contain a session token, and can include a return page, and/or various content IDs. This makes it essentially impossible to navigate directly to the page. And unless you’re testing app navigation, it’s better to navigate directly. It keeps your code clean and helps mitigate brittleness.

The solution I’ve come up with is to parse the current url and use it to navigate directly to my pages. To do this, I needed to override Geb’s getPageUrl() (thanks to the Geb user group on this!).


In my example above, we override Geb’s getPageUrl with our own getPageUrl, added to a BasePage, that we’ll extend in our page object. In this new getPageUrl, we want to replace the page name in the url (eg. http://localhost/html#/PAGENAME/…). To do this we grab the current url and just replace the current page name with the target page. All the other elements in the url should be correct.

Now we also need to make sure normal pages continue to operate, so we first test to see if pageName property exists in the page. If not, we execute Geb’s normal url code. To get the target pageName, we add it as a static property to the page (instead of url), named pageName. The code would looke something like this:


Now we can simply call to MyPage as you would with a page with a normal url. Not too shabby!