肥皂;在不同的测试用例中获得结果

时间:2016-05-18 12:14:45

标签: groovy soapui

我有一个名为Check in testcase 1的 groovy脚本,其中包含以下代码:

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)

它输出为:

  

Wed May 18 17:39:57 IST 2016:INFO:com.eviware.soapui.impl.wsdl.teststeps.WsdlTestStepResult@131bc813

如何在输出中查看正确的消息

1 个答案:

答案 0 :(得分:2)

TestStep.run方法不会直接从其他testStep返回所需的对象,它返回一个通用的WsdlTestStepResult对象来查看testStep执行的状态,可能的错误等。由于此log.info Test_script.run(testRunner,myCont),它会在toString()对象上打印WsdlTestStepResult方法的结果。

如果要将对象从一个 groovy脚本 testStep传递到另一个,请使用每个 groovy脚本中可用的context变量 testStep。

对于您的情况,因为您使用第二个脚本中的TestStep.run(TestCaseRunner testRunner,TestCaseRunContext testRunContext)运行第一个 groovy脚本,您可以取回context中添加的所有对象将testRunContext对象传递给run方法的第二个脚本中的第一个脚本。让我用一个例子来说明:

在第一个 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

希望它有所帮助,