Forum Discussion
This is just a simple example I wrote for my team and thought I would share with you. What I found challenging was when to use a $ for a variable and when is it left off and how to handle that within strings for Groovy. My team also pulls all data from a datasource so the actual call in the second snippet has a data source property values instead of an actual hard coded values.
Code from Utils.groovy:
class Utils{ def static doXmlCountComparison(String xmlApiRequest, String xmlApiResponseXpath, String xmlDbRequest, String xmlDbResponseXpath, log, context) { def apiCount = context.expand( '${'+xmlApiRequest+'#ResponseAsXml#count('+xmlApiResponseXpath+')}' ) def dbCount = context.expand( '${'+xmlDbRequest+'#ResponseAsXml#count('+xmlDbResponseXpath+')}' ) assert apiCount == dbCount } }
Utils.doXmlCountComparison('getThings','//ns1:things/ns1:e','JDBC','//Row',log,context)
The above is a groovy snippet in the test case.
My scripts folder is set Globally within Preferences.
Ahhh... Reading ByronJ's post has made me realise that I wasn't actually paying attention to the contents of your script. I didn't spot that you were referencing the Ready API variables context and log, plus a file variable. These will need to be passed into your static function.
I've edited my post above to reflect this.
Related Content
- 7 years ago
- 9 months ago
Recent Discussions
- 5 days ago
- 9 days ago