Geb + Spock : Best of breed UI Automation

/, BDD, Browser Automation, Geb, Spock, UI Testing/Geb + Spock : Best of breed UI Automation
UI Automation with Geb & Spock : Introduction — Part 1

UI Automation with Geb & Spock : Introduction — Part 1

Learn Geb + Spock : The best of breed solution for all your UI automation needs

If you are starting a new UI automation project for your web application, and have developer-grade test engineers on your team, look no further than Geb + Spock!

In this tutorial, we will share the code to a fully functional Geb + Spock example with all the best practices.

Let’s start with some high-level information first.

Say Hello to Geb

Geb is a Groovy-based browser automation solution which :

  • helps you write robust, maintainable, and reusable browser automation code
  • uses Selenium WebDriver under the hood
  • provides highly expressive jQuery-like syntax for content selection
  • is a Domain Specific Language (DSL) with useful out-of-the-box features and supporting patterns
  • provides native support for Page Object Model

Sample Geb code that illustrates some of the above bullet points :

A sample Geb page object

A sample Geb page object

Full code for the above Geb TwitterPage class snippet available on GitHub: TwitterPage

Meet Spock

Spock is a Behavioral Driven Design (BDD) testing and specification (spec) framework that improves quite a bit on the existing frameworks like JUnit and TestNG. Some of the useful features of Spock are :

  • Clarity in the test structure in the form of an explicit arrange-act-assert structure. (Spock uses the given-when-then pattern.)
  • Providing clear context around why a text failed so you quickly see the reason for the test failure
  • BDD driven specs means tests are readable by business / non-techie people
  • Great support for parametrized / data-driven tests
  • In-built mocking and stubbing capabilities
A sample Spock test / spec

A sample Spock test / spec

Full code for the above Spock spec available on GitHub: LoginLogoutSpec.groovy

Source Code For a Geb + Spock gradle project

Checkout a fully functional Geb + Spock gradle project from this Automation School github repo. The UI automation example in this repo illustrates several cool features of Geb & Spock :

Upcoming articles in this Geb & Spock series

In the upcoming articles in this Geb & Spock series, we will dive into the details on the following topics :

  • Config files: Geb.config file, Application config files, ConfigReader / ConfigSlurper
  • Wait profile configuration: How to “wait” elegantly for various page or HTML element events using implicit waits or using waitFor()
  • “At Checking”: A cool feature of Geb that makes it a breeze to wait for your next page in a elegant way
  • Content DSL and reusing content with Geb Modules: In the sample repo code, we have a module called HeaderModule, that all pages use for common content
  • BDD Spock Specs, Functional testing with Stepwise, Shared: Cookie management and sharing context between tests in functional tests
  • Driver management using Marcin Erdmann’s webdriver-binaries-gradle-plugin: This plugin helps in just in time downloading/caching of the browser drivers
  • Misc : Generating screenshots, page structure, class hierarchy

Additional Resources / References :

2018-08-15T15:48:33+00:00

About the Author:

One Comment

  1. Atkins August 15, 2018 at 3:56 pm - Reply

    Good article. Looking forward to next ones

Leave A Comment