在SOAP UI中读取外部XML打开Source并将其用作Request

时间:2014-09-24 13:48:44

标签: groovy soapui

我正在使用SOAPUI FREE。我的项目要求是从一个位置选择Request XML(我们可能有几百个)并将其原样用作请求。是否可以在免费版本中使用任何功能或Groovy Scripting

1 个答案:

答案 0 :(得分:2)

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

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

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请求或其他类型的{{1}您必须更改与testStepFactory(TestStep)相关的代码。

此外,对于我来说,你的问题还不清楚你是否要求为每个请求创建一个测试步骤,或者如果你喜欢从groovy脚本运行所有请求而不创建测试步骤,如果第二个是你的意图你可以在groovy脚本中使用包含在SOAPUI中的WsdlTestRequestStepFactory类来从你的目录中发送请求。

希望这有帮助,