{"id":2522,"date":"2011-01-13T18:21:09","date_gmt":"2011-01-13T12:51:09","guid":{"rendered":"http:\/\/www.tothenew.com\/blog\/?p=2522"},"modified":"2011-01-14T10:47:30","modified_gmt":"2011-01-14T05:17:30","slug":"pagechangelistener-for-debugging-in-functional-testing-using-geb","status":"publish","type":"post","link":"https:\/\/www.tothenew.com\/blog\/pagechangelistener-for-debugging-in-functional-testing-using-geb\/","title":{"rendered":"PageChangeListener for debugging in  functional testing using Geb"},"content":{"rendered":"<p>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.<\/p>\n<p>PageChangeListener will look like this:-<\/p>\n<p>[java]<br \/>\nclass EchoingPageChangeListener implements PageChangeListener {<br \/>\nvoid pageWillChange(Browser browser, Page oldPage, Page newPage) {<br \/>\nprintln &quot;browser &#8216;$browser&#8217; changing page from &#8216;$oldPage&#8217; to &#8216;$newPage&#8217;&quot;<br \/>\n}<br \/>\n}<br \/>\n[\/java]<\/p>\n<p>The SpockTest will be having the following code:-<\/p>\n<p>[java]<br \/>\nclass TestSpec extends GebSpec{<br \/>\ndef setupSpec() {<br \/>\n\/\/a kind of init method for our SpockTest<br \/>\nBrowser.drive {<br \/>\ndef listener = new EchoingPageChangeListener()<br \/>\n\/\/this register the browser with PageChangeListener<br \/>\nbrowser.registerPageChangeListener(listener)}<br \/>\n}<br \/>\ndef &quot;login test&quot;(){<br \/>\ngiven:<br \/>\nto(GmailLoginPage)<br \/>\nassert at(GmailLoginPage)<br \/>\nloginModule.loginAs(&quot;username@gmail.com&quot;,&quot;password&quot;)<br \/>\nwhen:<br \/>\nassert at(GmailLoginPage)<br \/>\nthen:<br \/>\nprintln &quot;invalid username or password&quot;<\/p>\n<p>}<br \/>\n}<br \/>\n[\/java]<\/p>\n<p>Hope this help you guys!<br \/>\nThanks and Regards,<br \/>\n<strong>Anuj Aneja<br \/>\nanuj@intelligrape.com<\/strong><\/p>\n<p><strong>http:\/\/intelligrape.com\/<\/strong><\/p>\n","protected":false},"excerpt":{"rendered":"<p>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 [&hellip;]<\/p>\n","protected":false},"author":27,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"iawp_total_views":3},"categories":[7],"tags":[4840,490],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/2522"}],"collection":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/users\/27"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/comments?post=2522"}],"version-history":[{"count":0,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/2522\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/media?parent=2522"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/categories?post=2522"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/tags?post=2522"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}