【问题标题】:Save SOAP UI mock requests to a file将 SOAP UI 模拟请求保存到文件
【发布时间】:2015-06-23 07:20:27
【问题描述】:

我正在使用 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 请求调用中正常工作。即使我从外部服务调用这个模拟服务,我怎样才能坚持我的请求?

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

谢谢!

【问题讨论】:

    标签: web-services soap request soapui


    【解决方案1】:

    如果您想将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 日志选项卡中获取响应...

    希望这会有所帮助,

    【讨论】:

    • 谢谢伙计,现在这项工作很好!我从未尝试过使用 onRequest 脚本,这比我想要的还要好。最好的问候!
    • @MiniHamza 很高兴帮助你:)
    猜你喜欢
    • 1970-01-01
    • 2016-05-20
    • 2015-09-16
    • 1970-01-01
    • 1970-01-01
    • 2018-05-17
    • 1970-01-01
    • 1970-01-01
    • 2012-10-13
    相关资源
    最近更新 更多