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.setPropertyValue("token" + context.ThreadIndex);
The source test case uses the tokenNUM variable while sending its request.
I have noticed that when running as a LoadTest with multiple threads, the called test case is always setting token0 variable in the test suite level. While the source test case is trying to use token1, token2, .... etc. variables through each thread.
Is it possible to pass/set ThreadIndex based variables from called test case nased on the ThreadIndex of the caller?
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!