cancel
Showing results for 
Search instead for 
Did you mean: 

SOAP UI 5.0-groovy Automation

Highlighted
Occasional Contributor

SOAP UI 5.0-groovy Automation

Hi All,

I have an automation task. I wanted to compare two different soap responses and come with an output.

My 1st soap response will have certain tags like this :

<personId>123</personId>

<mainId>234</mainId>

My 2nd response will have following tags but with same data as in 1st response:

<personIdentification>123</personIdentification>

<mainIdentity>234</mainIdentity>

 

I wanted to compare personId with PersonIdentification and mainID with mainIdentity and so on...

Anyone has a solution for this?

24 REPLIES 24
Occasional Contributor

We have a separate mapping document an excel sheet.. we will see that compare
Highlighted
Community Hero

You can create that mapping from excel sheet into groovy if needed.


Regards,
Rao.
Highlighted
Community Hero

First I request you to try the script with fixed data, then with your responses.


Regards,
Rao.
Highlighted
Occasional Contributor

@nmrao  your code is Perfect 200%

 

I wanted to know this how to fetch nodeNames and parentNodeName if you are given with the nodeValue..

for eg.

<PartyObj>

   <PersonId>123</PersonId>

   <Address>hifiCity</Address>

</PartyObj>

 

Now I have only number 123 and hifiCity (values) with this can I fetch back nodeName and ParentNodeName?

 

Highlighted
Frequent Contributor

It seems you are well on the way to completing this but missing the final step, which should not be dissimilar to the regular approach to data driven testing.  However instead of loading expected values I would load a set a of mappings/bindings.  I would define a properties file that maps one set of names to the other, so taking your table, its contents would something like:  PrimarySourceName = SecondarySourceName.  Then Get the values from each source and use the mapping to get the values for comparison.

 

Mapping.properties file

Placed in the same directory as your project.

basicObj.personId=basicObject.personIdentification
basicObj.personType=basicObject.AdminPersonType
basicObj.addressObj=basicObject.addressObject
basicObj.addressLine=basicObject.address
basicObj.city==basicObject.cityAddress
basicObj.pinCode==basicObject.pin

Load the Properties

 

import com.eviware.soapui.support.GroovyUtils

// location of mapping properties is relative to SOAPUI project file.
def groovyUtils = new GroovyUtils( context )
String mappingFile = groovyUtils.projectPath + "/mapping.properties"

// load the properties
Properties properties = new Properties()
File propertiesFile = new File(mappingFile)
propertiesFile.withInputStream {
    properties.load(it)
}

 

Assuming REST requests are made in previous steps, the responses are retrived

def sourceOneResponse = new XmlSlurper().parseText(requestOne.response)
def sourceTwoResponse = new XmlSlurper().parseText(requestTwo.response)

 

Then loop through the entries and compare values of each

 

for (property in properties) {
	sourceOneName = property.name	
	sourceOneValue = sourceOneResponse.getNodeValue(sourceOneName)
	
	sourceTwoName = property.value
	sourceTwoValue = sourceTwoResponse.getNodeValue(sourceTwoName)
	
	assert sourceOneValue == sourceTwoValue : "${sourceOneName} : ${sourceOneValue} is not equal to ${sourceTwoName} : ${sourceTwoValue}"
}

 

 

 

 

New Here?
Join us and watch the welcome video:
Announcements
Top Kudoed Authors