Groovy 索皮;在不同的测试用例中获得结果

Groovy 索皮;在不同的测试用例中获得结果,groovy,soapui,Groovy,Soapui,我有一个名为Check in testcase 1的groovy脚本,其中包含以下代码: log.info "Running from different test case script" 我试图在testcase 2中编写的脚本中获得此消息: 包com.eviware.soapui.impl.wsdl.testcase; Test_script=testRunner.testCase.testSuite.project.testSuites[“testSuite”]。testCases[“

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

log.info "Running from different test case script"
我试图在testcase 2中编写的脚本中获得此消息:

包com.eviware.soapui.impl.wsdl.testcase;
Test_script=testRunner.testCase.testSuite.project.testSuites[“testSuite”]。testCases[“testCase”]。testSteps[“Check”]
def myCont=new WsdlTestRunContext(测试脚本)
log.info Test_script.run(testRunner,myCont)
它给我的输出是:

2016年5月18日星期三17:39:57 IST:INFO:com.eviware.soapui.impl.wsdl.teststeps。WsdlTestStepResult@131bc813


这里要做什么才能在输出中看到正确的消息。run方法不会直接从其他TestStep返回所需的对象,因此,它会返回一个通用对象以查看状态、可能的错误等。。由于这个
log.info Test\u script.run(testRunner,myCont)
它正在
WsdlTestStepResult
对象上打印
toString()
方法的结果

如果要将对象从一个groovy脚本测试步骤传递到另一个groovy脚本测试步骤,必须使用每个groovy脚本测试步骤中可用的
context
变量

对于您的情况,因为您正在使用第二个脚本运行第一个groovy脚本,所以可以使用传递给
run
方法的
testRunContext
对象,在第二个脚本的
context
中返回添加的所有对象。让我用一个例子来说明:

在第一个groovy脚本中,将文本作为
上下文的属性添加:

//将文本放在上下文属性中,而不是日志
setProperty('somePropToGetBack','Running from Other test case script')
//你可以把你想要的所有属性。。。
setProperty('anotherOne','more props')
然后,在第二个脚本中,您只需返回以下属性:

包com.eviware.soapui.impl.wsdl.testcase.WsdlTestRunContext
def Test_script=testRunner.testCase.testSuite.project.testSuites[“testSuite”]。testCases[“testCase”]。testSteps[“Check”]
def myCont=new WsdlTestRunContext(测试脚本)
def result=Test_script.run(testRunner,myCont)
//在myCont变量中执行后,您已经设置了所有属性
//在第一个脚本的上下文变量中
log.info myCont.getProperty('somePropToGetBack')//打印星期三5月18日14:56:36 CEST 2016:info:从不同的测试用例脚本运行
log.info myCont.getProperty('anotherOne')//打印星期三5月18日14:56:36 CEST 2016:info:更多道具

希望对您有所帮助,

TestStep.run
方法不会直接从其他TestStep返回所需的对象,因此,它会返回一个通用对象以查看状态、可能的错误等。。由于这个
log.info Test\u script.run(testRunner,myCont)
它正在
WsdlTestStepResult
对象上打印
toString()
方法的结果

如果要将对象从一个groovy脚本测试步骤传递到另一个groovy脚本测试步骤,必须使用每个groovy脚本测试步骤中可用的
context
变量

对于您的情况,因为您正在使用第二个脚本运行第一个groovy脚本,所以可以使用传递给
run
方法的
testRunContext
对象,在第二个脚本的
context
中返回添加的所有对象。让我用一个例子来说明:

在第一个groovy脚本中,将文本作为
上下文的属性添加:

//将文本放在上下文属性中,而不是日志
setProperty('somePropToGetBack','Running from Other test case script')
//你可以把你想要的所有属性。。。
setProperty('anotherOne','more props')
然后,在第二个脚本中,您只需返回以下属性:

包com.eviware.soapui.impl.wsdl.testcase.WsdlTestRunContext
def Test_script=testRunner.testCase.testSuite.project.testSuites[“testSuite”]。testCases[“testCase”]。testSteps[“Check”]
def myCont=new WsdlTestRunContext(测试脚本)
def result=Test_script.run(testRunner,myCont)
//在myCont变量中执行后,您已经设置了所有属性
//在第一个脚本的上下文变量中
log.info myCont.getProperty('somePropToGetBack')//打印星期三5月18日14:56:36 CEST 2016:info:从不同的测试用例脚本运行
log.info myCont.getProperty('anotherOne')//打印星期三5月18日14:56:36 CEST 2016:info:更多道具

希望能有所帮助,

非常感谢。。我在寻找teststep.run概念。谢谢你的解释。@sunny很高兴能帮助你
:)
。您还可以在返回自
run
方法中检查所有可用的内容,以查看其中是否有适用于您的案例的UTIL。非常感谢。。我在寻找teststep.run概念。谢谢你的解释。@sunny很高兴能帮助你
:)
。您还可以在返回自
run
方法中检查所有可用的内容,以查看其中是否有适用于您案例的UTIL。