cancel
Showing results for 
Search instead for 
Did you mean: 

Get all Nodes Names and values from a test case Response

SOLVED
Highlighted
Community Hero

Re: Get all Nodes Names and values from a test case Response

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!
Highlighted
Contributor

Re: Get all Nodes Names and values from a test case Response

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 @msiadak

Highlighted
Community Hero

Re: Get all Nodes Names and values from a test case Response

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!
Highlighted
Contributor

Re: Get all Nodes Names and values from a test case Response

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! 

Highlighted
Community Hero

Re: Get all Nodes Names and values from a test case Response

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!
Highlighted
Contributor

Re: Get all Nodes Names and values from a test case Response

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?

Highlighted
Occasional Contributor

Re: Get all Nodes Names and values from a test case Response

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?

Highlighted
Community Hero

Re: Get all Nodes Names and values from a test case Response

@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!
New Here?
Join us and watch the welcome video:
Announcements
Top Kudoed Authors