【问题标题】:How do I get the size of a response attachment in SoapUI?如何在 SoapUI 中获取响应附件的大小?
【发布时间】:2023-03-23 12:55:02
【问题描述】:

我正在通过 SoapUI(不是 Pro)中 WSDL 定义的接口执行一系列文件上传和下载。用于验证这些附件的内置断言是不够的。我找到了一些 Groovy 代码,可以让我获取上传附件的大小。

import com.eviware.soapui.impl.wsdl.support.RequestFileAttachment

def uploadsize = testRunner.testCase.getTestStepByName("Upload File (200KB)").testRequest.getAttachmentAt(0).getSize()

我正在寻找可比较的代码来获取下载附件的大小。 HTTP 标头指定内容类型为“multipart/related”和 UTF-8。附件本身是“Content-Type: application/octet-stream \n Content-Transfer-Encoding: binary”

我尝试了下面的 sn-p 代码,但它没有给我附件的大小,只是响应的大小。

def downloadsize = testRunner.testCase.getTestStepByName("Download File (200KB) (Logged)").testRequest.response.contentAsString.size()

【问题讨论】:

    标签: groovy wsdl attachment soapui


    【解决方案1】:

    由于 SoapUI Groovy 类的文档充其量是错综复杂的,我使用自省来找出我正在使用哪种类:

    log.info testRunner.testCase.getTestStepByName("Download File (200KB) (Logged)").testRequest.class.name
    log.info testRunner.testCase.getTestStepByName("Download File (200KB) (Logged)").testRequest.response.class.name
    

    产生:

    com.eviware.soapui.impl.wsdl.teststeps.WsdlTestRequest
    com.eviware.soapui.impl.wsdl.submit.transports.http.support.attachments.WsdlMimeMessageResponse
    

    现在无需猜测要查找的类。

    附件大小的结果代码是:

    def downloadsize = testRunner.testCase.getTestStepByName("Download File (200KB) (Logged)").testRequest.response.getAttachments()[0].getSize()
    

    【讨论】:

    • 如果你只想要当前的测试步骤,你可以避免指定测试步骤的名称,而是使用def downloadsize = context.testCase.getTestStepAt(context.getCurrentStepIndex()).testRequest.response.getAttachments()[0].getSize()。这样一来,您的脚本在重构方面更加通用和健壮。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-01-23
    • 1970-01-01
    • 1970-01-01
    • 2010-12-13
    • 1970-01-01
    相关资源
    最近更新 更多