Geb Tutorial – Browser Automation Testing Using Geb Tool

Geb (pronounced “jeb”) is the answer to the challenges of browser automation. It is a very effective tool to perform automation testing over the web.

Geb originated out of the need to make browser automation (initially for web testing) less complicated, hassle-free and more efficient. It may be utilized for programming, extracting data from the web and automating the manual web tasks. Additionally, Geb is a cross-browser tool for automation testing.

Geb functions as a developer-driven tool for automating the collaboration between web browsers and web content. It runs the WebDriver in Groovy language.

The beauty of Geb testing tool is that it combines the best features of Groovy programming language, jQuery, WebDriver and Page Object Modelling to provide powerful, robust & dynamic content inspection, selection and web interaction.

What makes Geb unique when compared to other automation testing tools available in the market is its syntax. It is similar to jQuery that is normally used for querying the HTML pages easily. Secondly, it has integrated support for the Page Object pattern.

Geb provides great help for functional web testing through integration with some broadly used and common testing platforms including Spock, Grails, JUnit, Cucumber-JVM, TestNG, etc. We will see how Geb can be integrated with Grails framework in the later part of this article.

What You Will Learn:

Practical Uses

As already discussed in the introduction of this Geb tutorial, it can be used:



Before getting started, we need to download and install the software. At the central Maven repository, Geb is available as a single Geb-core jar. Click here to install it on your machine.

You will need the above Geb-core jar, a web driver implementation, and the selenium-support jar to get Geb working on your machine.

Please refer to the below installation and usage section of the book of Geb to install the tool and get it running => Geb installation and usage manual.

Getting Started

As already discussed, Geb can be integrated with different testing frameworks.

Depending on the framework you have chosen, you will need to install the related plugin.

For example: Grails (Grails is a very famous framework for web applications) to write automation test scripts and automate the test scenarios. If you wish to use Geb for your Grails functional testing, you can install the related plugin from here grails-geb plugin.  This plugin handles the baseUrl and reportsDir configuration items.

Learn with Example

Let me now show how to write a Geb script to automate a test scenario.

Take the below test scenario:

Test Scenario IDSoftwaretestinghelp-1Test Case IdSoftwaretestinghelp -1A
Test Case DescriptionVerify Page through search engineAutomation Script StatusIn Progress
Pre-requisite1 Browser

2. search engine

3. website - should exist
Pre-requisite Script NA

The execution steps are:

Launch google search engine
Verify if the search engine has been loaded successfully
Enter in the search box
Wait for results to load
Verify if the first link in results is directing to
If yes, open the link.
Wait until the website opens up.

Here is the Geb automation tool script for the above scenario:

import geb.Browser {
go ""

//verify if we are on the correct page
assert title=="Google"

//enter into the search field

//wait for the change to results page to happen
//(google updates the page dynamically without a new request)
waitFor{ title.endsWith("Google Serach")}

//is the first link to
def firstLink = $("li.g,0).find("a.l")
assert firstLink.text()= ="Software Testing Help - A Must Visit Software Testing Portal"

//click the link

//wait for Google's javascript
waitFor { title = ="Software Testing Help - A Must Visit Software Testing Portal" }

You can now try writing a simple GEB script on your own referencing the above example.

Database validation testing through Geb script:

Any web automation testing is divided into three parts:

The Geb script written to automate a test scenario can contain the code for all of the above three sections.

The Geb script in the above example section was for automating the test flow and UI validation. Similarly, you can write a test script for database validation.

For any DB validation test, you can always use the below template as an outline for your code:

def validateDB(/*define all variables here*/) {
def errorMessages = ""
try {
Configuration conf = (new ConfigurationLoader()).getConf()
def sql = Sql.newInstance(conf.readValue("dbPath", ""), conf.readValue("dbUserName", ""), conf.readValue("dbPassword", ""), conf.readValue("dbDriverName", ""))

/* Populate any required variables */

/* Give print commands here to print required values */
def qry = /* select statement to pull all required values from database */
println "SQL=$qry"
sql.eachRow(qry) { row ->

/*  ‘if’ block to perform validation and returning error in case of any variations */
catch(Exception e) {
println "EEEE=$e"
return errorMessages

Few useful Methods in Geb

Drawbacks of this tool

More resources:


Geb is very useful in automating test case scenarios. It is useful to automate web, functional and user acceptance testing. It supports multiple browsers and can be integrated with different frameworks. It combines the power of WebDriver, elegance of jQuery Selection, the robustness of Page Object Modelling and expressiveness of Groovy.

Geb scripts are both developer and user-friendly providing better test coverage and accelerated testing while making it more efficient at the same time.

About the author: This is a guest post by Priya K. She is having 4+ years of experience in IT Services with expertise in Testing and support for various applications.

Feel free to post your Geb automation testing queries in comments.