This multi-module Gradle project leverages Geb and Spock to create a behavior-driven development (BDD) web automation framework. The executable specifications, written in Groovy or Java, read like plain English and drive automated Selenium browser sessions locally or (optionally) against a scalable remote grid. The use of Page Object modeling ensures the maintainability and re-usability of code.
Multi-level logging is supported via slf4j and logback. A shared utility package is utilized to store common code. There is seamless Integration with IntelliJ IDEA, enabling easy step-by-step debugging and the testing of pipeline automation entry-points.
The project is intended for educational and demonstration purposes, and can serve as a starting point to rapidly develop functional web application test suites or automation scripts across a variety of web applications. Additional examples and design patterns will be added over time and an effort will be made to keep the integrated technologies up to date with modern browser standards.
Software | Version | Description |
---|---|---|
Groovy | 4.0.22 | A powerful and expressive JVM (Java) scripting language |
Geb | 7.0 | High level WebDriver API |
Spock | 2.3 | BDD test/specification runner |
Gradle | 8.5 | Build tool & dependency management |
Selenium (WebDriver) | 4.22.0 | Browser automation API |
ChromeDriver | 126.0.6478.126 | Selenium driver for Chrome |
GeckoDriver | 0.33.0 | Selenium driver for Mozilla |
slf4j | 2.0.13 | Logging API |
logback | 1.5.6 | Logging implementation |
Spock Reports | 2.5.1 | Third-party HTML reporting module for Spock |
- Git
- Java Development Kit 21
- A browser (or a remote grid). Tested against Firefox v128 and Chrome v126
- Clone the repo.
git clone [email protected]:treyturner/geb-spock-gradle-grid.git
- Change directory.
cd geb-spock-gradle-grid
- Run specs.
- On Windows:
gradlew.bat test
- On Mac / Linux:
./gradlew test
- View the results.
- HTML reports are written to
build/reports/tests
- JUnit XML results (for Jenkins/CI consumption) are written to
build/test-results/tests
- Console text logs are written to
build/logs
You have a few choices on how to run tests.
- Browser Type
- chrome
- chromeHeadless
- firefox
- firefoxHeadless
- Browser Location
- local
- grid
- For continuous integration. Docker is ideal for setting up your own grid (local or remote)
- If your grid is remote, set
gridUrl
in WebDriver.groovy accordingly, or you can set aGRID_URL
environment variable, ie.http://your.grid.ip.address:4444/wd/hub
Based on your choices to the above, edit the Globals.groovy file for the module you intend to configure. The browser type set in this file applies to IDEA spec executions only, as Gradle sets a value up front. The browser location applies to both Gradle and IDEA.
IDEA works great with Gradle; just 'Import project from existing sources' and select the root build.gradle
script.
- It helps if you check 'auto-import' so your changes to Gradle files are immediately refreshed
- I also check 'automatically create content roots' for when I add a new modules to
settings.gradle
There is currently only a very basic Google search in the Search Engine Exercises module. It illustrates:
- How to write a basic spec
- How to write basic page objects
- How to use modules to model table rows
It's easy to add a new module to start testing a new application.
- Edit settings.gradle and add a line to
include 'your-module'
- Copy a build.gradle into the newly created
your-module/
- Copy a GebConfig.groovy into
your-module/src/test/resources
- Copy a Globals.groovy into
your-module/src/main/groovy/your_package
and update the package name accordingly - Start writing Page Objects and specs