Forum Discussion

amitst's avatar
amitst
Occasional Contributor
6 years ago
Solved

context.ThreadIndex is always zero in the target test case called through "Run Test Case Step"

I have written following groovy code in the target test case called from a source test case (in a thread-safe way with "create isolated copy for reach run").   testRunner.testCase.testSuite.setPr...
  • JHunt's avatar
    JHunt
    6 years ago

    Here's how you can implement something similar to what the "Run Test Case" test step is doing. In fact, I pinched this from the Source Code in:

    src/main/java/com/eviware/soapui/impl/wsdl/teststeps/WsdlRunTestCaseTestStep.java

    FIrst, add this method to your script :

    import com.eviware.soapui.SoapUI;
    import com.eviware.soapui.impl.wsdl.testcase.WsdlTestCase
    import com.eviware.soapui.config.TestCaseConfig
    import com.eviware.soapui.config.LoadTestConfig;
    
    private WsdlTestCase createTestCase(WsdlTestCase testCase) {
       testCase.beforeSave();
       try {
           TestCaseConfig config = TestCaseConfig.Factory.parse(testCase.getConfig().xmlText());
           config.setLoadTestArray(new LoadTestConfig[0]);
           WsdlTestCase wsdlTestCase = testCase.getTestSuite().buildTestCase(config, true);
           wsdlTestCase.afterLoad();
           return wsdlTestCase;
       } catch (Throwable e) {
           SoapUI.logError(e);
       }
    
       return null;
    }

    And then in the code you posted, replace

    def myTestCase = myTestSuite.getTestCaseByName("Login") 

    by:

    def myTestCase = createTestCase( myTestSuite.getTestCaseByName("Login") )

    This should fix your threading issues!