我正在使用SOAPUI FREE。我的项目要求是从一个位置选择Request XML(我们可能有几百个)并将其原样用作请求。是否可以在免费版本中使用任何功能或Groovy Scripting
答案 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
类来从你的目录中发送请求。
希望这有帮助,