Reputation: 871
I am new to SoapUI and have run into an issue I do not understand. Goal: I want to pass a result from one Groovy script into another Groovy script in a different test step.
Step 1: I have a Groovy script that generates a GUID:
// generate a new GUID
def guidVal = "${java.util.UUID.randomUUID()}"
Step 2: I have a property transfer step that takes the result of the above script and passes it into an HTTP request step (that is working)
Step 3: I have a second Groovy script that runs a curl command where I need to include the same GUID.
def deviceGuid = testRunner.testCase.testSteps['Property Transfer'].getPropertyValue("result")
// run the following curl command to generate certs
def command = 'C:\\Program Files (x86)\\Git\\usr\\bin\\curl -v -H "Content-type: application/json" -X POST -d "{\"deviceId\": \"<NEED GUID HERE>\" }" http://localhost:49742/register > out.zip'.execute().text
Step 3 is where the problem starts. How do I the resulting GUID from the first script and place it into the second Groovy script? At runtime at the moment the above returns
Wed Mar 16 13:46:37 EDT 2016:INFO:null
Upvotes: 1
Views: 873
Reputation: 21369
Here is the simple thing you can do.
Since the uuid
value is used in the same test case, the value generated in first step can be saved at test case level property, say UUID, by adding the below command in the first step(add at the end):
context.testCase.setPropertyValue('UUID', guidVal)
Now the second step i.e., property transfer becomes obsolete as the value is available in the test case level property using the above step.
In the next groovy step, just use one of the following statement to get the uuid
value back from test case property.
def deviceGuid = context.testCase.getPropertyValue('UUID')
ordef deviceGuid = context.expand('${#TestCase#UUID}')
And regarding the device id replacement in the command, here is the changed command which need to escape the letters properly.
def command = "C:\\Program Files (x86)\\Git\\usr\\bin\\curl -v -H \"Content-type: application/json\" -X POST -d \"{\"deviceId\": \"${deviceGuid}\" }\" http://localhost:49742/register > out.zip"
And it can be executed like below:
def process = command.execute()
If you need to capture the output like mentioned here:
def outputStream = new StringBuffer()
process.waitForProcessOutput(outputStream, System.err)
Upvotes: 1