使用soapUI中的Groovy teststep将请求/响应文件存储在本地目录中

2024-04-21

通过soapUI中的常规测试步骤,我希望所有请求和响应文件都存储在具有系统日期的本地目录中。

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()

我收到以下错误:

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)

有几种方法可以做到这一点。一种方法是使用以下脚本创建 Groovy 测试步骤:

def myOutFile = "C:/Temp/MyOutDir/response.xml"
def response = context.expand( '${MyTestRequest#Response}' )
def f = new File(myOutFile)
f.write(response, "UTF-8")
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

使用soapUI中的Groovy teststep将请求/响应文件存储在本地目录中 的相关文章

随机推荐