Have you tried using page objects for this?

https://gebish.org/manual/5.0/#pages

Cheers,
11011011

On 2021-10-11 15:36 , Bob Brown wrote:

I am trying to make life a bit easier for my userbase. I allow things like:

===

       then: "Establish Contact Details"

withFlowViewForm('contactDetailsCheck') { form ->

            form.noPhone = true

            form.anonymous = true

form.clickCustomRadioButtonHavingNameAndText('caller', cfg.caller)

            form.clickNextButton()

        }

===

Obviously, clickCustomRadioButtonHavingNameAndText and clickNextButton are not standard Geb/Selenium methods…

Inside ‘withFlowViewForm’, I add clickCustomRadioButtonHavingNameAndText, clickNextButton (and more) closures to the ‘form’ INSTANCE metaClass:

===

   void withFlowViewForm(view, c) {

        withFrame('iframe') {

            final form = $('form')

            // inefficient, but simple and works

            form.metaClass.clickNextButton = { clickButton(delegate, 'next') }

form.metaClass.clickCustomRadioButtonHavingNameAndText = { name, text ->

                def radio = delegate.find('label.form-check-label', text: text).parent().find('input', name: name).module(RadioButtons)

                if (radio.isEmpty())

                    throw new LightweightException("Could not find radio button with {name: ${name}, text: ${text}}")

                radio.click()

            }

            c(form)

        }

    }

    private void clickButton(form, evt) {

        report "${form.parent('body').attr('id')}"

        def btn = form."_eventId_${evt}"()

        if (btn.isEmpty())

            throw new LightweightException("Could not find button with {attribute: _eventId_${evt}}")

        btn.click()

    }

===

This works very nicely, but I can’t help but feel that there should be a more efficient way of doing this…ideally, I would like to decorate ‘form’ one time only at startup (perhaps in GebConfig?).

I have read the doco section: “7.2.2. Navigator factory” is this the way to go? Provide an extension of Navigator?

I like that the doco says “..get in touch via the mailing list if you need help.”

Here I am 😊

Can anybody guide me?

Thanks,

BOB

--
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] <mailto:[email protected]>. To view this discussion on the web visit https://groups.google.com/d/msgid/geb-user/SY4P282MB1883F0917C84AD9F3210D85EEDB69%40SY4P282MB1883.AUSP282.PROD.OUTLOOK.COM <https://groups.google.com/d/msgid/geb-user/SY4P282MB1883F0917C84AD9F3210D85EEDB69%40SY4P282MB1883.AUSP282.PROD.OUTLOOK.COM?utm_medium=email&utm_source=footer>.

--
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/geb-user/b958f621-646e-9598-a981-f3cdae54648f%40getsu.com.

Reply via email to