This all feels very progressive! It's the first time I've tried something like this, but I'm glad I did!
Anyway, as per your suggestion, I now generate a new Groovy script step. I'm using a String method to return the specific script I want, and then calling that as a parameter in my script creation step, a la:
import com.eviware.soapui.impl.wsdl.teststeps.registry.GroovyScriptStepFactory
import com.eviware.soapui.impl.rest.RestResource;
import com.eviware.soapui.impl.wsdl.teststeps.registry.RestRequestStepFactory
import com.eviware.soapui.config.TestStepConfig
import com.eviware.soapui.impl.rest.RestRequest;
import com.eviware.soapui.impl.rest.RestService;
listOfTestCases = [
'Address Lookup with valid PostCode',
'Address Lookup with Valid CompanyName',
'Address Lookup with Valid Street',
'Address Lookup with Valid town',
'Address Lookup with Valid CompanyName & Postcode',
'Address Lookup with Valid Street & Postcode',
'Address Lookup with Valid Town & PostCode',
'Address Lookup with Valid CompanyName & Street',
'Address Lookup with Valid CompanyName & Town',
'Address Lookup with Valid Street & Town',
'Address Lookup with Valid Postcode, CompanyName, Street & Town']
for (String testCase : listOfTestCases) {
tc = context.testCase.testSuite.addNewTestCase(testCase)
tc.addProperty("testcycl-id")
tc.addProperty("cycle-id")
tc.addProperty("test-id")
tc.addProperty("run-id")
tc.addProperty("test-config-id")
tc.addProperty("test-step-id")
tc.addTestStep("groovy", "Set request headers").setScript(requestHeaderMethodText())
// ... other code here
}
}
// Store my groovy script as a String so it can be called in the test //generation script.
def String requestHeaderMethodText(){
return "import java.net.InetAddress;" + " \n" +
"def currentTimeInMillis = System.currentTimeMillis().toString()" + " \n" +
"ipAddress = InetAddress.getLocalHost();" + " \n" +
"testRunner.testCase.setPropertyValue( 'cleId', currentTimeInMillis)" + " \n" +
"testRunner.testCase.setPropertyValue( 'userIp', ipAddress.getHostAddress().toString())" + " \n"
}