Ask a Question

Running test step multiple times to add records

Frequent Visitor

Running test step multiple times to add records


I'm new to Readyapi. I want run a test step multiple times to create multiple records.
I have used following groovy script but test step has not been ran multiple times. 

if( context.loopIndex == null )
context.loopIndex = 0
if( ++context.loopIndex < 10 )
testRunner.gotoStepByName( "Name of TestStep to run n times" )


Can someone please suggest if the script is wrong or I need to add anything more

Many Thanks in advance

Community Leader



It looks like your code says.... If the count is less than 10, then go to some other step in the script.


The key bit is "testRunner.gotoStepByName".  This will move the test runner to that step, leapfrogging any steps between that and the groovy step and won't come back.


I've knocked up a simple loop that will call a step 10 times.  In order for this to work, you need to call the record creation step at least once before checking loop.  Think while loop over for loop.


Here's what my test looks like.  You need to create a test case property called 'count'.




Here are the contents of Initialise...

testRunner.testCase.setPropertyValue("count", "0");


The Rest request step just pings the BBC website and should be replaced with your step to create a record.


Lastly, the loop step.  In here we test the count property and if less than 10, increment the count and go back to the rest step.

// Get a test case property
def count = testRunner.testCase.getPropertyValue("count").toInteger();"Count before - " + count);

if (count < 10){;
	count = count +1;"Count after - " + count);
	testRunner.testCase.setPropertyValue("count", count.toString());
	testRunner.gotoStepByName( "Call BBC Website - REST Request");


Note the calls to toInteger() and toString().  The Test Case Property is a string value pair.  You need to convert to int before use and write back as a string.




Community Hero


If ReadyAPI is used, then data source step is the preferred option.

SmartBear Alumni (Retired)

Thanks everyone for helping!


@Tambu did the replies help? Please mark the best one as a Solution.

Sonya Mihaljova
Community and Education Specialist

Showing results for 
Search instead for 
Did you mean: