cancel
Showing results for 
Search instead for 
Did you mean: 

Groovy Script to run SOAP test step 2 times

SOLVED
Highlighted
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

1 ACCEPTED SOLUTION

Accepted Solutions
Super Contributor

Re: Groovy Script to run SOAP test step 2 times

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
		}
	}	
}

Click "Accept as Solution" if my answer has helped, and remember to give "kudos" Smiley Happy

Thanks and Regards,
Himanshu Tayal

View solution in original post

4 REPLIES 4
Super Contributor

Re: Groovy Script to run SOAP test step 2 times

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?

Contributor

Re: Groovy Script to run SOAP test step 2 times

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.

Super Contributor

Re: Groovy Script to run SOAP test step 2 times

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
		}
	}	
}

Click "Accept as Solution" if my answer has helped, and remember to give "kudos" Smiley Happy

Thanks and Regards,
Himanshu Tayal

View solution in original post

Community Manager

Re: Groovy Script to run SOAP test step 2 times

Thanks for your help, Community.

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

---------
Tanya Gorbunova
SmartBear Community Manager

Did my reply answer your question? Give Kudos or Accept it as a Solution to help others.↓↓↓↓↓