cancel
Showing results for 
Search instead for 
Did you mean: 

Capture request log via groovy script from a specific test step

Highlighted
Occasional Contributor

Capture request log via groovy script from a specific test step

I have a groovy script from where i invoke a API call.

The API call "Request log" section is required in my groovy script.

def logArea = com.eviware.soapui.SoapUI.logMonitor.getLogArea( "Request Log" );
def groovyUtils = new com.eviware.soapui.support.GroovyUtils(context.get) 
if( logArea !=null )
{
 	def model = logArea.model
 	// only continue of logArea not empty
 	if( model.size > 0 ) {
 		for( c in 0..(model.size-1) ) {
 		log.info(model.getElementAt(c))
 		}
 	}               
}

This cant get it from the next step which is my API call.

Kindly help 

1 REPLY 1
Occasional Contributor

Re: Capture request log via groovy script from a specific test step

hello,

 

first doubt should be on "request log" which soapui version you use ?

I use SoapUi 5.4.0 and this tab don't exist. I have Soapui Log, script log.. and perhaps you want to use "http log"

I use REST requests, and detail log, in real time displays in "http log".

So tell me your error please. If you have a "java.lang.NullPointerException" that is the explanation. 

second doubt in declaration of groovyUtils. I use GroovyUtils(context) syntax in all my scripts, and it works.

I don't understand why you write it in your code but anyway 🙂

at the end, i use ToString() function to log information , and try catch to get error if it occurs; this is more "safe code" to execute entirely without stop.

 

So here is a complete example solution, to replace your code : 

 

try {
def logArea = com.eviware.soapui.SoapUI.logMonitor.getLogArea( "http log" ); def groovyUtils = new com.eviware.soapui.support.GroovyUtils(context) if( logArea !=null ) { def model = logArea.model // only continue of logArea not empty if( model.size > 0 ) { for( c in 0..(model.size-1) ) { log.info(model.getElementAt(c).toString() + "\r\n") } } }
} catch (IOException ee) { ee.printStackTrace() }

 

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