Get all Nodes Names and values from a test case Response
SOLVED- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Get all Nodes Names and values from a test case Response
Hello @All,
i am trying to retrieve Node names and values from a SOAP response received by a webservice's method that I test.
Here is my code and I attach the output as a file:
import groovy.util.XmlSlurper;
import groovy.util.slurpersupport.*;
// create groovyUtils and XmlHolder for response of the request
def groovyUtils = new com.eviware.soapui.support.GroovyUtils(context);
def requestResponse = groovyUtils.expand('${CheckSdcAuthorisation[8.2]#Response}');
def holder = groovyUtils.getXmlHolder(requestResponse);
def parseResponse = new XmlSlurper().parseText(requestResponse);
def allNodeValues = holder.getNodeValues("//*");
// loop item nodes in response message
for( item in allNodeValues){
log.info "Item : [$item]"
}
The issue is that I'm not able to get node names and corresponding values. I do not understand why the for loop does not return Node values as expected? Also what code should I change to replace Item by the name of the node?
Do you have any suggestion to solve my issue?
Solved! Go to Solution.
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
When I ran this against two of my responses that were different, it outlined if there were differing nodes, differing text, etc. I am not sure if it creates an array or not, but the log statement displayed an entire list of differences for me.
---
Click the Accept as Solution button if my answer has helped, and remember to give kudos where appropriate too!
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
This is beautiful and really helpful library and script to use to achieve my purpose. This is nice because when I export the log as a file, all differences are really well presented and understanding XPath language it's easy to find which nodes does not match.
Now, I think I have to find an additionnal piece of code to export this file automatically if there is at least one difference (the reading of differences is really complicated from the console).
Also if you have any idea how I could ignore some differences for example (prefixes and namespaces which change or different businness object which are not the same because of business logic, for instance IDs, etc).
I will mark your answer as the solution because it is really what I was looking for. I just have to work on the script to improve it and find a way to ignore the differences which would due to business logic.
Thanks for sharing this script @groovyguy
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
If you want the Diff output to a file, that's easy enough to do. I can fix that up here in a bit.
As for ignoring namespace differences, that may be distinctly harder and requires overloading the XMLUnit class. I am not sure I can help with that but I'll see what I can find.
As for the business logic, that's something you would have to define. It may be easier to ignore those after the fact then try to account for all of them?
---
Click the Accept as Solution button if my answer has helped, and remember to give kudos where appropriate too!
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
To fix prefix names and namespaces what I could do is create another groovy script with regular expressions to transform elements in the response to correspond to what I want. Thanks to this script, it would only remain differences introduce by business logic and real differences.
Sorry but, I did not get your suggestion about business logic in your last message, but I imagine that it's the same idea as refactoring the XMLUnit class to suit the need, isn't it?
What do you think about the idea to ignore namespaces?
If you could share the line to export it to a log file instead of displaying in the console log, it would be really nice!
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
First, let's do the output to a file. Append this to your script at the end:
// Use whatever file / location works for you def fileOut = new File ('c:/temp/diff.txt'); // I had to convert myDiff to a string to write to a file. It keeps the formating as far as I can tell. fileOut.write (myDiff.toString());
Now, for the other part with namespaces and business rules. What I was reading this morning is that you would have to start building overloaded functions for XMLUnit class to refactor it to do what you want. Here is one example I found on stack overflow:
https://stackoverflow.com/questions/26524286/xmlunit-ignore-xmlns
That seems a solid theory on ignoring namespaces. The complex part may be writing something similar to ignore specific elements, but it may be doable?
---
Click the Accept as Solution button if my answer has helped, and remember to give kudos where appropriate too!
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks you for this!
I changed a little bit the code you provided to write the file to the folder of my project path! It works fine!
Now I have to read in details the article on stackoverflow to perform the business and namespaces/prefixes exceptions. I take a look on this and I will give you a feedback asap!
def groovyUtils=new com.eviware.soapui.support.GroovyUtils(context) def projectPath = groovyUtils.projectPath def fileOut = new File (projectPath+'/logOutput.log'); fileOut.write (myDiff.toString());
The code for overriding the class seems to not be so complicated but how should I integrated to the groovy script, or where should I look in my computer in order to override it, should I modify the code from the native class so?
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
My issue is, I have two SOAP responses I wanted to compare node values in one response with other Soap response. Problem I am facing is Nodenames are different but data present in nodes are same.How can I compare? will xmlunit help solving this?
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
@Mohan_hbk : You may want to consider starting your own thread with details specific to your question and problem at hand. 🙂
---
Click the Accept as Solution button if my answer has helped, and remember to give kudos where appropriate too!

- « Previous
-
- 1
- 2
- Next »
- « Previous
-
- 1
- 2
- Next »