2013-07-08 91 views
0

我想編寫一個groovy腳本,它在請求中設置輸入。當groovy在同一個測試套件中執行時,它工作正常,但我希望這個腳本可以通過幾個測試套件。這是我的代碼,用於測試我得到了第五個測試套件,第一個測試用例和第一個測試步驟。這是getXmlHolder行失敗,出現「Unexpected CDATA」錯誤。我試圖將testSuite和testCase添加到inputHolder字符串,但這也沒有幫助。使用Groovy在SOAPUI請求中動態設置輸入

def groovyUtils = new com.eviware.soapui.support.GroovyUtils(context) 

def project = context.testCase.testSuite.project 

    def testSuite = project.getTestSuiteAt(5) 
    log.info(testSuite.getLabel()) 
    def testCase = testSuite.getTestCaseAt(0) 
    log.info(testCase.getLabel()) 
    def testStep = testCase.getTestStepAt(0) 
    log.info(testStep.getLabel()) 

    def teststepname = testCase.getTestStepAt(0).getName().toString() 
    def inputHolder = +teststepname + "#Request" 
    log.info(inputHolder); 
    def holderRawReq = groovyUtils.getXmlHolder(inputHolder) 
    holderRawReq["//tem:brandId"] = "test" 

我認爲getXmlHolder只檢查它駐留在testSuite中,所以問題是如何讓它訪問其他testSuites?

回答

3

好的,解決了。

你要創建的一步步測試的上下文您當前所在,這樣的:

import com.eviware.soapui.impl.wsdl.teststeps.* 

def project = context.testCase.testSuite.project 
def testSuite = project.getTestSuiteAt(5) 
def testCase = testSuite.getTestCaseAt(1) 
def testStep = testCase.getTestStepAt(1) 

// this will get the current teststep name 
def teststepname = testStep.getName().toString() 

//create a context for the teststep where we are 
def testStepContext = new com.eviware.soapui.impl.wsdl.testcase.WsdlTestRunContext(testStep); 

//create a util on the testStepContext 
def groovyUtils = new com.eviware.soapui.support.GroovyUtils(testStepContext) 

def inputHolder = teststepname + "#Request" 
def holderRawReq = groovyUtils.getXmlHolder(inputHolder) 

holderRawReq["//tem:brandId"] = "test7" 
holderRawReq.updateProperty() 
相關問題