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()
On Mon, Aug 28, 2017 at 8:27 AM, Samuel Rossinovic <
[email protected]> wrote:
> Thanks.
>
> I am keen to try this solution, but am unsure how to pass a Page class
> reference as a parameter.
>
>
> On Thursday, August 17, 2017 at 5:01:00 PM UTC+10, Marcin Erdmann wrote:
>>
>> 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.
>>
>> On Wed, 16 Aug 2017 at 11:05, Samuel Rossinovic <[email protected]>
>> wrote:
>>
>>> 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
>>>
>>> --
>>> 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 [email protected].
>>> To post to this group, send email to [email protected].
>>> To view this discussion on the web visit https://groups.google.com/d/ms
>>> gid/geb-user/cff33ec1-2ad2-4104-89b6-97bd728f60ac%40googlegroups.com
>>> <https://groups.google.com/d/msgid/geb-user/cff33ec1-2ad2-4104-89b6-97bd728f60ac%40googlegroups.com?utm_medium=email&utm_source=footer>
>>> .
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>> --
> 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 [email protected].
> To post to this group, send email to [email protected].
> To view this discussion on the web visit https://groups.google.com/d/
> msgid/geb-user/ec667610-6315-48d5-b381-637ce7714616%40googlegroups.com
> <https://groups.google.com/d/msgid/geb-user/ec667610-6315-48d5-b381-637ce7714616%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>
> For more options, visit https://groups.google.com/d/optout.
>
--
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 [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/geb-user/CA%2B52dQSUF-POM-SJisCz5Qd3E1JF4-7neB2fZ6875_oqYe2gPg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.