Forum Discussion

pankajmalinda's avatar
pankajmalinda
Occasional Contributor
6 years ago

Groovy Script to run SOAP test step 2 times

Hi HimanshuTayal    I am trying to execute one SOAP Test step 2 times, I have below script but it seems that it's not working fine.   if( context.loopIndex == null ) context.loopIndex = 0 i...
  • HimanshuTayal's avatar
    6 years ago

    Hi pankajmalinda ,

     

    If the only motive of 1st groovy is to execute SOAP Step 2times then you can use below code:

     

    def SOAPStep = testRunner.testCase.getTestStepByName("Test Step Name");
    
    for(i=0;i<2;i++){
    	SOAPStep.run(testRunner,context);
    }

    If yoy want to execute all below 3 steps then use below code:

     

    def SOAPStep = testRunner.testCase.getTestStepByName("Your Test Step Name");
    def groovyStep1 = testRunner.testCase.getTestStepByName("Your Test Step Name");
    def groovyStep2 = testRunner.testCase.getTestStepByName("Your Test Step Name");
    
    disableTestStep(SOAPStep, "false")
    disableTestStep(groovyStep1, "false")
    disableTestStep(groovyStep2, "false")
    
    for(i=0;i<2;i++){
    	SOAPStep.run(testRunner,context);
    	groovyStep1.run(testRunner,context);
    	groovyStep2.run(testRunner,context);
    }
    
    disableTestStep(SOAPStep, "true")
    disableTestStep(groovyStep1, "true")
    disableTestStep(groovyStep2, "true")
    
    
    def disableTestStep(testStep, disableFlag){
    	if(disableFlag.toLowerCase() == "true"){
    		if( testStep.disabled.toString().trim() == "false" ){
    			testStep.disabled = true
    		}
    	}
    	else{
    		if( testStep.disabled.toString().trim() == "true" ){
    			testStep.disabled = false
    		}
    	}	
    }