arunbharath
6 years agoContributor
How to get a test-step response from Suite TearDown script?
Hi All. I trying to get step step response of each test case from suite TearDown script.
def testCaseCount = runner.testSuite.getTestCaseCount()
for (int i=0;i<testCaseCount;i++){
def testCaseName = runner.testSuite.getTestCaseAt(i).getName()
def testStepCount = runner.testSuite.getTestCaseAt(i).getTestStepCount()
for (int j=0;j<testStepCount;j++){
def testStepName = runner.testSuite.getTestCaseAt(i).getTestStepAt(j).getName()
// log.info(testStepName)
if (testStepName == "SendPayment"){
def request=context.expand('${SendPayment#Response}')
log.info(request)
}
//File f = new File(projectProperty+"/TearDownScriptFiles/"+testCase.name+".json")
//f.write(response)
}
log.info(testCaseName)
}
Above is my groovy code. I'm iterating all the testcases under suite and test step as well, I'm trying to get the test-step response based on the test step name. Right now I'm able to iterate the test cases and test steps but I could get the test step response..I belive I need to change below one
if (testStepName == "SendPayment"){
def request=context.expand('${SendPayment#Response}')
log.info(request)
}Any input is appreciated. Thanks
Here you go:
Please follow comments inline
/** * Tear down script of suite **/ import com.eviware.soapui.impl.wsdl.teststeps.RestTestRequestStep def processStep = { log.info "Step name : ${it.name}" log.info "Case name : ${it.testCase.name}" log.info "Suite name : ${testSuite.name}" log.info "Response :\n ${it.testRequest.responseContentAsString}" //Write logic below to save the response data to file here } testSuite.testCaseList.collect { kase -> kase.testStepList.collect { switch(it) { //Process only REST requests; add additional cases as needed case {it instanceof RestTestRequestStep}: processStep it break default: break } } }If you don't want to have the above script for each test suite or project, then you can use events, "TestRunListener.afterStep" and have relevant logic to do the same.