2016-12-27 58 views
2

我有一个包含4个Test Suite的soap项目,每个Test Suite都有一些测试用例,每个测试用例都有一些测试步骤[Soap Request,Groovy Script] 我能够使用如下代码提到访问所有的属性,但是,代码在本地系统中写入空白的请求/响应文件**如何使用Soap UI编写项目中可用的所有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) 
    } 
    } 
} 

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

+0

请对齐的代码可以正确 –

+0

@安德里·阿布拉莫夫完成 –

+0

@albciff你可以在这里帮忙, –

回答

2

其实有是多种方法来实现这一点。 下面是一种方法。

这是Groovy Script它写入请求和响应。

该脚本假定用户已经运行测试套件,以便可以保存响应。

创建一个新的测试套件 - >测试用例 - >添加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" 
      } 
     } 
    } 
} 
+0

感谢您的快速响应,但我能够使用此编写只有一个请求/资源..错误groovy.lang.MissingMethodException:没有方法的签名:Script2.saveToFile()适用于参数类型:(com.eviware.soapui .impl.wsdl.teststeps.WsdlTestRequestStep)values:[[email protected]9]可能的解决方案:saveToFile(java.lang.Object,java.lang.Object)error at line:35 –

+0

就像它提到的那样,在运行上述脚本之前,应该有可用的响应或者运行测试。如果可以写一个请求,那么其他人也不应该有任何问题。 – Rao

+0

让我再试一次,但如果有读取超时回应 –