使用soapUI中的Groovy teststep将请求/响应文件存储在本地目录中 [英] Store request/response files in local directory with Groovy teststep in soapUI

查看:295
本文介绍了使用soapUI中的Groovy teststep将请求/响应文件存储在本地目录中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通过soapUI中的groovy teststep,我希望所有的请求和响应文件都存储在系统日期的本地目录中。

soapUI中的groovy teststep:

  def name = context.expand('$ {Input#TG}')

def locatie = context .expand('$ {#TestCase#locatie}')

def createFolder(){
date = new Date()
dateFormat = new java.text.SimpleDateFormat(' ddMMyyyy')
shortDate = dateFormat.format(date)
outputFolder = locatie + shortDate
createFolder = new File(outputFolder)
createFolder.mkdir()
}
$ b $ def getResponseFilename(name){
respFilename = createFolder()+_+ name +_ response.xml
}
$ b $ def getRequestFilename(locatie ,name){
reqFilename = createFolder()+_+ name +_ request.xml
}

def file = new PrintWriter(getResponseFilename(name))

def response = testRunner.testCase.testSteps
[CheckAdres]。testRequest.respo nse.contentAsString
$ b $ file.println(响应)
file.flush()
file.close()

def file2 = new PrintWriter(getRequestFilename (name))
def request = context.expand('$ {CheckAdres#Request}')

file2.println(请求)
file2.flush()
file2.close()

我得到以下错误:

  Tue Jun 14 12:47:24 CEST 2011:**错误:groovy.lang.MissingPropertyException:No such property:locatie for class:Script78 ** 
groovy.lang.MissingPropertyException:No such property:locatie for class:Script78
at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:49)
at org.codehaus.groovy。运行时.callsite.PogoGetPropertySite.getProperty(PogoGetPropertySite.java:49)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callGroovyObjectGetProperty(AbstractCallSite.java:241)
at Script78.createFolder(Script78。 groovy:8)
在Script78 $ createFolder。在脚本78中
$ getResponseFilename.callCurrent(未知源)
at Script78.run(Script78.groovy:21)
at com.eviware.soapui.support.scripting.groovy.SoapUIGroovyScriptEngine.run(SoapUIGroovyScriptEngine.java:93)
at com.eviware.soapui.support.scripting.groovy.SoapUIProGroovyScriptEngineFactory $ SoapUIProGroovyScriptEngine.run(SourceFile :51)
at com.eviware.soapui.impl.wsdl.teststeps.WsdlGroovyScriptTestStep.run(WsdlGroovyScriptTestStep.java:148)
at com.eviware.soapui.impl.wsdl.panels.teststeps.GroovyScriptStepDesktopPanel $ RunAction $ 1.run(GroovyScriptStepDesktopPanel.java:274)
at java.util.concurrent.ThreadPoolExecutor $ Worker.runTask(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor $ Worker.run(Unknown源)
在java.lang.Thread.run(未知源)


解决方案

o有几种方法f这样做。一个是用下面的脚本创建一个Groovy测试步骤:

  def myOutFile =C:/ Temp / MyOutDir / response。 xml
def response = context.expand('$ {MyTestRequest#Response}')
def f = new File(myOutFile)
f.write(response,UTF-8)


Through a groovy teststep in soapUI i want all request and response files to be stored in a local directory with system date.

The groovy teststep in soapUI:

def name = context.expand( '${Input#TG}' )

def locatie = context.expand( '${#TestCase#locatie}' )

def createFolder() {
  date = new Date()
  dateFormat = new java.text.SimpleDateFormat('ddMMyyyy')
  shortDate = dateFormat.format(date)
  outputFolder = locatie+shortDate
  createFolder = new File(outputFolder)
  createFolder.mkdir()  
}

def getResponseFilename(name) {
  respFilename = createFolder()+"_"+name+"_response.xml"
}

def getRequestFilename(locatie,name) {
  reqFilename = createFolder()+"_"+ name+"_request.xml"
}

def file = new PrintWriter (getResponseFilename(name))

def response = testRunner.testCase.testSteps
["CheckAdres"].testRequest.response.contentAsString

file.println(response)
file.flush()
file.close()

def file2 = new PrintWriter (getRequestFilename(name))
def request = context.expand('${CheckAdres#Request}')

file2.println(request)
file2.flush()
file2.close()

I get the following error:

Tue Jun 14 12:47:24 CEST 2011:**ERROR:groovy.lang.MissingPropertyException: No such property: locatie for class: Script78**
groovy.lang.MissingPropertyException: No such property: locatie for class: Script78
  at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:49)
  at org.codehaus.groovy.runtime.callsite.PogoGetPropertySite.getProperty(PogoGetPropertySite.java:49)
  at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callGroovyObjectGetProperty(AbstractCallSite.java:241)
  at Script78.createFolder(Script78.groovy:8)
  at Script78$createFolder.callCurrent(Unknown Source)
  at Script78.getResponseFilename(Script78.groovy:14)
  at Script78$getResponseFilename.callCurrent(Unknown Source)
  at Script78.run(Script78.groovy:21)
  at com.eviware.soapui.support.scripting.groovy.SoapUIGroovyScriptEngine.run(SoapUIGroovyScriptEngine.java:93)
  at com.eviware.soapui.support.scripting.groovy.SoapUIProGroovyScriptEngineFactory$SoapUIProGroovyScriptEngine.run(SourceFile:51)
  at com.eviware.soapui.impl.wsdl.teststeps.WsdlGroovyScriptTestStep.run(WsdlGroovyScriptTestStep.java:148)
  at com.eviware.soapui.impl.wsdl.panels.teststeps.GroovyScriptStepDesktopPanel$RunAction$1.run(GroovyScriptStepDesktopPanel.java:274)
  at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
  at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
  at java.lang.Thread.run(Unknown Source)

解决方案

There are several ways of doing this. One would be creating a Groovy test step with the following script:

def myOutFile = "C:/Temp/MyOutDir/response.xml"
def response = context.expand( '${MyTestRequest#Response}' )
def f = new File(myOutFile)
f.write(response, "UTF-8")

这篇关于使用soapUI中的Groovy teststep将请求/响应文件存储在本地目录中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆