Getting missing property exception for accessing browser object in module.

642 views
Skip to first unread message

Manoj Joshi

unread,
Dec 22, 2015, 3:07:31 AM12/22/15
to Geb User Mailing List
Hi,

We have some helper methods in our module which are using browser object.

For example:

def getViewport(){
Dimension dim = browser.driver.manage().window().getSize()
}

However after migrated out framework from geb 0.10 to geb 0.12.2

The methods are started giving following exception.

Unable to resolve browser as content for com.qa.module.TestModule@715408d9, or as a property on its Navigator context. Is browser a class you forgot to import?
groovy.lang.MissingPropertyException: Unable to resolve browser as content for com.qa.module.TestModule @715408d9, or as a property on its Navigator context. Is browser a class you forgot to import?
at geb.content.PageContentSupport.propertyMissing(PageContentSupport.groovy:45)
at geb.Module.propertyMissing(Module.groovy:101)
at com.qa.module.TestModule.getViewport(TestModule.groovy:323)
at geb.content.TemplateDerivedPageContent.methodMissing(TemplateDerivedPageContent.groovy:128)

Please provide suggestion on accessing browser or driver object in module.

Thanks
Manoj Joshi

Brian Kotek

unread,
Dec 22, 2015, 9:04:48 AM12/22/15
to Geb User Mailing List
Just an idea, but you could try overriding the Module init() method to store a reference to the browser. http://www.gebish.org/manual/current/api/geb/Module.html#init(geb.Browser, geb.navigator.factory.NavigatorFactory)

Manoj Joshi

--
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/0e05f50d-504a-4d3c-a11f-84e39c121525%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Marcin Erdmann

unread,
Dec 23, 2015, 7:53:47 AM12/23/15
to Geb User Mailing List
I wouldn't recommend overriding Module.init() because that method is an implementation detail, is not designed to be overridden and hence it's signature is subject to change. If you do that then it's possible that it will not work for a future version.

I've removed the browser reference from the API of Module because I thought that modules shouldn't need to access the browser but I have recently found myself that it's not always the case and it's sometimes useful to be able to access the current browser from within a module. Therefore the reference to the browser instance will be coming back onto public API of Module in the next version.

In the meantime I would suggest passing the browser as a module parameter:

class ModuleWithDimensions extends Module {
    
    Browser browser

    Dimensions getViewport() {
        browser.driver.manage().window().getSize()
    }

}

and then in your page:

static content = {
    moduleWithDimensions { $(".with-dimensions").module(new Module(browser: browser)) }
}


Marcin Erdmann

unread,
Dec 23, 2015, 9:01:34 AM12/23/15
to Geb User Mailing List
The browser will be back on Module when a snapshot version is published upon a successful build: https://github.com/geb/issues/issues/416.

Manoj Joshi

unread,
Dec 24, 2015, 2:40:26 AM12/24/15
to Geb User Mailing List
Thanks a lot Marcin and Brain for addressing issue.


Best Regards
Manoj Joshi
Reply all
Reply to author
Forward
0 new messages