2016-12-27 49 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

讓我再試一次,但如果有讀取超時迴應 –