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(); "result was: " +requestContent;

def found=null

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



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

assert found=="found"