Geb Programmer : Obtain current page html source?

Geb manual:

Geb builds on the WebDriver browser automation library, which means that Geb can work with any browser that WebDriver can.

With WebDriver is easy to obtain the page source. Lets do a test to verify it.

Lets start by creating a Gradle project with Groovy

$ gradle --version

Gradle 3.1
$ mkdir pagesource
$ cd page source
$ touch <i>build.gradle</i>

Add Groovy dependency to build.gradle

apply plugin: 'groovy'

Add Gradle wrapper

$ gradle wrapper --gradle-version 3.1

add Geb and Spock depependencies to build.gradle

apply plugin: 'groovy'

repositories {
dependencies {
    compile "org.gebish:geb-core:1.0-rc-1"
    compile "org.seleniumhq.selenium:selenium-firefox-driver:2.52.0"
    compile "org.seleniumhq.selenium:selenium-support:2.52.0"
    compile 'org.spockframework:spock-core:1.0-groovy-2.4'

Create a test

$ vi <i>src/test/groovy/PageSourceSpec.groovy</i>
import spock.lang.Specification

import geb.Browser

class PageSourceSpec extends Specification {
   def "test page source of has a closing </body> tag"() {
        def browser = new Browser()
        browser.go ''


If you run the test, it will pass:

$ ./gradlew test

Tags: #geb #grails
Oct 2016, 02.