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

groovysoapui

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.

Best Answer

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.

Related Topic