Geb/Groovy Page Object

244 views
Skip to first unread message

N Kuruba

unread,
May 20, 2015, 5:01:08 AM5/20/15
to geb-...@googlegroups.com
This is a continuation of my previous post in the old group markmail.org/list/org.codehaus.geb.user

Many thanks for your suggestions. I have been using to() extensively and didn't know that we could skip the definition of url property (especially for pages with dynamic urls).
Now, when I have removed the url property in my page objects and the to( ) calls in spec, it fails to find the elements or methods defined in the page.
 
A typical page object in my project:

class MyPage extends Page {
static at = { title == "Version 1.0" }
static content = {
search (wait:true) {$("input", type: "text", name: "search")}
send (wait:true) { $("input", class: "button go", type: "submit") }
}

// this method would click any (text) hyperlink on the page
def clickMenu(String link){
def menuLink = $("a" , text : link)
menuLink.click()
}
}

Spec() {

     // post login, say current page is MyPage
     search = 'keyword'        //  unable to resolve 'search' as property of ...
     send.click()
      
     clickMenu('menu option 1')     //  missing method exception .... 
}

As you can see I get errors for the same code which was working (with URL property set). Is it due to the wait strategy, please help.

Marcin Erdmann

unread,
May 20, 2015, 5:59:33 AM5/20/15
to geb-...@googlegroups.com
You cannot just remove to() calls, you still need to tell Geb that the page has changed. You can do it using at() which verifies the at checker and sets the page if the check was successful. If you don't want to do at checking (to be honest there is no reason to not do at checking, but still) you can use page() method to change the page. Finally, there is also the `to` content definition option, that allows you to ask Geb to switch the page after clicking on given content: http://www.gebish.org/manual/current/pages.html#to.

--
You received this message because you are subscribed to the Google Groups "Geb User Mailing List" group.
To unsubscribe from this group and stop receiving emails from it, send an email to geb-user+u...@googlegroups.com.
To post to this group, send email to geb-...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/geb-user/6c6045ec-06e7-4fca-822d-00cd906e5718%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Brian Kotek

unread,
May 20, 2015, 10:31:54 AM5/20/15
to geb-...@googlegroups.com
As Marcin said, use at() instead of to(). I'd recommend reading the docs, as this is all described there pretty well: http://www.gebish.org/manual/current/all.html#changing_the_page

Reply all
Reply to author
Forward
0 new messages