Forum Discussion

PriyeshS's avatar
PriyeshS
New Member
11 years ago

Loop extending in the last run

I am facing issues with a script i have created for looping through the test steps. The script - 

 

def count = context.expand( '${RequestData#Count}' )
//log.info count
import java.math.*;
def groovyUtils = new com.eviware.soapui.support.GroovyUtils(context);
def j
def x=count.toInteger()
def CountNew = count.toBigDecimal();
log.info CountNew
def Addition= 1
Count=CountNew.add(Addition)
groovyUtils.setPropertyValue("RequestData", "Count", Count.toString())
log.info Count

for(j=x; j<10; j++)
{
if(j<10)
{
testRunner.runTestStepByName("teststep1");
testRunner.runTestStepByName("teststep2");
.

.

.

.

.

.

break;
}

}

 

The issue is that even after reaching the max value for the looping vaiable, teststep2 is being executed.

 

Any help is really appreciated.

1 Reply

  • nishantna's avatar
    nishantna
    Occasional Contributor

    You may use following script instead:

    import com.eviware.soapui.impl.wsdl.testcase.WsdlTestRunContext
    presentIndex=context.getCurrentStepIndex()
    def count=testRunner.testCase.getTestStepCount()
    for(index=0;index<count;index++)
    {
     if(index!=presentIndex)
     {
    	 testStep=testRunner.testCase.getTestStepAt(index)  
    	 WsdlTestRunContext testRunContext=new WsdlTestRunContext(testStep) 
    	 log.info testStep.run(testRunner,testRunContext)
     }
    }

     The only thing you need to do is to place it as any one of the test steps and run this script, it will automatically run remaining test steps.

    As far as the problem with your code is concerned, i would say that you should check placing your script as the last step, and then see what happens.