加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Java > 正文

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

发布时间:2020-12-15 08:34:22 所属栏目:Java 来源:网络整理
导读:我有一堆 XML格式的SOAP请求消息.有没有办法将它们导入SoapUI项目? 我想导入它们并将“测试请求”测试步骤添加到现有的测试用例中. 解决方法 一种简单且更自动的方法是使用groovy脚本从您拥有xml请求文件的目录中自动创建testStep请求: 手动创建TestCase.
我有一堆 XML格式的SOAP请求消息.有没有办法将它们导入SoapUI项目?

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

解决方法

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

>手动创建TestCase.
>添加一个空的TestStep请求,我们将其用作模板来创建其他请求.
>添加一个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())
}

希望这可以帮助,

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读