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

如何使用Soap UI Groovy编写项目中所有可用的Soap请求

洪飞龙
2023-03-14

我有一个4个测试套件的soap项目,每个测试套件都有一些测试用例,每个测试用例都有一些测试步骤[Soap请求,Groovy脚本]我能够使用下面提到的代码访问所有属性,但是,代码在本地系统中写入空白请求/响应文件**

def Project = testRunner.testCase.testSuite.project;
for(def i=0;i<Project.testSuiteCount;i++)
{
log.info Project.getTestSuiteAt(i).name 
def Suite = Project.getTestSuiteAt(i)
  for(def j=0;j<Suite.testCaseCount;j++)
  {  
   log.info Suite.getTestCaseAt(j).name
   def TCase = Suite.getTestCaseAt(j)
    for(def k=0;k < TCase.testStepCount;k++)
    {
    def TStep= TCase.getTestStepAt(k)
    def req =  context.expand('${'+TStep.name+'#Request}')
    new File("D:/Directory/"+Suite.name+"_"+TCase.name+"_"+TStep.name+"_"+k+".txt").write( req )
    }
  }
}

**请帮助解决这个问题,**

共有1个答案

养星汉
2023-03-14

实际上,有多种方法可以实现这一点。下面是一种方法。

下面是编写请求和响应的< code>Groovy脚本。

这个脚本假设用户已经运行了测试套件,以便可以保存响应。

创建一个新的测试套件 -

Groovy脚本:

/**
* This groovy script saves the request and response
* And this script will be able to write the responses
* into files if and only if there is response available
**/
import com.eviware.soapui.impl.wsdl.teststeps.WsdlTestRequestStep

//Change direcoty path if required
def directoryToSave = 'D:/directory'

//Not required to change the script beyond this point

//date time is appended to the file name
def dt = new Date().format('yyyyMMdd_HHmmss')

//Closure to save the file
def saveToFile(file, content) {
    if (!file.parentFile.exists()) {
         file.parentFile.mkdirs()
         log.info "Directory did not exist, created"
    }
    if (content) {
        log.info "Writing the content into file :${file.name}"
    file.write(content) 
    assert file.exists(), "${file.name} not created"
    } else {
        log.warn "the content is empty, not writing the content into file"
    }
}

//Get the project object
def project = context.testCase.testSuite.project

//Loop thru the project and save the request and responses
project.testSuiteList.each { suite ->
    suite.testCaseList.each { kase ->
                kase.testStepList.each { step ->
            if (step instanceof WsdlTestRequestStep) {
                def reqFilePath = new File("${directoryToSave}/${suite.name}_${kase.name}_${step.name}_request${dt}.xml")   
                def resFilePath = new File("${directoryToSave}/${suite.name}_${kase.name}_${step.name}_response${dt}.xml")  
                saveToFile(reqFilePath, step.testRequest.requestContent)
                saveToFile(resFilePath, step.testRequest.responseContent)
saveToFile(step)
            } else {
                log.info "Ignoring as the step type is not Soap request"
            }
        }
    }
}
 类似资料:
  • 我是新到Groovy wslite,我想写一个肥皂请求在wslite。 我在xml中的肥皂请求是- 我正在运行的groovy脚本如下- 当我执行我的时髦时,出现错误 我做错了什么。 PS:SoapAction在我使用的wsdl中为“”

  • 问题内容: 我需要所有已登录的SOAP请求,以及持续时间(处理请求所花费的时间)。 最好的方法是什么?看起来可以为Spring WebServices配置log4j,但是它将记录所有值吗? 将以下行添加到log4j.xml 编辑:我们实际上是在使用,而不是。另外,看起来可以通过配置PayloadLoggingInterceptor来做到这一点 但是我不确定日志消息会去哪里。我将该拦截器添加到了我们

  • 我想创建一个Java类,它将执行以下 1。使用WSDL加载/创建SOAPUI项目。 2。运行对该WSDL中的操作的请求。 这是我的soapjavatest.java文件(虽然这并不完整,但它只是在SOAP UI中注册一个项目并打印其中包含的操作)

  • 问题内容: 我是python的新手。最近,我有一个用python编写的项目,需要进行一些安装。我运行以下命令进行安装,但出现错误。 我在Google上搜索并找到了此链接,但我不太了解该帖子中的解决方案。 以下是我的requirements.txt文件: 有没有简单的方法来在此python项目中安装所有必需的依赖项? 编辑1 以下是的输出。 我已经安装了,但是pip命令仍然报告缺少此依赖项。 问题答

  • 问题内容: 我正在尝试向SOAP Web服务发送请求。我阅读了本教程并准备了以下代码。但是,我将向多个SOAP Web服务发送不同的请求,而本教程只关注一个请求。如何使用发送SOAP请求? WebServiceTemplate 问题答案: 您可以使用以下代码,而无需在xml文件中定义任何内容。

  • 本高级教程上接教程 6。我们将把我们的网页投票转换成一个独立的Python包,这样你可以在其它项目中重用或者分享给其它人。 如果你最近没有完成教程1–6,我们建议你阅读它们使得你的示例项目与下面描述的相匹配。 可重用很重要 设计、构建、测试和维护一个网页应用有许多工作要做。许多Python 和 Django 项目都有常见的共同问题。如果我们可以节省一些这些重复的工作会不会很棒? 可重用性是Pyth