How to get a test-step response from Suite TearDown script?
SOLVED- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
Solved! Go to Solution.
- Labels:
-
Automation Environments
-
Scripting
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Regards,
Rao.
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Regards,
Rao.
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
Regards,
Rao.
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
@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?
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
By the way you posted a question earlier related the same I guess. If so that can closed too.
Regards,
Rao.
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
If you have specific question after looking at the other suggestions, please feel free to open a new topic.
Regards,
Rao.
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Regards,
Rao.
