【问题标题】:How to import existing SOAP request messages to SoapUI?如何将现有的 SOAP 请求消息导入 SoapUI?
【发布时间】:2010-07-01 19:22:42
【问题描述】:

我有一堆 XML 格式的 SOAP 请求消息。有没有办法将它们导入 SoapUI 项目?

我想将它们导入并作为“测试请求”测试步骤添加到现有测试用例中。

【问题讨论】:

    标签: java web-services wsdl soapui


    【解决方案1】:

    一种简单且更自动化的方法是使用 groovy 脚本从您拥有 xml 请求文件的目录中自动创建 testStep 请求:

    1. 手动创建测试用例。
    2. 添加一个空的 TestStep 请求,我们将使用它作为模板来创建其他请求。
    3. 添加一个 groovy testStep,它使用以下代码导入所有文件,并执行它以创建 testSteps。

    你在 groovy 代码执行之前的 SOAPUI 如下所示:

    以及必要的 groovy 代码:

    import com.eviware.soapui.impl.wsdl.teststeps.registry.WsdlTestRequestStepFactory
    import groovy.io.FileType
    
    // get the current testCase to add testSteps later
    def tc = testRunner.testCase
    // get the testStep as template to create the other requests
    def tsTemplate = tc.getTestStepByName("TestRequest template")
    // create the factory to create testSteps
    def testStepFactory = new WsdlTestRequestStepFactory()
    
    def requestDir = new File("/your_xml_request_directory/")
    // for each xml file in the directory
    requestDir.eachFileRecurse (FileType.FILES) { file ->
      def newTestStepName = file.getName()
      // create the config
      def testStepConfig = testStepFactory.createConfig( tsTemplate.getOperation(), newTestStepName )
      // add the new testStep to current testCase
      def newTestStep = tc.insertTestStep( testStepConfig, -1 )
      // set the request which just create with the file content
      newTestStep.getTestRequest().setRequestContent(file.getText())
    }
    

    希望这会有所帮助,

    【讨论】:

    • “your_xml_request_directory”是绝对路径吗?或者如果它是一个相对路径,它来自哪个目录是相对的?
    • @HyukchanKwon 在我的示例中,/your_xml_request_directory/ 指的是绝对路径。我不确定,但我想如果你使用相对路径,它是相对于 soapui 执行目录的。
    【解决方案2】:

    将每个请求复制/粘贴到一个新请求中,然后右键单击每个请求并将它们添加到您的测试用例中。

    【讨论】:

      【解决方案3】:

      或者在请求视图中打开上下文菜单时选择“加载自...”。

      【讨论】:

        【解决方案4】:

        另一种选择是:

        1. 用一个请求创建一个soapui项目
        2. 打开soapui-project XML 文件
        3. 搜索 con:call 部分
        4. 复制它并将 con:request 替换为您自己的 XML 请求
        5. 在soapui中保存并重新加载项目

        【讨论】:

        • 这是我在没有看到其他选项的情况下要做的。如果可行,将退回到此
        猜你喜欢
        • 1970-01-01
        • 2013-04-16
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-01-09
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多