Search code examples
groovysoapui

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.


Solution

  • 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.