Reputation: 145
I have one groovy script named Check in testcase 1, which contains the follow code:
log.info "Running from different test case script"
I am trying to get this message in a script written in testcase 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)
It gives me output as:
Wed May 18 17:39:57 IST 2016:INFO:com.eviware.soapui.impl.wsdl.teststeps.WsdlTestStepResult@131bc813
What to do here to see proper message in output
Upvotes: 1
Views: 1038
Reputation: 18507
TestStep.run
method doesn't return directly a desired object from other testStep or so, It returns a generic WsdlTestStepResult
object to see the status, possible errors etc.. of the testStep execution, due this log.info Test_script.run(testRunner,myCont)
it's printing the result of toString()
method on WsdlTestStepResult
object.
If you want to pass objects from one groovy script testStep to another, you've to use the context
variable which is available in each groovy script testStep.
For your case since you're running the first groovy script using TestStep.run(TestCaseRunner testRunner,TestCaseRunContext testRunContext)
from the second one script, you can get back all objects added in the context
of your first script in the second one with testRunContext
object passed to run
method. Let me show it with an example:
In the first groovy script add your text as a property of the 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')
Then in your second script you only have to get back these properties:
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
Hope it helps,
Upvotes: 2