SoapUI: Groovy Script for accessing Mock Service Request

If you want to access your mock service request pragmatically via Groovy Script step and perform assertion, then you can following this sample code.

def mockService =testRunner.testCase.testSuite.project.getMockServiceByName("SampleMockService")

def mockOperation=mockService.getMockOperationByName("SampleRequest");

def requestContent=mockOperation.getLastMockResult().getMockRequest().getRequestContent();

log.info "result was: " +requestContent;

def found=null

if(requestContent.contains( "Your Key Word" ))
{
log.info("content found!")

found="found"

}

File file = new File("C:/temp/ExampleResult.txt")
file.write requestContent
println file.text

assert found=="found"


 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s