Ask a Question

Verify multiple rows and then data drive

SOLVED
endorium
Frequent Contributor

Verify multiple rows and then data drive

First off I am new to Soup/ReadyAPI. 

I have an API that returns row information for a grid.

I have assertions for the count of rows and the first row. I am also verifying the data against an excel sheet which is all working fine.

 

The problems comes when I add more than one row of data in the excel sheet as i want to validate multiple rows. I cannot get this to work. Ideally I want to validate 3 rows on each run looking at the same excel sheet.

Any ideas how I do this? Eventually I want to datadrive this as well.

 

Screenshots of assertions and data returned plus excel sheet.

 

Ready.PNGexcel.PNG

45 REPLIES 45

The excel you attached has 2 rows. You said that you have an excel with 3 rows. Please attach me that one. I will try to look into it tonight. No promises though. Quite busy at work now...



If my answer helped please click on the 'Accept as Solution' button.
endorium
Frequent Contributor

Ok, it should not matter how many rows though should it?  I have attached a file with three rows.

I will also keep looking as well 🙂

Thanks again

 

 

It should not matter. It's just that I want to use the same data as you use so I can better see why it's failing for you.

 



If my answer helped please click on the 'Accept as Solution' button.
Lucian
Community Hero

Ok, first things first. Please notice that your excel starts with the Id = 0 while the response starts with Id = 1.

 

Nevertheless my script was wrong. Here you have the same script with some corrections and logs added to it:

 

import groovy.json.JsonSlurper

// Get the id from the datasource
def id = context.expand('${DataSource#ID}') as Integer
log.info "The id collected from the datasource is '" + id + "'." 

// Get the response from the GetResponse step
def response = context.expand('${GetResponse#Response}')

// Parse the response with JsonSlurper
def jsonSlurper = new JsonSlurper()
def jsonObject = jsonSlurper.parseText( response )

// Get the element where the ID is the same as in the datasource
log.info "Trying to find the element with id " + id + " in response..."
for (item in jsonObject.value) {
	if (item.Id == id) {
		log.info "Element found. Comparing the datasource data with the response data..."
		
		// Start comparison
		log.info "The TestID value collected from the datasource is '" + context.expand('${DataSource#TestId}') + "' while the response value is " + item.TestID + "'."
		assert item.TestID.equals( context.expand('${DataSource#TestId}'))

		log.info "The TestName value collected from the datasource is '" + context.expand('${DataSource#TestName}') + "' while the response value is '" + item.TestName + "'."
		assert item.TestName.equals( context.expand('${DataSource#TestName}'))

		log.info "The Assays value collected from the datasource is '" + context.expand('${DataSource#Assay}') + "' while the response value is '" + item.Assays + "'."
		assert item.Assays.equals( context.expand('${DataSource#Assay}'))

		log.info "The Analyses value collected from the datasource is '" + context.expand('${DataSource#Analyses}') + "' while the response value is '" + item.Analyses + "'."
		assert item.Analyses.equals( context.expand('${DataSource#Analyses}'))

		log.info "The Cassettes value from the datasource is '" + context.expand('${DataSource#Cassettes}') + "' while the response value is '" + item.Cassettes + "'."
		assert item.Cassettes.equals( context.expand('${DataSource#Cassettes}'))

		log.info "The Enabled value from the datasource is '" + context.expand('${DataSource#Enabled}') + "' while the response value is '" + item.Enabled + "'."
		assert item.Enabled == context.expand('${DataSource#Enabled}').toBoolean()

		log.info "The UserDefined value from the datasource is '" + context.expand('${DataSource#UserDefined}') + "' while the response value is '" + item.UserDefined + "'."
		assert item.UserDefined == context.expand('${DataSource#UserDefined}').toBoolean()
	}
}


If my answer helped please click on the 'Accept as Solution' button.
endorium
Frequent Contributor

Thank you Lucian. I have had a good look and learnt lots from this.

It executes and passes (when it should).

 

This really has been a massive help and I have learned more in a week off your replies than I could of in a month on my own.

 

Thanks again.

Glad I could help.

If this issue is solved by my comment just please hit 'Accept as a solution' on my answer. This can help others who are searching for answers.


If my answer helped please click on the 'Accept as Solution' button.
cancel
Showing results for 
Search instead for 
Did you mean: