Ask a Question

How to validate response using script assertion when the Rest Response has multiple nodes?

saradhipb
Occasional Contributor

How to validate response using script assertion when the Rest Response has multiple nodes?

Trying to perform an End to End Test using readyapi/soap ui pro, if any solution please advise..

  • I have rest URI as http:localhost/DataRequest1/DataRequest2/DataRequest3. All the Data request I have created as a Template.
  • I created a test step 'Data Source' & 'Data Source Loop' and passed data.
TestCaseStatusDataRequest1DataRequest2DataRequest3Response1Response2
 A001B001C001D001E001
 A002B002C002D002E002
 A001B001C001D003E003
 A002B002C002D004E004
 A001B001C001D005E005
 A002B002C002D006E006
  • In response I have getting response in below JSON if I perform 1st Step as Rest request

Reuest URI: http:localhost/A001/B001/C001.

Response JSON:

[
{

"DataRequest1": "A001",
"DataRequest2": "B001",
"DataRequest3": "C001",
"Response1": "D001",
"Response2": "E001"
},
{

"DataRequest1": "A001",
"DataRequest2": "B001",
"DataRequest3": "C001",
"Response1": "D003",
"Response2": "E003"
},
{

"DataRequest1": "A001",
"DataRequest2": "B001",
"DataRequest3": "C001",
"Response1": "D005",
"Response2": "E005"
}
]

 

As you see on the above I get multiple responses on a request. My challenge is to validate whether I am getting the response correctly or not in form of Script Assertion and store it as a TestCaseStatus for each iteration from the Data Source Step and validate the response with property response on Data Source Step.

 

Any suggestions please?

7 REPLIES 7
nmrao
Community Hero

Re: How to validate response using script assertion when the Rest Response has multiple nodes?

May be you can use below one for reference and implement your own.

http://stackoverflow.com/questions/31472381/dynamically-compare-rest-xml-json-response-and-jdbc-usin...


Regards,
Rao.
saradhipb
Occasional Contributor

Re: How to validate response using script assertion when the Rest Response has multiple nodes?

Hi Rao,

 

I have a challenge here in building JDBC request, I am using Mongo Client and there is no inbuilt JDBC congiguration for MongoDB.

 

My expectations are listed in the DataSource step. I have to compare the JSON response with respective to Data Source Step.

 

 

Regards,

Saradhi

nmrao
Community Hero

Re: How to validate response using script assertion when the Rest Response has multiple nodes?

Is not the question about compring the results from jdbc and another request step response?


Regards,
Rao.
nmrao
Community Hero

Re: How to validate response using script assertion when the Rest Response has multiple nodes?

In that case, you need to download the respective client library and add it to READYAPI_HOME/bin/ext directory.

In the connection string use the mango documentation.
Good luck.


Regards,
Rao.
saradhipb
Occasional Contributor

Re: How to validate response using script assertion when the Rest Response has multiple nodes?

Hi Rao,

 

I have downloaded and placed the files in the respective directory. 

 

I have written groovy script (Named the script as Script1) for retrieving values from Database. I added one more groovy script and trying to access the response from the groovy script in the new script, but I was getting 'null' value.

 

Any suggestions please.

 

 

 

saradhipb
Occasional Contributor

Re: How to validate response using script assertion when the Rest Response has multiple nodes?

I tried to put everything in the same script, now challenge arises on assertion. I am not able to compare below database and rest responses getting assertion failed. Please advise.

 

Database Groovy Script response

{
"_id" : {"$oid" : "57560fb04c4013fef4e31d20"} ,
"Datarequest1" : "A001" ,
"Datarequest2" : "B001" ,
"Datarequest3" : "C001" ,
"Response1" : "D001" ,
"Response2" : "E001"
}
{
"_id" : {"$oid" : "57560fb04c4013fef4e31d20"} ,
"Datarequest1" : "A001" ,
"Datarequest2" : "B001" ,
"Datarequest3" : "C001" ,
"Response1" : "D003" ,
"Response2" : "E003"
}

{
"_id" : {"$oid" : "57560fb04c4013fef4e31d20"} ,
"Datarequest1" : "A001" ,
"Datarequest2" : "B001" ,
"Datarequest3" : "C001" ,
"Response1" : "D005" ,
"Response2" : "E005"
}

REST Response:
[{"id":"57560fb04c4013fef4e31d20",
"Datarequest1":"A001",
"Datarequest2":"B001",
"Datarequest3":"C001",
"propertyKey":"D001",
"propertyValue":"E001"
},
{"id":"57560fb04c4023fef4e31d20",
"Datarequest1":"A001",
"Datarequest2":"B001",
"Datarequest3":"C001",
"propertyKey":"D003",
"propertyValue":"E003"},
{"id":"5761aa6a02d875aeb096bc22",
"Datarequest1":"A001",
"Datarequest2":"B001",
"Datarequest3":"C001",
"propertyKey":"D005",
"propertyValue":"E005"}]

saradhipb
Occasional Contributor

Re: How to validate response using script assertion when the Rest Response has multiple nodes?

I tried to put everything in the same script, now challenge arises on assertion. I am not able to compare below database and rest responses getting assertion failed. Please advise.

 

Database Groovy Script response

{
"_id" : {"$oid" : "57560fb04c4013fef4e31d20"} ,
"Datarequest1" : "A001" ,
"Datarequest2" : "B001" ,
"Datarequest3" : "C001" ,
"Response1" : "D001" ,
"Response2" : "E001"
}
{
"_id" : {"$oid" : "57560fb04c4013fef4e31d20"} ,
"Datarequest1" : "A001" ,
"Datarequest2" : "B001" ,
"Datarequest3" : "C001" ,
"Response1" : "D003" ,
"Response2" : "E003"
}

{
"_id" : {"$oid" : "57560fb04c4013fef4e31d20"} ,
"Datarequest1" : "A001" ,
"Datarequest2" : "B001" ,
"Datarequest3" : "C001" ,
"Response1" : "D005" ,
"Response2" : "E005"
}

REST Response:
[{"id":"57560fb04c4013fef4e31d20",
"Datarequest1":"A001",
"Datarequest2":"B001",
"Datarequest3":"C001",
"propertyKey":"D001",
"propertyValue":"E001"
},
{"id":"57560fb04c4023fef4e31d20",
"Datarequest1":"A001",
"Datarequest2":"B001",
"Datarequest3":"C001",
"propertyKey":"D003",
"propertyValue":"E003"},
{"id":"5761aa6a02d875aeb096bc22",
"Datarequest1":"A001",
"Datarequest2":"B001",
"Datarequest3":"C001",
"propertyKey":"D005",
"propertyValue":"E005"}]

cancel
Showing results for 
Search instead for 
Did you mean: