将多个XML文件导入SoapUI

亚历克斯·库克

几个月前开始了一项新工作,并且需要对SoapUI进行日常使用,以执行需要进行视觉验证的测试批处理(我们尚未使视觉部分自动化)。

但是,我现在有一大堆新的xmls文件,我需要将其导入到项目中,并且我想知道是否有人使用groovy脚本之类的东西来导入文件并将文件中的内容用作xml文本。经过,。通过HTTP请求。

基本上,我想要albciff这里做些什么但是将我的xml文件变成HTTP步骤。

我试图修改他的脚本以包括正确的HTTP类,但是却遇到了无法解决的异常

更新28/01

我只是在使用SoapUI的免费/标准版。由于我只是一个功能测试员,因此我对编码/脚本知识的了解有限:

我当前的常规脚本是

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:方法的无签名:com.eviware.soapui.impl.wsdl.teststeps.HttpTestRequestStep.getOperation()适用于参数类型:()值:[]可能的解决方案:第一行的getAssertions()错误: 14

Albciff

您快到了:),尝试这种方式(使用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方法看起来更方便但是,当您在groovy中调用此testStep函数时会创建,但groovy会引发以下异常(我认为这是SOAPUI API的问题):

java.lang.ClassCastException:com.eviware.soapui.impl.wsdl.teststeps.HttpTestRequestStep无法转换为com.eviware.soapui.impl.wsdl.teststeps.WsdlTestRequestStep

但是,由于我认为您仅在使用文件内容来设置请求时才很有趣,因此在您的情况下,上面建议的代码就足够了。

根据评论进行编辑:

您还可以根据需要在注释中使用HttpRequestConfig设置mediaType或添加其他参数,看看HttpRequestConfigAPI,我也在上面的代码中进行了更新,向您展示了如何获取此对象并对其setMediaType进行查看的示例

希望这可以帮助,

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章