cancel
Showing results for 
Search instead for 
Did you mean: 

How to get response error from run Test case step?

SOLVED
Highlighted
Contributor

How to get response error from run Test case step?

         In readyAPI, we have a step called 'Run TestCase" under add step. If I use that to call another testcase, is there any way to receive the response of called test case?. Because right now I'm just getting passed or failed. I'm not getting any errors from the called step.

 

       In short, When I run the "Run Testcase" pointing to test case A, if testcase A failed, how can I get the failure reason without going to testcase A

1 ACCEPTED SOLUTION

Accepted Solutions
Super Contributor

Re: How to get response error from run Test case step?

I'm not sure if this is what you are after, but I make extensive use of the "Run TestCase" test step. To help me debug, I always add the following to my "common" test cases tear down script:

 

def logPrefix = testCase.getName() + ': '
log.info (logPrefix + 'Number of results = ' + testRunner.getResults().size().toString())

for(result in testRunner.getResults()){
	if(result.getStatus().toString() != 'PASS' ){
		def failedTestStepName = result.getTestStep().getName()
		def logPrefixStep = logPrefix.trim() + failedTestStepName + ': '
		
		log.error(logPrefixStep + 'TestStep "' + failedTestStepName + '" finished with the status ' + result.getStatus().toString())

		for(testProperty in testCase.getTestStepByName(failedTestStepName).getPropertyList()){
			if(testProperty.isReadOnly()){
				log.info(logPrefixStep + 'Output property: ' + testProperty.getName() + ' = ' + testProperty.getValue())
			}else{
				log.info(logPrefixStep + 'Input property: ' + testProperty.getName() + ' = ' + testProperty.getValue())
			}
		}
		
		for(message in result.getMessages()){
			log.error(logPrefixStep + 'Error message: ' + message) 
		}
	}
}

Is this what you are after?

 

 

View solution in original post

5 REPLIES 5
Super Contributor

Re: How to get response error from run Test case step?

I'm not sure if this is what you are after, but I make extensive use of the "Run TestCase" test step. To help me debug, I always add the following to my "common" test cases tear down script:

 

def logPrefix = testCase.getName() + ': '
log.info (logPrefix + 'Number of results = ' + testRunner.getResults().size().toString())

for(result in testRunner.getResults()){
	if(result.getStatus().toString() != 'PASS' ){
		def failedTestStepName = result.getTestStep().getName()
		def logPrefixStep = logPrefix.trim() + failedTestStepName + ': '
		
		log.error(logPrefixStep + 'TestStep "' + failedTestStepName + '" finished with the status ' + result.getStatus().toString())

		for(testProperty in testCase.getTestStepByName(failedTestStepName).getPropertyList()){
			if(testProperty.isReadOnly()){
				log.info(logPrefixStep + 'Output property: ' + testProperty.getName() + ' = ' + testProperty.getValue())
			}else{
				log.info(logPrefixStep + 'Input property: ' + testProperty.getName() + ' = ' + testProperty.getValue())
			}
		}
		
		for(message in result.getMessages()){
			log.error(logPrefixStep + 'Error message: ' + message) 
		}
	}
}

Is this what you are after?

 

 

View solution in original post

Highlighted
Community Hero

Re: How to get response error from run Test case step?

Hey @Radford 

 

I've just 'borrowed' your script - cheers fella - very handy! 🙂

 

nice one

 

rich

 

if this helped answer the post, could you please mark it as 'solved'? Also if you consider whether the title of your post is relevant? Perhaps if the post is solved, it might make sense to update the Subject header field of the post to something more descriptive? This will help people when searching for problems. Ta
Highlighted
Super Contributor

Re: How to get response error from run Test case step?

@richie glad you found it useful.

 

Just to mention in my "real world" testing scenarios, I actually put the script in a "TestRunListener.afterRun" event, that way I just have a single copy of the script that runs for all test cases (you can always add a filter to the event if you want to limit the number of tets cases it runs against).

Highlighted
Contributor

Re: How to get response error from run Test case step?

Thanks Radford, I have implemented the groovy script in the TestRunListener.afterStep, After the run where I can find the logs from the script?

Highlighted
Super Contributor

Re: How to get response error from run Test case step?

Details of the logs can be found here:

 

https://support.smartbear.com/readyapi/docs/configure/logs.html

 

You need to look at the "Script Log" tab.

New Here?
Join us and watch the welcome video:
Announcements
Top Kudoed Authors