Ask a Question

Looping datasources in Groovy

sodonnell
Occasional Contributor

Looping datasources in Groovy

I have 2 datasources in my test the first "DataSourceRESTData" supplies data for builing a REST request but before I execute the REST request I need to validate some of this data against a column in my 2nd data source "DataSourceValidEntries".

 

I want to loop though each row in the "DataSourceValidEntries" to verify the data form "DataSourceRESTData" using Groovy

 

Looping through "DataSourceRESTData" works fine and the the first time the method below is executed... all column entries get printed but on the second loop around only the last value get printed 5250 times.

 

 

boolean isValid(checkifValid){
     //testRunner.testCase.getTestStepByName('DataSourceValidEntries').repositionAtStartRow( testRunner, context)    //Doesn't seem to rest the row number in DataSourceValidEntries
     def ds = testRunner.testCase.getTestStepByName('DataSourceValidEntries')
     
     //def rowsToRead = testRunner.testCase.getTestStepByName('DataSourceValidEntries').size; //This doesn't work so its hard coded below
     def rowsToRead = 5250;
          
	for (row in 1..rowsToRead)
	{
		def colvalue = ds.getPropertyValue('ABC');
		log.info "Column Value: " + colvalue; 
		testRunner.testCase.getTestStepByName('DataSourceValidEntries').next(testRunner, context)

		if(colvalue.equals(checkifValid)){
			log.info "Found: " + checkifValid;
			return true;
		}
	}
	
	return false;
}

 

I've looked at the tips and tricks section for groovy but cant seem to figure this out.

What am I missing?

Regards
Sod

5 REPLIES 5
TanyaYatskovska
SmartBear Alumni (Retired)

Hi,

 

I think you need to reset your second datasouce to the first record after each loop. There might be a special method for this. If you fail to find it, I recommend that you submit a support case so that they could help you. You can submit the case here: http://support.smartbear.com/product-list/

---------
Tanya Yatskovskaya
SmartBear Community and Education Manager



sodonnell
Occasional Contributor

Thanks tried but nothing happened:

 

.repositionAtStartRow( testRunner, context)
TanyaYatskovska
SmartBear Alumni (Retired)

Hi,

Thanks for checking this.

I suggest that you submit the support case anyway – they should help you resolve this.

 

---------
Tanya Yatskovskaya
SmartBear Community and Education Manager



Hi, 

 

I am running into the same issue. was there any resolution on this question?

sodonnell
Occasional Contributor

I didn't get answer on how to do it progammatically but if I found if you right-click on the datasource there is an option to 'Restart Datasource when this step is run'

 

cancel
Showing results for 
Search instead for 
Did you mean: