肥皂泡;在不同的测试用例中得到结果
soapui ; getting result in different Testcase
我有一个 groovy 脚本 名为 Check in testcase 1,其中包含以下代码:
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
在这里要做什么才能在输出中看到正确的消息
TestStep.run
方法不会 return 直接从其他 testStep 左右获取所需的对象,它 return 是一个通用的 WsdlTestStepResult
对象来查看状态,可能的错误等等 testStep 执行,由于这个 log.info Test_script.run(testRunner,myCont)
它在 WsdlTestStepResult
对象上打印 toString()
方法的结果。
如果你想将对象从一个 groovy 脚本 testStep 传递到另一个,你必须使用每个可用的 context
变量groovy 脚本 测试步骤。
对于你的情况,因为你是 运行 第一个 groovy 脚本 使用第二个脚本中的 TestStep.run(TestCaseRunner testRunner,TestCaseRunContext testRunContext)
,你可以得到在第二个脚本中返回第一个脚本的 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
希望对您有所帮助,
我有一个 groovy 脚本 名为 Check in testcase 1,其中包含以下代码:
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
在这里要做什么才能在输出中看到正确的消息
TestStep.run
方法不会 return 直接从其他 testStep 左右获取所需的对象,它 return 是一个通用的 WsdlTestStepResult
对象来查看状态,可能的错误等等 testStep 执行,由于这个 log.info Test_script.run(testRunner,myCont)
它在 WsdlTestStepResult
对象上打印 toString()
方法的结果。
如果你想将对象从一个 groovy 脚本 testStep 传递到另一个,你必须使用每个可用的 context
变量groovy 脚本 测试步骤。
对于你的情况,因为你是 运行 第一个 groovy 脚本 使用第二个脚本中的 TestStep.run(TestCaseRunner testRunner,TestCaseRunContext testRunContext)
,你可以得到在第二个脚本中返回第一个脚本的 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
希望对您有所帮助,