Forum Discussion
Hi,
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();
log.info("Count before - " + count);
if (count < 10){
log.info(count);
count = count +1;
log.info("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.
Related Content
- 4 years ago
- 12 years ago
- 8 years ago
- 4 years ago
Recent Discussions
- 3 hours ago
- 3 hours ago
- 4 hours ago
- 4 hours ago