将多个 XML 个文件导入 SoapUI
Import Multiple XML files into SoapUI
几个月前开始了一份新工作,需要基本的日常使用 SoapUI 来执行需要一些视觉验证的批次测试(我们还没有自动化视觉部分)。
但是,我现在有一大堆新的 xmls 文件需要导入到项目中,我想知道是否有人有 groovy 脚本之类的东西来导入文件,并使用文件中的内容作为 xml 文本传递,。通过 HTTP 请求。
基本上,我想要什么albciff has done here。但是将我的 xml 文件转换为 HTTP 步骤。
我已经尝试修改他的脚本以包含正确的 HTTP 类,但我遇到了一个我无法修复的异常
更新 28/01
我正在使用 free/standard 版的 SoapUI。我的知识有限 codding/scripting,因为我只是一名功能测试员 :(
我当前的 groovy 脚本是
import com.eviware.soapui.impl.wsdl.teststeps.registry.WsdlTestRequestStepFactory
import com.eviware.soapui.impl.wsdl.teststeps.registry.HttpRequestStepFactory
import groovy.io.FileType
// get the current testCase to add testSteps later
def tc = testRunner.testCase
// get the testStep as template to create the other requests
def tsTemplate = tc.getTestStepByName("Template")
// create the factory to create testSteps
def testStepFactory = new HttpRequestStepFactory()
def requestDir = new File("C://directory//..//final_dir")
// for each xml file in the directory
requestDir.eachFileRecurse (FileType.FILES) { file ->
def newTestStepName = file.getName()
// create the config
def testStepConfig = testStepFactory.createConfig( tsTemplate.getOperation(), newTestStepName )
// add the new testStep to current testCase
def newTestStep = tc.insertTestStep( testStepConfig, -1 )
// set the request which just create with the file content
newTestStep.getTestRequest().setRequestContent(file.getText())
}
我在 运行 时得到的异常是
groovy.lang.MissingMethodException: No signature of method:
com.eviware.soapui.impl.wsdl.teststeps.HttpTestRequestStep.getOperation()
is applicable for argument types: () values: [] Possible solutions:
getAssertions() error at line: 14
你快到了 :)
,试试这个方法(使用 HttpRequestStepFactory.createNewTestStep
而不是 HttpRequestStepFactory.createConfig
):
import com.eviware.soapui.impl.wsdl.teststeps.registry.WsdlTestRequestStepFactory
import com.eviware.soapui.impl.wsdl.teststeps.registry.HttpRequestStepFactory
import groovy.io.FileType
// get the current testCase to add testSteps later
def tc = testRunner.testCase
// get the testStep as template to create the other requests
def tsTemplate = tc.getTestStepByName("Template")
// create the factory to create testSteps
def testStepFactory = new HttpRequestStepFactory()
def requestDir = new File("C://directory//..//final_dir")
// for each xml file in the directory
requestDir.eachFileRecurse(FileType.FILES){ file ->
def newTestStepName = file.getName()
// get the template endpoint
def endpoint = tsTemplate.getPropertyValue('Endpoint')
// create the config using endpoint and your method (post in your case)
def testStepConfig = testStepFactory.createNewTestStep(tc,newTestStepName,endpoint,'POST')
// add the new testStep to current testCase
def newTestStep = tc.insertTestStep( testStepConfig, -1 )
// set the request which just create with the file content
def testRequest = newTestStep.getTestRequest()
testRequest.setRequestContent(file.getText())
// UPDATED CODE BELOW BASED ON COMMENT
// you can use in this case HttpRequestConfig (due the type of your
// testStep you can use this class) to set some additional properties
// in your TestStep
def httpReqCfg = testRequest.getConfig();
// for example for mediaType as you said in your comment
httpReqCfg.setMediaType('application/json');
}
注意,使用HttpTestRequestStep.clone
method看起来更方便。但是,当您在 groovy 中调用它时,会创建 testStep
但 groovy 会抛出以下异常(我认为这里的 SOAPUI API 有问题):
java.lang.ClassCastException: com.eviware.soapui.impl.wsdl.teststeps.HttpTestRequestStep cannot be cast to com.eviware.soapui.impl.wsdl.teststeps.WsdlTestRequestStep
但是因为我认为你只对使用文件内容设置感兴趣
请求上面建议的代码就足够了。
根据评论进行编辑:
您还可以使用HttpRequestConfig
设置mediaType
或在您的评论中根据需要添加其他参数,看看HttpRequestConfig
API,我也更新了上面的代码向您展示如何获取此对象的示例,然后 setMediaType
看一看。
希望这对您有所帮助,
几个月前开始了一份新工作,需要基本的日常使用 SoapUI 来执行需要一些视觉验证的批次测试(我们还没有自动化视觉部分)。
但是,我现在有一大堆新的 xmls 文件需要导入到项目中,我想知道是否有人有 groovy 脚本之类的东西来导入文件,并使用文件中的内容作为 xml 文本传递,。通过 HTTP 请求。
基本上,我想要什么albciff has done here。但是将我的 xml 文件转换为 HTTP 步骤。
我已经尝试修改他的脚本以包含正确的 HTTP 类,但我遇到了一个我无法修复的异常
更新 28/01
我正在使用 free/standard 版的 SoapUI。我的知识有限 codding/scripting,因为我只是一名功能测试员 :(
我当前的 groovy 脚本是
import com.eviware.soapui.impl.wsdl.teststeps.registry.WsdlTestRequestStepFactory
import com.eviware.soapui.impl.wsdl.teststeps.registry.HttpRequestStepFactory
import groovy.io.FileType
// get the current testCase to add testSteps later
def tc = testRunner.testCase
// get the testStep as template to create the other requests
def tsTemplate = tc.getTestStepByName("Template")
// create the factory to create testSteps
def testStepFactory = new HttpRequestStepFactory()
def requestDir = new File("C://directory//..//final_dir")
// for each xml file in the directory
requestDir.eachFileRecurse (FileType.FILES) { file ->
def newTestStepName = file.getName()
// create the config
def testStepConfig = testStepFactory.createConfig( tsTemplate.getOperation(), newTestStepName )
// add the new testStep to current testCase
def newTestStep = tc.insertTestStep( testStepConfig, -1 )
// set the request which just create with the file content
newTestStep.getTestRequest().setRequestContent(file.getText())
}
我在 运行 时得到的异常是
groovy.lang.MissingMethodException: No signature of method: com.eviware.soapui.impl.wsdl.teststeps.HttpTestRequestStep.getOperation() is applicable for argument types: () values: [] Possible solutions: getAssertions() error at line: 14
你快到了 :)
,试试这个方法(使用 HttpRequestStepFactory.createNewTestStep
而不是 HttpRequestStepFactory.createConfig
):
import com.eviware.soapui.impl.wsdl.teststeps.registry.WsdlTestRequestStepFactory
import com.eviware.soapui.impl.wsdl.teststeps.registry.HttpRequestStepFactory
import groovy.io.FileType
// get the current testCase to add testSteps later
def tc = testRunner.testCase
// get the testStep as template to create the other requests
def tsTemplate = tc.getTestStepByName("Template")
// create the factory to create testSteps
def testStepFactory = new HttpRequestStepFactory()
def requestDir = new File("C://directory//..//final_dir")
// for each xml file in the directory
requestDir.eachFileRecurse(FileType.FILES){ file ->
def newTestStepName = file.getName()
// get the template endpoint
def endpoint = tsTemplate.getPropertyValue('Endpoint')
// create the config using endpoint and your method (post in your case)
def testStepConfig = testStepFactory.createNewTestStep(tc,newTestStepName,endpoint,'POST')
// add the new testStep to current testCase
def newTestStep = tc.insertTestStep( testStepConfig, -1 )
// set the request which just create with the file content
def testRequest = newTestStep.getTestRequest()
testRequest.setRequestContent(file.getText())
// UPDATED CODE BELOW BASED ON COMMENT
// you can use in this case HttpRequestConfig (due the type of your
// testStep you can use this class) to set some additional properties
// in your TestStep
def httpReqCfg = testRequest.getConfig();
// for example for mediaType as you said in your comment
httpReqCfg.setMediaType('application/json');
}
注意,使用HttpTestRequestStep.clone
method看起来更方便。但是,当您在 groovy 中调用它时,会创建 testStep
但 groovy 会抛出以下异常(我认为这里的 SOAPUI API 有问题):
java.lang.ClassCastException: com.eviware.soapui.impl.wsdl.teststeps.HttpTestRequestStep cannot be cast to com.eviware.soapui.impl.wsdl.teststeps.WsdlTestRequestStep
但是因为我认为你只对使用文件内容设置感兴趣 请求上面建议的代码就足够了。
根据评论进行编辑:
您还可以使用HttpRequestConfig
设置mediaType
或在您的评论中根据需要添加其他参数,看看HttpRequestConfig
API,我也更新了上面的代码向您展示如何获取此对象的示例,然后 setMediaType
看一看。
希望这对您有所帮助,