如何将现有的 SOAP 请求消息导入 SoapUI? [英] How to import existing SOAP request messages to SoapUI?

查看:25
本文介绍了如何将现有的 SOAP 请求消息导入 SoapUI?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

我想导入它们并作为测试请求"测试步骤添加到现有测试用例中.

解决方案

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

>

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

常规代码执行前的 SOAPUI 如下所示:

以及必要的常规代码:

import com.eviware.soapui.impl.wsdl.teststeps.registry.WsdlTestRequestStepFactory导入 groovy.io.FileType//获取当前的 testCase 以便稍后添加 testStepsdef tc = testRunner.testCase//获取 testStep 作为模板以创建其他请求def tsTemplate = tc.getTestStepByName("TestRequest 模板")//创建工厂以创建 testStepsdef testStepFactory = new WsdlTestRequestStepFactory()def requestDir = new File("/your_xml_request_directory/")//对于目录中的每个 xml 文件requestDir.eachFileRecurse (FileType.FILES) { file ->def newTestStepName = file.getName()//创建配置def testStepConfig = testStepFactory.createConfig( tsTemplate.getOperation(), newTestStepName )//将新的 testStep 添加到当前的 testCasedef newTestStep = tc.insertTestStep( testStepConfig, -1 )//设置刚刚用文件内容创建的请求newTestStep.getTestRequest().setRequestContent(file.getText())}

希望这会有所帮助,

I have a bunch of SOAP request messages in XML format. Is there a way to import them to a SoapUI project?

I want to import them and add as "Test Request" Test Step to an existing Test Case.

解决方案

An easy and more automatic way to do so is using a groovy script to automatically create the testStep request from a directory where you have you xml request files:

  1. Create a TestCase manually.
  2. Add an empty TestStep request which we will use as a template to create the other requests.
  3. Add a groovy testStep which imports all files using the code below, and execute it in order to create the testSteps.

Your SOAPUI before groovy code execution looks like:

And the necessary groovy code:

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())
}

Hope this helps,

这篇关于如何将现有的 SOAP 请求消息导入 SoapUI?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆