Forum Discussion

Mohan_hbk's avatar
Mohan_hbk
Occasional Contributor
6 years ago

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?

    • ShasiSingh's avatar
      ShasiSingh
      Occasional Contributor

      You can use the xml parser to do the same.

      //eg response 1:

      File OrginalFile = new File(FilenameAsInputXmlFile);
      def String FetchXmlData = OrginalFile.getText();
      def response = new XmlSlurper().parseText(FetchXmlData)

      def firstreqvalue=response.YourTagname[0]

       

      //eg response 2:

      File OrginalFile2 = new File(FilenameAsInputXmlFile);
      def String FetchXmlData2 = OrginalFile.getText();
      def response2 = new XmlSlurper().parseText(FetchXmlData)

      def firstreqvalue2=response2.YourTagname[0]

      if(response2 ==response){

      //your code

      }

       

  • Mohan_hbk's avatar
    Mohan_hbk
    Occasional Contributor


    My testing work is completely in SOAPUI. In that when I hit an wsdl with request Message I will be getting an response soap message.

    For example

    Consider two wsdl links I have.

    I have an id, if I hit the request message for those two wsdl with the same id in SOAPUI separately, I will get two SOAP responses separately.

     

    Now coming to my problem:

    In groovy script I wanted to check whether data present in wsdl1's response matches with the wsdl2's response.

    I am able to get the SOAP responses individually in groovy script also.

    Now I wanted to compare these responses, in which nodeNames are diffferent for the same nodeValues. How sholud I proceed?

    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>

    <classification>P</classification>

     

    If u see the above two responses personId(from 1st response)and personIdentification(from 2nd response) have same data, I wanted to compare these nodeValues(but different nodeNames) individually and get a result. True or False 

    • ShasiSingh's avatar
      ShasiSingh
      Occasional Contributor

      As you have Mentioned You have 2 WSDL. So you have to create 2 test suite, each is related to corresponding operations, I am assuming Old service vs new Services.

       

      In your First test suite ( Old ), you can add test cases which can have a groovy test step. that step will save Responses to the local system.

       

      eg..

              def outPutFileLocationRes01="C://TestSection//Res01.xml";
      	def response = context.expand( '${testCaseNameOfYourService#Response}' )
      	def f = new File(outPutFileLocationRes01)
      	f.write(response, "UTF-8")
      	log.info "Responses is save in local :"+outPutFileLocationRes01

      In your Second test suite ( New ), you can add test cases which can have a groovy test step. that step will save Responses to the local system.

       

      eg..

              def outPutFileLocationRes02="C://TestSection//Res02.xml";
      	def response = context.expand( '${testCaseNameOfYourService#Response}' )
      	def f = new File(outPutFileLocationRes02)
      	f.write(response, "UTF-8")
      	log.info "Responses is save in local :"+outPutFileLocationRes02

      Once Both Operations is Compleated Either you can create a new project to use the existing project to make new testSuite , That suite should have testcase along with  testStep groovy Script

       

      Where you can write the read the both responses (new and old) from local system and parse to as xml, read entire XML and do the validations.

       

      eg.. (below example is just considering one tag) Please share your responses next time for more insight.

       

              FilenameAsInputXmlFileRes01="C://TestSection//Res01.xml"
      	File OrginalFile01 = new File(FilenameAsInputXmlFileRes01);
      	def String FetchXmlData01 = OrginalFile01.getText();
      	def response01 = new XmlSlurper().parseText(FetchXmlData01)
      	String personId=response01.personId;
      	
      	
      	FilenameAsInputXmlFileRes02="C://TestSection//Res02.xml"
      	File OrginalFile02 = new File(FilenameAsInputXmlFileRes02);
      	def String FetchXmlData02 = OrginalFile02.getText();
      	def response02 = new XmlSlurper().parseText(FetchXmlData02)
      	String personIdentification=response02.personIdentification;
      	
      	
      	if(personId.trim()==personIdentification.trim())
      	{
      			log.info "Both Tags Values are same -> personId : [ "+ personId + " ] [ personIdentification : [  " + personIdentification + " ]"
      			//return true;
      	}else{
      			log.info "Both Tags Values are Not same -> personId : [ "+ personId + " ] [ personIdentification : [  " + personIdentification + " ]"
      			//return false;
      	}

       

       

       

      • Mohan_hbk's avatar
        Mohan_hbk
        Occasional Contributor
        Thanks a lot I dint expect this.. But one more thing what if you dont know what tagNames will come in each response personid and personIdentification I gave as an example many such tags will come home to traverse and compare now?
    • nmrao's avatar
      nmrao
      Champion Level 3
      Please look at my previous reply and respond accordingly.