Geb Gems: Running Geb Spock tests with Maven

Geb is framework which makes it easy to create functional tests for your application. Since you can use Groovy, Spock and the elegance of the JQuery selector, you can setup solid functional test very easy.

In this blogpost we will make a simple test which will test a functional part of the JDriven website. We will start our test with configuring the Maven POM file. We need to add the following dependencies.

We also need to configure the GMaven plugin which will compile our Groovy files for us and

When using Geb, a GebConfig.groovy file is requrired to be on your classpath. The best location is to put it in a recognizable location e.g. test/functional. In this file you configure your WebDriver (e.g. Firefox, Chrome etc) and the profile settings for this driver e.g. download folders, proxy settings etc.

Our test class will do a simple check to verify if there is a working link with the text ‘JDriven’ on the JDriven website which refers to the homepage.

We extend our test class from GebReportingSpec. You can also extend from GebSpec but GebReportingSpec will automatically create a screenshot if your test fails, which is more convenient

Please note that you need Firefox to be installed if you want to run the test. When you execute the following Maven command from the command line, the tests will run.

Written with Groovy 2.4.3.

Leave a Reply

Your email address will not be published. Required fields are marked *