cancel
Showing results for 
Search instead for 
Did you mean: 

SOAP UI 5.0-groovy Automation

Occasional Contributor

Re: SOAP UI 5.0-groovy Automation

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

Re: SOAP UI 5.0-groovy Automation

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


Regards,
Rao.
Community Hero

Re: SOAP UI 5.0-groovy Automation

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


Regards,
Rao.
Occasional Contributor

Re: SOAP UI 5.0-groovy Automation

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

 

Frequent Contributor

Re: SOAP UI 5.0-groovy Automation

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:
Top Kudoed Authors