Groovy 在SOAPUI开源中读取外部XML并将其用作请求
我正在免费使用SOAPUI。我的项目需求是从一个位置选取请求XML(我们可能有数百个),并将其作为请求使用。是否可以在免费版本中使用任何功能或Groovy脚本如果您在某个目录中有SOAP xml请求,并且希望从中选取每个文件并为每个文件创建一个新的Groovy 在SOAPUI开源中读取外部XML并将其用作请求,groovy,soapui,Groovy,Soapui,我正在免费使用SOAPUI。我的项目需求是从一个位置选取请求XML(我们可能有数百个),并将其作为请求使用。是否可以在免费版本中使用任何功能或Groovy脚本如果您在某个目录中有SOAP xml请求,并且希望从中选取每个文件并为每个文件创建一个新的TestStep,您可以执行以下操作: 创建一个新的TestCase并在其中添加一个新的SOAPTestStep,该SOAP将用作模板以轻松创建新的测试步骤,然后添加一个groovyTestStep并使用下一个代码在相同的TestCase中创建新的测试
TestStep
,您可以执行以下操作:
创建一个新的TestCase
并在其中添加一个新的SOAPTestStep
,该SOAP将用作模板以轻松创建新的测试步骤,然后添加一个groovyTestStep
并使用下一个代码在相同的TestCase
中创建新的测试步骤(我在代码中添加注释以解释其工作原理):
我认为您询问的是SOAPTestStep
,但是请注意,此代码用于创建SOAPTestStep
请求,要创建RESTTestStep
请求或其他类型的TestStep
,必须更改与testStepFactory相关的代码(WsdlTestRequestStepFactory
)
此外,对于我来说,您的问题中不清楚是要为每个请求创建测试步骤,还是希望在不创建测试步骤的情况下运行groovy脚本中的所有请求,如果第二个是您的意图,那么您可以在groovy脚本中使用SOAPUI中包含的ApacheHTTP客户端
类从您的目录发送请求
希望这有帮助,这只能在免费版本中使用groovy脚本。为此,您需要了解groovy/java,通过目录对每个xml进行迭代,创建一个TestStep,设置相应的值并运行该步骤
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())
};