Java 如何将现有的SOAP请求消息导入到SoapUI?

Java 如何将现有的SOAP请求消息导入到SoapUI?,java,web-services,wsdl,soapui,Java,Web Services,Wsdl,Soapui,我有一堆XML格式的SOAP请求消息。有没有办法将它们导入到SoapUI项目中 我想导入它们并将其作为“测试请求”测试步骤添加到现有测试用例中。将每个测试步骤复制/粘贴到新的请求中,然后右键单击每个请求并将其添加到您的测试用例中。或在请求视图中打开上下文菜单时选择“加载自…”。另一个选项是: 使用一个请求创建soapui项目 打开soapui项目XML文件 搜索con:callpart 复制它并用您自己的XML请求替换con:request 在soapui中保存并重新加载项目 一种更简单、更自动

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


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

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

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

另一个选项是:

  • 使用一个请求创建soapui项目
  • 打开soapui项目XML文件
  • 搜索con:callpart
  • 复制它并用您自己的XML请求替换con:request
  • 在soapui中保存并重新加载项目

  • 一种更简单、更自动的方法是使用groovy脚本从包含xml请求文件的目录中自动创建testStep请求:

  • 手动创建一个测试用例
  • 添加一个空的TestStep请求,我们将使用它作为模板来创建其他请求
  • 添加一个groovy testStep,它使用下面的代码导入所有文件,并执行它以创建testStep
  • 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())
    }
    

    希望这有帮助,

    这是我在没有看到其他选项的情况下要做的。如果它是“您的xml请求目录”的绝对路径,是否会回到这个问题?或者,如果它是一个相对路径,它是从哪个目录相对的?@HyukchanKwon在我的示例中
    /your\u xml\u request\u directory/
    指的是一个绝对路径。我不确定,但我认为如果使用相对路径,它是相对于soapui执行目录的。