Forum Discussion
Hi beetlejuice ,
All of required information are in test results.
assume that you run a test case which contains several steps, then you can retrieve what you require from result:
import com.eviware.soapui.support.types.StringToObjectMap
try {
def testResult = testRunner.testCase.run(new StringToObjectMap(), false)
if (testResult) {
// print test case status
def testCaseStatus = testResult.getStatus().toString()
log.info testCaseStatus
testResult.results.eachWithIndex {stepResult, index ->
if (stepResult.testStep.metaClass.respondsTo(stepResult.testStep, "getAssertionList")) {
// print response time
log.info stepResult.testStep.testRequest.response.timeTaken
} else {
// non-REST step
}
}
} else {
// no test result
}
} catch (Exception e) {
log.error(e)
}
Thanks,
/Aaron
- beetlejuice7 years agoNew Contributor
Thank you for the reply, aaronpliu. My Groovy code is iterating through my multiple test step results using...
for(stepResults 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 = stepResults.getTestStep();
// Retrieve Test Step name
def testStepName = testStep.name
// Retrieve Test Step type
def type = testStep.config.type
// Retrieve Test Step status
def status = stepResults.getStatus()...
I had noted in a previous post (https://community.smartbear.com/t5/SoapUI-Pro/Output-Response-time-via-groovy/td-p/3500) that the following could be used to get response time:
testRunner.testCase.testSteps["Request 1"].testRequest.response.timeTaken
Since I've identified the test step name in my Groovy code as a variable called "testStepName", I'd like to create a new definition that replaces "Request 1" with the testStepName variable. Something like...
def respTime = testRunner.testCase.testSteps["$testStepName"].testRequest.response.timeTaken
The script, however, doesn't like how I'm trying to use the variable in that line. How should I invoke that variable within the brackets?