Ask a Question

How to get a test-step response from Suite TearDown script?

SOLVED
arunbharath
Contributor

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

 

 

9 REPLIES 9
nmrao
Community Hero

Appreciate if you can let us know what is the use case?

 

"Right now I'm able to iterate the test cases and test steps but I could get the test step response.." - did not understand the issue. Did you miss something?



Regards,
Rao.
nmrao
Community Hero

And what are different type of test steps for which you need response?


Regards,
Rao.

Sorry my bad. Typo on the last message 

 

Use Case:

=========

1) Let say I have a Test suite which has multiple testcases and each test case has multiple test steps. I want to iterate each test cases and test steps and get API response of test step based on the test-step name (using if-loop). after getting all the respective test-step response, I need to save those response in the file.

 

2) Currently I'm having a script to iterate test-cases and test-steps, I need script to recive test-step response.

 

What I meant was why to save response while the tool does it automatically when a step is failed.



Regards,
Rao.
nmrao
Community Hero

@arunbharath 

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.afterStepand have relevant logic to do the same. 



Regards,
Rao.

@nmrao  Thanks. It is working like a gem. I have one more question. How can we extract any specific datafield field value from the test-step Json api response?

Nothing special, write logic to extract the required data. You can find samples in the forum or online search or from my GitHub.com/nmrao

By the way you posted a question earlier related the same I guess. If so that can closed too.


Regards,
Rao.

@arunbharath,
If you have specific question after looking at the other suggestions, please feel free to open a new topic.


Regards,
Rao.

Click thumbs-up for the helpful reply if you wish.


Regards,
Rao.
cancel
Showing results for 
Search instead for 
Did you mean: