Ask a Question

Groovy Script to run SOAP test step 2 times

Occasional Contributor

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
if( ++context.loopIndex < 3 )
testRunner.gotoStepByName( "AuthenticateAndGetUserDetails" )


SOAP Screenshot.png

Super Contributor

What do you mean when you say "but it seems that it's not working fine."? Are there any error messages?


Have you tried adding some log file messages to help trace the flow of the code or tried debugging the Groovy script?


gotoStepByName does not actually run the test step. It tells testRunner what step to run next. AuthenticateAndGetUserDetails is already after the groovy script so that is why it does not run twice. If all you need that groovy script to do is run the test step twice you can remove the if statements and do it with a single line. Just use runTestStepByName(String name) and that will execute the step one time. After the groovy script is finished the test will continue onto the next step and your request will be sent a second time.

Community Hero

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");


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")


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
		if( testStep.disabled.toString().trim() == "true" ){
			testStep.disabled = false

Click "Accept as Solution" if my answer has helped,
Remember to give "Kudos" 🙂 ↓↓↓↓↓

Thanks and Regards,
Himanshu Tayal
SmartBear Alumni (Retired)

Thanks for your help, Community.

@pankajmalinda, do the suggestions help you resolve the issue? Please accept the best answer as a solution

Tanya Yatskovskaya
SmartBear Community and Education Manager

Showing results for 
Search instead for 
Did you mean: