"to" content DSL param - will clicking the content return the page like to()

30 views
Skip to first unread message

Samuel Rossinovic

unread,
Aug 16, 2017, 6:05:56 AM8/16/17
to Geb User Mailing List
Hi.

Taking the example from geb's doc:

class PageWithTemplateUsingToOption extends Page
{
   
static content = {
        helpLink
(to: HelpPage) { $("a", text: "Help") }
   
}
}

to
PageWithTemplateUsingToOption
helpLink
.click()



Can I expect the return value from the click to be the page pointed-to by the to: paramater?

HelpPage helpPage = helpLink.click()



Thanks

Marcin Erdmann

unread,
Aug 17, 2017, 3:01:00 AM8/17/17
to geb-...@googlegroups.com
If I remember correctly (on my mobile atm) Navigator.click() returns the clicked navigator instance, so your assumption is not correct. 

I would suggest writing a custom module implementation with a method called, for example, clickTo() having HelpPage as the return type and the implementation could call click() and return the value returned from "at HelpPage". Finally I would use that module for your content definition, remove the to template option from your content definition and call clickTo() instead of click() in yoir code.

You could make your model parameterised (there is a section in the manual about parameterised modules) with the target page being the parameter if you wanted to apply this pattern in multiple places that deal with different target pages.

--
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/cff33ec1-2ad2-4104-89b6-97bd728f60ac%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Samuel Rossinovic

unread,
Aug 28, 2017, 3:27:08 AM8/28/17
to Geb User Mailing List
Thanks.

I am keen to try this solution, but am unsure how to pass a Page class reference as a parameter.

Marcin Erdmann

unread,
Aug 28, 2017, 6:12:21 PM8/28/17
to Geb User Mailing List
Your module would look like this:

class PageSwitchingOnClickModule<T extends Page> extends Module {

    private final Class<T> targetPage

    PageSwitchingOnClickModule(Class<T> targetPage) {
        this.targetPage = targetPage
    }
    
    T clickTo() {
        click()
        at targetPage
    }

}

and then you would use it like:

static content = {
    helpLink { $("a", text: "Help").module(new PageSwitchingOnClickModule<>(HelpPage))
}

and

HelpPage helpPage = helpLink.clickTo()

To unsubscribe from this group and stop receiving emails from it, send an email to geb-user+unsubscribe@googlegroups.com.

To post to this group, send email to geb-...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages