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 {
jcenter()
}
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 sergiodeamo.es has a closing </body> tag"() {
when:
def browser = new Browser()
browser.go 'http://sergiodelamo.es'
then:
browser.driver.pageSource.contains('</body>')
}
}
If you run the test, it will pass:
$ ./gradlew test
My next events:
๐ May 27 09:00 AWS Dublin - Micronaut and AWS Lambda
๐ Jul 20 09:00 Workshop Security in the Micronaut Framework
๐ Sep 20 09:00 JCON Online 2022 - Getting Started with the Micronaut Framework
๐ Sep 23 09:00 JCON Online 2022 - Micronautยฎ Framework and Microstream Java-native persistence engine