ravienu
4 years agoOccasional Contributor
passing result or variable value from Groovy to test step
Dear Team,
I have query below to achieve one of the requirements. I am using ReadyAPI with proper license.
I would like to pass Goovy script result as one request body(XML/JSON) parameter for API. I have written a Groovy script and test step under it. But dont know how to specify groovy result as body request parameter.
For example:
def today = new Date()
today.format("dd/MM/yyyy")
//Add some random number to Date field and store it in some variable like cutom_date
Now I would like to pass custom_date as request body(XML) parameter for API step under the groovy script as below
........
........
<app_date>?</app_date>
.......
.......
cutom_date from groovy script should come and sit at ? place above.
Can anyone help on this please ?
- Groovy Script test step is not needed. It can done in the request step itself as shown in the below thread.
Please refer an existing solution.
https://community.smartbear.com/t5/API-Functional-Security-Testing/Ready-API-3-3-1-messed-date-up/m-p/205251#M46876 - Save the value into custom property, say EMPLOYEE_ID by adding below line to the script
context.testCase.setPropertyValue('EMPLOYEE_ID', employeeNumber.toString())
Now, in the request, use as ${#TestCase#EMPLOYEE_ID}
Of course, one can save the property at test suite, project level as well. For that respective changes have to done in both groovy and request. - Here is the more detailed information from documentation regarding the same
https://www.soapui.org/docs/scripting-and-properties/property-expansion/
https://www.soapui.org/docs/scripting-and-properties/tips-tricks/