首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >在SOAP开放源码中读取外部XML并将其用作请求

在SOAP开放源码中读取外部XML并将其用作请求
EN

Stack Overflow用户
提问于 2014-09-24 13:48:44
回答 1查看 3.4K关注 0票数 0

我正在使用SOAPUI免费。我的项目需求是从一个位置选择请求XML (可能有数百个请求),并将其作为请求使用。是否可以在免费版本中使用任何特性或Groovy脚本

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-09-24 22:40:46

如果在某个目录中有SOAP请求,并且希望从中选择每个文件并为每个文件创建一个新的TestStep,则可以执行以下操作:

创建一个新的TestCase并在其中添加一个新的SOAP TestStep,它将用作模板来轻松地创建新的TestStep,然后添加一个groovy TestStep--使用下一个代码在同一个TestCase中创建新的测试步骤(我将注释放在代码中以解释它是如何工作的):

代码语言:javascript
运行
复制
import com.eviware.soapui.impl.wsdl.teststeps.registry.WsdlTestRequestStepFactory

// get the current testCase to add testSteps later
def tc = testRunner.testCase;
// get the SOAP TestStep as template to create the other requests
def tsTemplate = tc.getTestStepByName("MyRequest");
// create the test step factory to use later
def testStepFactory = new WsdlTestRequestStepFactory();

// now get all the request from a specific location...

// your location
def directory = new File("C:/Temp/myRequests/")
// for each file in the directory
directory.eachFile{ file -> 
    // use file name as test step name 
    def testStepName = file.getName()
    // create the config
    def testStepConfig = testStepFactory.createConfig( tsTemplate.getTestRequest(), testStepName)
    // add the new testStep to TestCase
    def newTestStep = tc.insertTestStep( testStepConfig, -1 ) 
    // set the request from the file content
    newTestStep.getTestRequest().setRequestContent(file.getText())   
};

我认为您是在询问SOAP TestStep,但是请注意,这段代码是要创建SOAP TestStep请求、创建REST TestStep请求或其他类型的TestStep,您必须更改与testStepFactory (WsdlTestRequestStepFactory)相关的代码。

此外,对于我来说,您的问题中还不清楚是要为每个请求创建一个测试步骤,还是希望在不创建测试步骤的情况下运行来自groovy脚本的所有请求,如果第二个步骤是您打算在groovy脚本中使用SOAPUI中包含的apache-http-client类从您的目录发送请求。

希望这能帮上忙

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/26018585

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档