Forum Discussion
Hi,
"Is there no other way to delete parent elements?". Sorry, I really don't know.
I've used SoapUI's data driven test functionality extensively. In the main, my test data wholly aligns to the payload, so I usually don't have to worry about empty nodes and having to remove them.
On the flip side, I have built validation tests where I'm checking for the existence (and non-existence) of nodes as well as testing expected response where some node is empty.
For this, I still use data-driven tests, but instead of squirting in individual values, I've squirted in the whole request. I've also used data driven tests where my Excel data is a path to a file and I've 'pulled in' the file contents using a Groovy script step. The files contain the whole request I want to send.
To sum up, whilst SoapUI may not always offer what you need, I've never not been able to use the functionality to work around such limitations.
- ZDGN4 years agoContributor
Hi DavidSEM_Admin,
ChrisAdams is pointing something that I find really interesting.
As far as I understand, you could use some groovy code to dynamically generate your xml content depending on the values extracted form your excel file.
That is to say that you keep your data driven test step, and then use groovy code to add or not xml element to the request.
This should make the deal for you.
David.
- DavidSEM_Admin4 years agoOccasional Contributor
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?
- ChrisAdams4 years agoChampion Level 3
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.
- ChrisAdams4 years agoChampion Level 3
Hi,
Yes, this exactly.
- richie4 years agoCommunity HeroHey DavidSEM_Admin
That just proves you should make sure you read everyones posts before responding to the last. I also suggested groovy using an event handler. Unfortunately i didnt notice everyone else suggested this too!
Cheers
Rich
- DavidSEM_Admin4 years agoOccasional Contributor
ChrisAdams can you show or give an example how you did this?
"For this, I still use data-driven tests, but instead of squirting in individual values, I've squirted in the whole request. I've also used data driven tests where my Excel data is a path to a file and I've 'pulled in' the file contents using a Groovy script step. The files contain the whole request I want to send."
i am not sure that I get this possible solution right...
- richie4 years agoCommunity HeroHey DavidSEM_Admin,
If youre running ReadyAPI!, you could create an event handler to strip out the empty elements after the data has been extracted from your source but before its injected via your REST request, so you wouldnt have to build the xml using groovy.
For the event handler groovy youd just need to identify the xpath of the attributes you want stripped.
Ta
Rich- DavidSEM_Admin4 years agoOccasional Contributor
HI richie
Thank you for your answer. Could you explain a little more about your idea with the event handler? I am using ReadyAPI 3.3.1.
I did an event handler with the mentioned script in my previous messages in this topic. I did an event "RequestFilter.filterRequest" and it didn't work. What went wrong?
This was the script:
def groovyUtils = new com.eviware.soapui.support.GroovyUtils( context )
def stepName = context.getCurrentStep().getLabel()
def holder = groovyUtils.getXmlHolder(stepName + "#Request")for( item in holder.getDomNodes( "//*[. = '']" )){
holder.removeDomNodes("//"+item.nodeName)
}
Related Content
- 3 years ago
Recent Discussions
- 9 days ago