PageChangeListener for debugging in functional testing using Geb

13 / Jan / 2011 by Anuj Aneja 0 comments

While using Geb for fuctional testing i require some deugging support so i use PageChangeListener and i found it very useful to find flow of pages while testing my application fuctionally.What it does is it will show the page flow from one page to another.For that we need to just register the PageChangeListener with browser in your Spock Test.

PageChangeListener will look like this:-

[java]
class EchoingPageChangeListener implements PageChangeListener {
void pageWillChange(Browser browser, Page oldPage, Page newPage) {
println "browser ‘$browser’ changing page from ‘$oldPage’ to ‘$newPage’"
}
}
[/java]

The SpockTest will be having the following code:-

[java]
class TestSpec extends GebSpec{
def setupSpec() {
//a kind of init method for our SpockTest
Browser.drive {
def listener = new EchoingPageChangeListener()
//this register the browser with PageChangeListener
browser.registerPageChangeListener(listener)}
}
def "login test"(){
given:
to(GmailLoginPage)
assert at(GmailLoginPage)
loginModule.loginAs("username@gmail.com","password")
when:
assert at(GmailLoginPage)
then:
println "invalid username or password"

}
}
[/java]

Hope this help you guys!
Thanks and Regards,
Anuj Aneja
anuj@intelligrape.com

http://intelligrape.com/

FOUND THIS USEFUL? SHARE IT

Tag -

Grails spock

Leave a Reply

Your email address will not be published. Required fields are marked *