Groovy 如何在SoapUI中自动从RESTAPI下载附件以获取响应
我正在使用SOAPUI5.5.0,我正在尝试从RESTAPI GET响应自动下载.xls附件。 它不会出现在响应的附件选项卡中Groovy 如何在SoapUI中自动从RESTAPI下载附件以获取响应,groovy,soapui,Groovy,Soapui,我正在使用SOAPUI5.5.0,我正在尝试从RESTAPI GET响应自动下载.xls附件。 它不会出现在响应的附件选项卡中 我尝试添加“Enable MTOM | true”,但请求停止使用 它 我尝试了一些groovy脚本,但我没有从中得到任何东西 在此之后,响应有一堆无法读取的字符 如果查看XML选项卡,我会发现: **XML RESPONSE** <data contentType="application/vnd.ms-excel" contentLen
- 我尝试添加“Enable MTOM | true”,但请求停止使用 它
- 我尝试了一些groovy脚本,但我没有从中得到任何东西
**XML RESPONSE**
<data contentType="application/vnd.ms-excel" contentLength="647680">0M8R4KGxGuEAAAAAAAAAAAAAAAAAAAAAOwADAP7/CQAGAAAAAAAAAAAAAAAKAAAAAAAAAAAAAAAAEAAA/v///wAAAAD+////AAAAAAEAAACAAAAAAAEAAIABAAAAAgAAgAIAAAADAACAAwAAAAQAAIAEAAD///...it's very long
响应的主体是文件。你必须提取它,像这样:
import org.apache.commons.io.FileUtils
def testStep = testRunner.testCase.testSteps['test step name']
def response = testStep.testRequest.response
assert response.getContentType() == 'application/vnd.ms-excel'
def data = response.getRawResponseBody()
// define some filename
def filename = response.getProperty('Content-Disposition').split('=')[1]
def file = new File(filename)
FileUtils.writeByteArrayToFile(file, data)
非常感谢你。
import org.apache.commons.io.FileUtils
def testStep = testRunner.testCase.testSteps['test step name']
def response = testStep.testRequest.response
assert response.getContentType() == 'application/vnd.ms-excel'
def data = response.getRawResponseBody()
// define filepath/name
exportname = testRunner.testCase.getPropertyValue("exportName")
reportfolder = (System.getProperty("user.home") + File.separatorChar + "Documents" + File.separatorChar);
def filename = reportfolder + exportname +'.xls'
def file = new File(filename)
FileUtils.writeByteArrayToFile(file, data) `
import org.apache.commons.io.FileUtils
def testStep = testRunner.testCase.testSteps['test step name']
def response = testStep.testRequest.response
assert response.getContentType() == 'application/vnd.ms-excel'
def data = response.getRawResponseBody()
// define some filename
def filename = response.getProperty('Content-Disposition').split('=')[1]
def file = new File(filename)
FileUtils.writeByteArrayToFile(file, data)