我正在使用SOAPUI免费。我的项目需求是从一个位置选择请求XML (可能有数百个请求),并将其作为请求使用。是否可以在免费版本中使用任何特性或Groovy脚本
发布于 2014-09-24 22:40:46
如果在某个目录中有SOAP请求,并且希望从中选择每个文件并为每个文件创建一个新的TestStep,则可以执行以下操作:
创建一个新的TestCase并在其中添加一个新的SOAP TestStep,它将用作模板来轻松地创建新的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请求或其他类型的TestStep,您必须更改与testStepFactory (WsdlTestRequestStepFactory)相关的代码。
此外,对于我来说,您的问题中还不清楚是要为每个请求创建一个测试步骤,还是希望在不创建测试步骤的情况下运行来自groovy脚本的所有请求,如果第二个步骤是您打算在groovy脚本中使用SOAPUI中包含的apache-http-client类从您的目录发送请求。
希望这能帮上忙
https://stackoverflow.com/questions/26018585
复制相似问题