Forum Discussion
SmartBear_Suppo
12 years agoSmartBear Alumni (Retired)
Hi again Sarat,
I once again apologize for keeping you waiting. Here's my solution:
Structure your test case like this:
In the first step, "Read Excel DataSource", create a data source using your excel data file and save each customer's name (or ID, or whatever you want to validate) in a property (In my example I've called it "name").
In the second step, run the following script in the "Add name to list" step:
This creates a list in the context object so that we can access it later, and enters the current "name" property into it.
We want to fill this list with all the customer names, so we add a "DataSource Loop" using the excel file and with the groovy test step as the target.
Then, after performing your "REST request" and receiving a response, we want to check that all the customers exist in this aforementioned list (that we built using the excel data source). In order to do this we use a second groovy script (the "Validate names" step), utilizing the JsonSlurper class (http://groovy.codehaus.org/gapi/groovy/ ... urper.html).
Here's a quick (untested) groovy snippet that should work:
I hope this helps. Normally we don't support groovy, but I made an exception in this case. Let me know if you have any further questions!
Regards,
Arian
SmartBear Sweden
I once again apologize for keeping you waiting. Here's my solution:
Structure your test case like this:
In the first step, "Read Excel DataSource", create a data source using your excel data file and save each customer's name (or ID, or whatever you want to validate) in a property (In my example I've called it "name").
In the second step, run the following script in the "Add name to list" step:
if ( context["allRows"] == null )
context["allRows"] = []
context["allRows"] << context.expand('${Read Excel DataSource#name}')
This creates a list in the context object so that we can access it later, and enters the current "name" property into it.
We want to fill this list with all the customer names, so we add a "DataSource Loop" using the excel file and with the groovy test step as the target.
Then, after performing your "REST request" and receiving a response, we want to check that all the customers exist in this aforementioned list (that we built using the excel data source). In order to do this we use a second groovy script (the "Validate names" step), utilizing the JsonSlurper class (http://groovy.codehaus.org/gapi/groovy/ ... urper.html).
Here's a quick (untested) groovy snippet that should work:
import groovy.json.JsonSlurper
def nameList = context["allRows"]
def responseString = context.expand( '${REST request#Response}' )
def slurper = new JsonSlurper()
def response = slurper.parseText(responseString)
for (customer in custProfile.custProfileList)
assert nameList.contains(customer.custRefNm)
I hope this helps. Normally we don't support groovy, but I made an exception in this case. Let me know if you have any further questions!
Regards,
Arian
SmartBear Sweden