Forum Discussion

Gautam's avatar
Gautam
Occasional Contributor
10 years ago

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...
  • rupert_anderson's avatar
    10 years ago

    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

  • nmrao's avatar
    10 years ago

    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)