How to use a defined variable elsewhere in a Groovy script?
I am using Groovy scripting to create output files containing test execution results from SoapUI for a given test case. My test case contains several test steps, so I'm using the following logic to iterate through each test step and collect specific information (this is a snippet from the script):
...
for(stepResult in testRunner.getResults())
{
// Retrieve Test Suite name
def testSuite = testRunner.testCase.testSuite.name;
// Retrieve Test Case name
def testCase = testRunner.testCase.name;
// Retrieve Test Step
def testStep = stepResult.getTestStep();
// Retrieve Test Step name
def testStepName = testStep.name;
// Retrieve Test Step type
def type = testStep.config.type;
// Retrieve Test Step status
def status = stepResult.getStatus();
// Retrieve response time
def respTime = testRunner.testCase.testSteps["Request 1"].testRequest.response.timeTaken;
...
The question I have revolves around the line that I've highlighted in green (the last "def" statement). Since my script will process a number of test steps, I'd like to replace "Request 1" with a variable that reflects the test step name in order to get that particular test step's response time. So, I'm trying to use "$testStepName" (defined earlier in my snippet) in place of "Request 1", but I'm not getting anything as a result. Here's how I'm trying to apply it:
def respTime = testRunner.testCase.testSteps["$testStepName"].testRequest.response.timeTaken;
Am I referencing the variable correctly in my "respTime" definition? Or, is there a different approach I should take to get the response time for each of my steps?
Thank you!