将 SOAP UI 模拟请求保存到文件

Save SOAP UI mock requests to a file

我正在使用 Soap UI 基本版本进行一些模拟。我需要将我的请求保存到某个文件中。我刚刚生成了带有一些预定义输入到输出规则的模拟服务,我在网上搜索并发现了这个:

def logArea = com.eviware.soapui.SoapUI.logMonitor.getLogArea( "http log" );
def groovyUtils = new com.eviware.soapui.support.GroovyUtils(context) 

Date startTime = new Date();
def cur_Time = startTime.getMonth() + "_" + startTime.getDate()
cur_Time = cur_Time + "_" + startTime.getHours()  + "_" + startTime.getMinutes() +startTime.getSeconds()

def testPath = "C:/Users/..." + cur_Time  + ".log"
def logFile = new File(testPath)

logFile.write("soapUI Logs In a file.\r\n")
   if( logArea !=null )
   {
      def model = logArea.model
      if( model.size > 0 )            
         for( c in 0..(model.size-1) )         
           logFile.append("\n" + model.getElementAt( c ))         
   }

logArea.clear() 

这仅适用于 Soap UI GUI 请求调用。即使我从外部服务调用这个模拟服务,我怎么能坚持我的请求?

我没有任何测试用例,不需要保存他们的请求,只需要直接从外部系统请求。

谢谢!

如果您想将 Mock service 收到的所有请求保存在一个文件中,只需执行以下操作即可。在您的模拟服务中打开 onRequest script 选项卡,如下图所示(此脚本在您的服务每次收到请求时执行):

并在此选项卡中添加以下 groovy 脚本。

def myRequestPath = 'C:/temp/request_' + System.currentTimeMillis()  + ".log"
def logFile = new File(myRequestPath)
logFile.append(mockRequest.getRequestContent())

onRequest script 上下文中,您可以使用 mockRequest 对象(属于 com.eviware.soapui.impl.wsdl.mock.WsdlMockRequest type),您可以使用 getRequestContent() 方法从该对象获取请求内容,然后这个脚本将这个对象保存在一个文件中。

这个脚本比你的简单,因为它直接从对象获取响应,而不是尝试从 soapui 日志选项卡获取响应...

希望这对您有所帮助,