Click here to Skip to main content
15,888,351 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have some methods in a module (groovy Spock framework. The methods all shared a common pattern. I want to make a method for this common pattern, then call on it from the mentioned methods.

two of the methods which shared the same pattern are: (I show just two of them here but they are more).
```
void setPayloadIndexRetention(String payloadIndexRetention) {
        if (payloadIndexRetention==null){
            payloadIndexRetention='30 days(default)'
        }
            arielRetention.find('input', class: contains('dijitArrowButtonInner')).click()
            arielRetentionmenu.find('td', text: payloadIndexRetention).click()
            sleep(5000)
    }
   ```

`arielRetention` and `payloadIndexRetention` are defined in the module content as:
```
arielRetention { $('table', id: 'ARIEL_FREE_TEXT_RETENTION') }
arielRetentionmenu { $('table', id: 'ARIEL_FREE_TEXT_RETENTION_menu') }
```


``` void setPrivacyProtocol(String privacyProtocol) {
        if (privacyProtocol==null){
            privacyProtocol='DES'
        }
        snmpPrivacyProtocol.find('input', class: contains('dijitArrowButtonInner')).click()
        snmpPrivacyProtocolmenu.find('td', text: privacyProtocol).click()
        sleep(5000)
    }
```

`snmpPrivacyProtocol` and `snmpPrivacyProtocolmenu` are:
```
snmpPrivacyProtocol { $('table', id: 'SNMP_V3_DEC_PROTO') }
snmpPrivacyProtocolmenu { $('table', id: 'SNMP_V3_DEC_PROTO_menu') }
```

I made another method that includes the shared pattern:
```
 void setParameter (String parameter, String defaultValue, def navigator1, def navigator2){
        if (parameter==null){
            parameter=defaultValue
        }
        navigator1.find('input', class: contains('dijitArrowButtonInner')).click()
        navigator2.find('td', text: parameter).click()
    }
```

When I call `setParameter` on the `setPayloadIndexRetention` method, and run my test I get the following error:
```
geb.error.RequiredPageContentNotPresent: The required page content 'geb.qradar.gebpages.SystemSettingsPage -> settings: geb.qradar.gebmodules.SystemSettingsModule -> arielRetentionmenu: geb.navigator.DefaultNavigator' is not present
```

Does anyone have any idea where am I making a mistake?
I also use `Navigator` instead of `def as parameter type, the issue was still there.

What I have tried:

I tried what I mentioned in the above post.
Posted
Updated 30-Apr-22 14:07pm
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900