Snehas Das
Snehas Das

Reputation: 53

How to stop infinite loop while executing Test Case in soapUI using Groovy Script

Below code is a part of my groovy script which executes a test case in soapUI.

def testCase = testRunner.testCase.testSuite.testCases["TestCase"];  
def properties = new com.eviware.soapui.support.types.StringToObjectMap();  
def async = false;  
testCase.run(properties, async);

After executing this code, test case execution started normally but it's not stopping. Suppose there are 13 test step inside the test case. Once I run that groovy script, it started from 1 to 13 and again from 1 to 13 and so on. until I close the whole soapUI application.

is there any way to break the loop?

Thanks in advance.

Upvotes: 2

Views: 9209

Answers (4)

grinosn
grinosn

Reputation: 1

Create a condition in properties, for instance continueLoop with a boolean value true. Check if the value is true in your script. When you want the script to stop, change the value to false.

Upvotes: 0

Roberto
Roberto

Reputation: 1

I used

testRunner.testCase.getTestStepByName("teste").setDisabled(false); //enabled
testRunner.testCase.getTestStepByName("teste").setDisabled(true); //disabled

Upvotes: 0

J E Carter II
J E Carter II

Reputation: 1496

Strictly speaking, you can not stop a running script with something like a "break" key. As the accepted answer did not make that abundantly clear, I thought it worth pointing out to spare others a fruitless search.

As the Groovy Script is running in some anonymous jvm worker thread, your only hope with the tool at present would be to find the active thread and terminate it and hope the tool recovered gracefully. I've tried attaching a JIT debugger but it didn't prove to be helpful. I wound up restarting the tool and rewriting the unsaved portions of my script.

A good rule of thumb for writing loops is to test with a conditional break.

def i = 0;

for (foo in bar){

    // do stuff

    if(i>1){ break }
}

If your script stops responding, it's worth noting that it may not necessarily be in an infinite loop but may be having memory problems. This is the second reason I posted this answer.

You can check this post for ways to optimize SOAPUI test cases for memory useage. It tends to get hungry. http://www.soapui.org/working-with-soapui/improving-memory-usage.html

Specifically, close any open Request and Response windows that may get updated by a loop in your script. The cost to redraw these can bury the SOAPUI client quickly in a loop.

Upvotes: 1

Abhishek Asthana
Abhishek Asthana

Reputation: 1855

Lets say you want to run "Test Case 1" which has multiple steps (13 in your case). It also has a groovy step "G1" (test index 1) from where you are initiating the test execution. What happens when you run the test Case from G1 is the test case executes its test steps 1 by one and as soon as it reaches G1 it start executing again because that's what you are doing in that step. Hence you end up with an infinite loop.

What you should do is keep the step that starts the execution out of the test case that has to be executed. Traditionally such a script is called a driver script and is either a separate test case or outside the application itself.

To solve your problem you could do one of the following.

1. Disable the step G1 from where you are starting the execution so that when the test runner cycles through all the steps in the test case it'll skip G1 because it is disabled and you'll escape the infinite loop.

2. Alternatively you can use the below code instead of what you have.

def project = testRunner.testCase.testSuite.project
testRunner.runTestStep(project.testSuites["TestSuite 1"].testCases["TestCase 1"].testSteps['delete'])

Let me know if this worked for you.

Upvotes: 0

Related Questions