Geb (pronounced “jeb”)

very groovy browser automation… web testing, screen scraping and more

Page Objects

Geb has first class support for the Page Object pattern, leveraging Groovy's DSL capabilities to allow you the developer to easily define the interesting parts of your pages in a concise, maintanable and extensible manner.

import geb.Page
    
class LoginPage extends Page {
    static url = "http://myapp.com/login"
    static at = { heading.text() == "Please Login" }
    static content = {
        heading { $("h1") }
        loginForm { $("form.login") }
        loginButton(to: AdminPage) { loginForm.login() }
    }
}

class AdminPage extends Page {
    static at = { heading.text() == "Admin Section" }
    static content = {
        heading { $("h1") }
    }
}

Pages define their location, an “at checker” and content (among other things). Defining this information as part of the page allows you to separate the implementation details from the intention.

import geb.Browser
    
Browser.drive {
    to LoginPage
    assert at(LoginPage)
    loginForm.with {
        username = "admin"
        password = "password"
    }
    loginButton.click()
    assert at(AdminPage)
}

See the manual section on pages for more information on.