Geb Tutorial – Browser Automation Testing Using Geb Tool

By Vijay

By Vijay

I'm Vijay, and I've been working on this blog for the past 20+ years! I’ve been in the IT industry for more than 20 years now. I completed my graduation in B.E. Computer Science from a reputed Pune university and then started my career in…

Learn about our editorial policies.
Updated October 17, 2025

Here is an in-depth tutorial on the process of browser automation through Geb Tool for your benefit:

Geb (pronounced “jeb”) is the answer to any kind of browser automation challenges. 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 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 effectiveness of Geb testing tool is in the fact 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. Learn about this tool in detail in this article.

Geb Tool Tutorial

Geb Browser automation solution

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 HTML pages easily. Other than that, 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.

Practical Use of the Geb Tool

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

  • As a Testing tool on multiple browsers like Chrome, Firefox, Internet explorer, etc. The same automation script can be run on different browsers to perform web testing of your application.
  • Automate User acceptance and functional test cases.
  • Automate test scenarios created for functional or web testing of any application.
  • Cover end-to-end testing including UI (User Interface) validation and DB (Database) validation.
  • As a Developer’s tool for automating the interaction between a web browser and web content.

Its Advantages

  • Geb is a free, open-sourced tool. It is licensed under the Apache License, Version 2.0.
  • Easy and simple to automate web testing.
  • Geb’s Page Objects and Groovy DSL make tests readable to the extent that they almost look like plain English.
  • Runs the tests fast and thus saves time and cost of testing.
  • Compatible with different browsers like IE, Firefox, Chrome, and HTMLUnit.
  • It executes the tests in the real browser. It is like testing in a real environment – the one that the user would see.
  • It makes regression testing easy. You can run the Geb automated test cases to check if any existing functionality is breaking after a fix or change in the application.
  • While using Geb for automation testing, minimal test code changes are required if there are any UI changes in your application. So, it reduces the effort & duplication of code.
  • It helps 360 degrees (or maximum) testing coverage within a single script.

Prerequisites for installing the tool

Before getting started, we need to download and install the software. In 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. This plugin handles the BaseUrl and ReportsDir configuration items.

Learn with Examples

Let me now show you 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 Softwaretestinghelp.com Page through search engineAutomation Script StatusIn Progress
Pre-requisite1 Browser
2. search engine
3. website - Softwaretestinghelp.com should exist
Pre-requisite Script NA

The execution steps are:

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

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

import geb.Browser
Browser.drive {
go "http://google.com/"

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

//enter softwaretestinghelp.com into the search field
$("input",name:"q").value("softwaretestinghelp.com")

//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 softwaretestinghelp.com?
def firstLink = $("li.g,0).find("a.l")
assert firstLink.text()= ="Software Testing Help - A Must Visit Software Testing Portal"

//click the link
firstLink.click()

//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:

Web automation testing is divided into three parts:

  • UI Validation – Validating the data reflected on the user interface (front end) before & after the automation test scenario run.
  • DB Validation – Validating the data reflected in the database (backend) before & after the automation test scenario run.
  • Actual Test flow / Script flow.

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 tests, you can always use the template below 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
}

A Few Useful Methods in Geb

  • When your test case scenario involves multiple tabs and windows: Whenever you come across an application that opens up new windows or tabs, for example when clicking on a link with a target attribute set, you can make use of withWindow() and with NewWindow() methods to execute code in the context of other windows.
  • Drive method: Browser class contains a static method – drive(). This method gives extra convenience to Geb scripting. All top level method calls and property accesses are implied to be against the browser.
  • Making Requests: Browser instances uphold a baseUrl property that is employed to resolve all relative URLs. It is usually most preferable to define your base URLs with trailing slashes and not to use leading slashes on relative URLs.
  • Changing the Page: With the help of useful page() methods, it is feasible to change the page instance without making a new request.
  • Quitting the Browser: The browser object provides quit() and close() methods (that simply handover the task to the base driver).

Some Drawbacks of this tool

  • Geb executes WebDriver in Groovy language. The whole idea behind this is to make the use of WebDriver easier and simpler. So, when you are using Webdriver through Geb, only Groovy programming language will be supported. But, if you directly use WebDriver, it supports many languages like Ruby, C#, Python, Java.
  • I would not suggest the use of Geb for small projects – it works awesome for enormous tasks but takes a hit on small activities. If your web application does not contain multiple pages and forms through which the information needs to flow, you may discover that Geb really costs you additional time than it spares.
  • It is very particular about what environment your website application utilizes. Geb is required to be well integrated into a specific environment to make it function fine.

More resources for your benefit:

Conclusion

Geb is very useful in automating test case scenarios. It is effective in automating web, functional and user acceptance testing. It supports a variety of 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 or feedback in the comments section below. We would love to hear from you.

Was this helpful?

Thanks for your feedback!

Recommended Reading

  • Katalon Studio Tutorial

    Katalon Studio is a wonderful free tool for test automation. We have provided a detailed Katalon Studio tutorial for your benefit: Test Automation is one area where there is always a constant quest for betterment, simplicity, robustness and ease of use. Some tools can help create robust, light and maintainable…

  • Load Testing Using LoadUI

    What is LoadUI? LoadUI is a free and open-source load testing tool that allows you to perform complex load tests and test performance by simply dragging different components around. LoadUI lets you create and update test cases while you run them. What makes load UI powerful is the focus on…

  • Load Testing from the Cloud

    Let’s face it - the ideal load test emulates real world traffic, yet most load testing software doesn’t come close. A series of GET requests from an in-house server can't possibly replicate what happens when a website sees a sudden increase in users from all over the world. Held back…

  • Learning Basics of Rational Robot

    Rational Robot is an automated functional, regression testing tool for automating Windows, Java, IE and ERP applications under windows platform. This article should be a good start for those who wants to learn Rational Robot test automation tool. Read on for Rational robot tutorial with trial version download and resources.


READ MORE FROM THIS SERIES:



10 thoughts on “Geb Tutorial – Browser Automation Testing Using Geb Tool”

  1. I can’t get this script to run. What may I be doing wrong?
    I’m getting this error:

    Caught: java.lang.NoClassDefFoundError: geb/error/UnableToLoadException
    java.lang.NoClassDefFoundError: geb/error/UnableToLoadException
    at geb.Browser.(Browser.groovy:61)
    at geb.Browser.drive(Browser.groovy:1028)
    at geb.Browser$drive.call(Unknown Source)
    at firstGroovy.FirstGeb.run(FirstGeb.groovy:4)

    I’ve got your script on a groovy file, and the following GebConfig.groovy file:

    package firstGroovy
    /*
    This is the Geb configuration file.

    See:
    */

    import org.openqa.selenium.chrome.ChromeDriver
    import org.openqa.selenium.firefox.FirefoxDriver

    // Use firefox as the default
    // See: http://code.google.com/p/selenium/wiki/FirefoxDriver
    driver = { new ChromeDriver() }

    environments {

    // run as “gradle -Dgeb.env=chrome cucumber”
    // See: http://code.google.com/p/selenium/wiki/ChromeDriver
    chrome {
    driver = { new ChromeDriver() }
    }

    }

    baseUrl = “http://gebish.org”

    baseNavigatorWaiting = true
    atCheckWaiting = true

    I’ve added geb-core, selenium-support jars, as well as selenium libs into buildpath. Any clues?

    Reply
  2. Hi Priya

    I am using GEB Cucumber Groovy test framework, where i have feature files and corresponding Step Def file.

    Now i want to work on reporting part, which is the best tool(Test NG, Extent Reports) to integrate to get good good reports.

    Also need to basic Code on integrating TestNG or Extent report to Cucumber Geb Groovy test framework.

    Reply
  3. Looks like need update code part of the tutorial. There is website title already changed to
    “Software Testing Complete Guide — Software Testing Help”

    Reply

Leave a Comment