Geb thinks Page content is a Browser property

581 views
Skip to first unread message

Manny Rodriguez

unread,
May 20, 2016, 2:41:16 PM5/20/16
to Geb User Mailing List
Using Geb 0.13.1 here. I'm not trying to integrate it with any kind of testing framework (yet), just trying to get a feel for its DSL. I just want Geb to launch a Firefox browser, point it to Google's homepage and type in 'gmail' in the search address (HTML <input/> with an id of 'q'):

    class GoogleHomepage extends Page {
        GoogleHomepage() {
            super()

            url = 'http://google.com'
            at = {
                title == 'Google'
            }
        }

        static content = {
            search {
                $('input', id: 'q')
            }
        }
    }

    class MyGebDriver {
        static void main(String[] args) {
            FirefoxDriver firefoxDriver = new FirefoxDriver()
            Browser browser = new Browser(driver: firefoxDriver)

            Browser.drive(browser) {
                to(GoogleHomepage)

                search.value('gmail')

                quit()
            }
        }
    }

When I run this, Firefox opens up and goes to Google, but seems to choke when finding the search ('q' element) bar to set a value for:

    Exception in thread "main" groovy.lang.MissingPropertyException: No such property: search for class: sandbox.geb.GoogleHomepage
      at groovy.lang.MetaClassImpl.invokeStaticMissingProperty(MetaClassImpl.java:1001)
      at groovy.lang.MetaClassImpl.getProperty(MetaClassImpl.java:1856)
      at groovy.lang.MetaClassImpl.getProperty(MetaClassImpl.java:1832)
        ...rest of stack trace omitted for brevity

Any ideas as to what's going on here?

Brian Kotek

unread,
May 20, 2016, 3:02:44 PM5/20/16
to Geb User Mailing List
Not sure if it's the cause, but I'm pretty sure values like url and at must be static. You also shouldn't need your own constructor (that could also be interfering with Geb). 

--
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/379200db-c403-449e-9519-6bce49fb3153%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Manny Rodriguez

unread,
May 20, 2016, 3:26:24 PM5/20/16
to Geb User Mailing List
Thanks @brian428, so I changed GoogleHomepage to:

class GoogleHomepage extends Page {
    static url = 'http://google.com'

    static at = {
        title == 'Google'
    }

    static content = {
        search {
            $('input#q')
        }
    }
}

And now the exception is:

Exception in thread "main" geb.error.RequiredPageContentNotPresent: The required page content 'sandbox.geb.GoogleHomepage -> search: geb.navigator.EmptyNavigator' is not present


I think we're getting somewhere, but I'm still not quite there...any ideas? Thanks again!

Brian Kotek

unread,
May 20, 2016, 4:01:01 PM5/20/16
to Geb User Mailing List
Well, Geb is telling you that it can't find the search element. "input#q" equates to an input with an id of "q". Where are you getting that code from? Google.com has no input field with an ID of 'q'. It has a field with the name 'q' though. Try $('input', {name: 'q'}).

You may want to just pull down one of the examples and run it to see things work? 

Manny Rodriguez

unread,
May 20, 2016, 4:05:50 PM5/20/16
to Geb User Mailing List
Thanks again @brian428, I think I get how things are working, and yes I have read most of the intro docs, I was just positive I saw Google's main search field having an id of 'q'...

So per your suggestion I changed GoogleHomepage's static content block to:

static content = {
search {
$('input', { name: 'q' })
}
}

And now I am getting a third (but different!) exception:

Exception in thread "main" geb.error.InvalidPageContent: Definition of page component template '$' of 'sandbox.geb.GoogleHomepage' is invalid, params must be either a Closure, or Map and Closure (args were: [class java.lang.String, class sandbox.geb.GoogleHomepage$__clinit__closure2$_closure3$_closure4])


How is the dollar sign '$' an invalid page component? Do I need to use a Module or something here? Thanks again for all the help thus far!

Marcin Erdmann

unread,
May 22, 2016, 1:32:27 PM5/22/16
to Geb User Mailing List
The error is a bit cryptic because you are trying to call a non existing method, i.e. Module.$(String, Closure), and Groovy then tries to see if there is a method like that on the delegate of the content definition closure which leads to the error about na invalid template definition '$'.

Unfortunately Brian tripped a bit when suggesting the method call you should use. He probably meant to suggest using $('input', name: 'q'), which is a Groovy shortcut for calling $([name: 'q'], 'input'), which means that this method will be called: http://www.gebish.org/manual/current/api/geb/navigator/Locator.html#$(Map<String, Object>, java.lang.String).

Brian Kotek

unread,
May 23, 2016, 10:02:28 AM5/23/16
to Geb User Mailing List
Doh, Marcin is right of course. That's what I get for replying from my phone without looking closely enough. :-/

Reply all
Reply to author
Forward
0 new messages