1

I am currently setting up some REST API tests. I have a test case that has the following Steps:

  1. Data Source - Get all Auth credentials in database
  2. REST Request - Auth POST getting auth token components
  3. Groovy Script - Create Auth token variable in test case properties
  4. Data Source - Get expected information from database
  5. REST Request - Account information GET
  6. Data Source - Get Json response from GET Request step (step 5) and put it into table form.
  7. Assertion - Compare data source table from step 4 + 6
  8. Data Loop - Loop back to step 2

I am currently having issues with step 7. I have the expected table from step 4 which is in the form of column; [id][name] with varying rows depending on the account logged in. Then I have the table in the same format from step 6.

What is the best way to compare that these two tables and assert whether they have the same data in them. So I need to loop through each row and match it to the other table. Both tables will be sorted by id so they will be in the same order.

I have tried the assertion test step, however that only seems to assert the first row in both tables.

2 Answers 2

0

My suggestion here would be a 'script assertion'. A script assertion allows you to use Groovy script or Java to create your own custom assertion.

Within such a step you can 'pull in' data from another step and assign the data to a variable. In your script, right-click and select 'Get Data'.

So, I use 'Get Data' to get data from another step and use XML Slurper (loads of examples on Stack Overflow) to be able to iterate over the data. Also within the script assertion, I use JDBC to pull data from the db. With scripting, I can then compare each item from the API response with the db response to decide whether it is a pass of a fail.

0

I would say write an assertion groovy script to get the data from Response and compare it with the values at your data source.

import net.sf.*;
import net.sf.json.*;
import net.sf.json.groovy.*;
import net.sf.json.groovy.JsonSlurper
def groovyUtils = new com.eviware.soapui.support.GroovyUtils(context)

//Getting response from methods
def response = context.expand( '${Request 1#Response}' ).toString()

def slurper = new JsonSlurper()
def json = slurper.parseText response
def countryList = json.result.country

In here I have my response as countryList.

Like this read the data from your data source and assert it within the groovy script.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.