Forum Discussion
HIZDGN
i also found that a groovy script would possible help. However, I have no idea how to write such a groovy code to make it work.
Could you tell me how or do you have such a working groovy code?
DavidSEM_Admin Sorry, I'm not back in work for another week, so I cannot dig out some examples. At work, I have pro, but at home, I don't so I don't currently have access to the pro features to help.
Groovy Script steps allow you to script some action or task. They return a value. It could be true, false, 1, 0, "hello world' or even a whole payload.
You could have one or several such steps in your test prior to the REST/SOAP request step. In the REST/SOAP step you can 'pull' in the results of the Groovy step(s).
It's a really, really neat feature and one I use a lot.
Great big caveat here, this is an untested example. There will be bugs...
In terms of reading your datasource values in a Groovy Step, here is an example...
// What the below does is read your DataSource and gets the value of CountryCode
// for the current row and assigns it into a variable called countryCode.
def countryCode = context.expand( '${DataSource#CountryCode}' );
// Initialise a var to use to return whatever we need from this script.
def returnValue = '';
// Check if countryCode contains something....
if(countryCode.length > 0){
// It does! Let's put country code inside a tag.
returnValue = "<someElement>" + countryCode + "</countryCode>"
else {
// Do nothing, there is no contry code to consider for this row.
// But, you could do something. E.g shove in a default value.
}
// Let's return our custom part of the request.
return returnValue;
Then, in your REST/SOAP Request, you can pull this into the body of the request. E.g.
<soapEnv:envelope>
<soapEnv:header/>
<soapEnv:body>
<someElementInDataSource>${DataSource#CountryCode}</someElementInDataSource>
${GroovyStepName#result}
</soapEnv:body>
</soapEnv:envelope>
In the above, it tries to show how you pull in the result of your groovy into your request. The syntax might be wrong, but what you can do is in the request window, right-click and select 'Get Data' from the context menu, that gives you access to the other steps in your test. Just select the Groovy Step and then 'result' from the pop-out menus and SoapUI will insert the command for you.
Related Content
- 3 years agomrarkapravo
Recent Discussions
- 6 hours agoruchisingh