Ask a Question

Looping series of test step using groovy

SOLVED
Gautam
Occasional Contributor

Looping series of test step using groovy

Hi,

 

I am trying to loop series of test steps using groovy scripting. I am using context.getTestRunner().gotoStepByName('HTTPREQUEST') but not much success. The HTTPRequest is looped only once and i am getting the same request and response for the number of times i put the loop.

 

 

 

Capture.PNG

 

Script is not triggering the Request step n number of times but only once and last.

 

Please suggest solution!!

 

Thanks,

Gautam S

 

4 REPLIES 4
rupert_anderson
Valued Contributor

Hi Gautam,

 

Your steps look good e.g. I thought I undertood what you are looking to do... but I can't understand why you need the for loop in your loop step?

 

I might be missing something, but I think all you need to do is check that the currentCount < maxCount if so loop? e.g. no need for for loop, but something like 

 

if (currentCount < maxCount) testRunner.gotoStepByN
ame("GetNextRowAndExractValues")

 

(you'll maybe have to adjust for your variable names)

 

Sorry if I missed something,

 

Cheers,

Rup

Author of SoapUI Cookbook
nmrao
Community Hero

Could not stop asking why currentCount is being read from a property while it can be start from either 1 or 0?

And do not need to increment currentCount inside of for as an explicit statement, instead you could do something like one of the below:

for (int currentCount=0;currentCount < maxCount; currentCount++) {
     //do the stuff here
}

 

or

 

for (int currentCount=1;currentCount <= maxCount; currentCount++) {
     //do the stuff here
}

 

If the above are confusing whether to continue till < or <= or star with 0 or 1, then below is good and groovified too:

 

(0..maxCount).each {
       //do the stuff
}

 

If you are in need with index, then here is your fried:

 

 

(0..maxCount).eachWithIndex { index ->
       //do the stuff, and use index where ever it is needed
}

 


So any of the above methods will automatically loop thru the defined number of times (maxCount)



Regards,
Rao.
Gautam
Occasional Contributor

Hi Rupert and Rao,

 

Thanks for your replies.

@Rupert, yes there was some issue in the currentCount variable as i read it from property it was a string and not integer, so the loop was unsuccessful.

@Rao, i am using the value currentCount to create report in excel and this currentCount is test case number Many test steps depends on this variable so i am trying to get it read from a property. And it is working for my framework

 

I was able to troubleshoot the issue and thanks again for your help.

 

Kudos to both of you!!

 

Thanks & Regards,

Gautam

Hi Gautam,

 

You're welcome! Well done solving the issue, team work! 🙂

 

Cheers,

Rup

Author of SoapUI Cookbook
cancel
Showing results for 
Search instead for 
Did you mean: