2016-05-18 30 views
0

我在測試用例1一個Groovy腳本命名檢查,其中包含如下代碼:soapui;得到的結果在不同的測試用例

log.info "Running from different test case script" 

我想在寫測試用例2腳本來得到這個消息:

package com.eviware.soapui.impl.wsdl.testcase; 
Test_script= testRunner.testCase.testSuite.project.testSuites["TestSuite"].testCases["TestCase"].testSteps["Check"] 
def myCont= new WsdlTestRunContext(Test_script) 
log.info Test_script.run(testRunner,myCont) 

它給我輸出:

週三5月18日17時39分57秒北京時間2016年信息:com.eviware.soapui.impl.wsdl。 [email protected]

怎麼辦這裏看到正確的信息在輸出

回答

2

TestStep.run方法不能從其他一步步測試直接返回所需的對象或如此,它會返回一個通用WsdlTestStepResult對象查看testStep執行的狀態,可能的錯誤等,因爲log.info Test_script.run(testRunner,myCont)它打印toString()方法的結果在WsdlTestStepResult對象上。

如果你想從一個Groovy腳本一步步測試對象傳遞給另一個,你已經使用context變量,它是在每個Groovy腳本一步步測試可用。

對於你的情況,因爲你正在運行使用TestStep.run(TestCaseRunner testRunner,TestCaseRunContext testRunContext)從第二個劇本第一Groovy腳本,你可以回到你的第一個腳本的context添加傳遞給run第二個與testRunContext對象的所有對象方法。讓我用一個例子顯示它:

在第一Groovy腳本添加你的文字作爲context的屬性:在你的第二個腳本

// instead of log put the text in a context property 
context.setProperty('somePropToGetBack','Running from different test case script') 
// you can put all the properties you want... 
context.setProperty('anotherOne','more props') 

然後你只需要拿回這些屬性:

package com.eviware.soapui.impl.wsdl.testcase.WsdlTestRunContext 
def Test_script= testRunner.testCase.testSuite.project.testSuites["TestSuite"].testCases["TestCase"].testSteps["Check"] 
def myCont= new WsdlTestRunContext(Test_script) 
def result = Test_script.run(testRunner,myCont) 

// after execution in myCont variable you've all properties you set 
// in context variable of first script 
log.info myCont.getProperty('somePropToGetBack') // prints Wed May 18 14:56:36 CEST 2016:INFO:Running from different test case script 
log.info myCont.getProperty('anotherOne') // prints Wed May 18 14:56:36 CEST 2016:INFO:more props 

希望它能幫助,

+0

太感謝你了。我一直在尋找teststep.run概念。感謝您解釋它。 – sunny

+0

@sunny很高興幫助你':)'。您還可以檢查['TestStepResult'](https://www.soapui.org/apidocs/com/eviware/soapui/impl/wsdl/teststeps/WsdlTestStepResult.html)中的所有可用內容,運行'方法,看看有些是你的情況。 – albciff

相關問題