当前位置: 首页 > 知识库问答 >
问题:

将多个XML文件导入SoapUI

陆文斌
2023-03-14

但是,我现在有一大堆新的xmls文件需要导入到一个项目中,我想知道是否有人有groovy脚本或其他东西来导入这些文件,并使用文件中的内容作为xml文本传递。通过HTTP请求。

基本上,我想要albciff在这里所做的。但是把我的xml文件转换成HTTP步骤。

我尝试修改他的脚本以包含正确的HTTP类,但我得到了一个无法修复的异常

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()的签名不适用于参数类型:()值:[]可能的解决方案:第14行的getAssertions()错误

共有1个答案

蒙才
2023-03-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方法看起来更方便。但是,当您在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

 类似资料:
  • 问题内容: 更新 在我发布此问题之后的第二秒,由于对结果查询的语法突出显示,我看到了出了什么问题:该字符串未以闭合斜线开头。现在我将其更改为: 但是,这提出了一个新问题:为什么PDO对象没有为此向我吐出错误?手动执行查询肯定会返回一个错误,指出没有名为的字段,最后是逗号。为什么我没有收到任何错误?有任何想法吗? PS:关于解决我的问题的SO语法突出显示方面有什么想法吗?:-) 我将原始问题留作参考

  • 我试图将一个目录中的几个csv文件读入pandas,并将它们连接到一个大数据帧中,但出现以下错误: 这是我的密码 我不知道为什么它不起作用。我试图用chmod解决这个问题,但一切都变了

  • 我正在尝试将JTable导出到Microsoft Excel可用的文件中。 最初,我将数据写入一个文本文件,并将扩展名设置为“.xls” 我们非常感谢任何帮助和洞察力。可能还值得一提的是,tables模型是一个自定义模型。

  • 问题内容: 我是新手,想知道有关从一台服务器导入文件到另一台服务器的信息。我尝试了以下命令,它对我来说很好用。现在,我想知道当有多个文件时,如何一次导入所有文件。我找不到任何相关的文档,这是不可能的。请帮助我,这可能吗? 问题答案: 您总是可以编写一些shell脚本。

  • 我正在尝试读取多个excel文件,并将每个文件中的数据附加到一个主文件中。每个文件都有相同的标题(因此我可以跳过导入初始文件后的第一行)。 我对Python和OpenPyXL模块都很陌生。我可以毫无问题地导入第一个工作簿。当我需要打开后续文件并复制数据以粘贴到原始工作表中时,我的问题就出现了。 到目前为止,这是我的代码: 谢谢!

  • 我已经安装了Sonarqube5.1.2和Checkstyle插件2.3。 我已经尝试导出一个现有的预装规则集,并尝试用其他名称导入它。但这会导致同样的失败。 这也是一个bug吗?