cancel
Showing results for 
Search instead for 
Did you mean: 

Get the status of a teststep that already has been executed

SOLVED
HanTest
Occasional Contributor

Get the status of a teststep that already has been executed

I want to get the status of a previously runned teststep in a groovyscript step.

How can this be done?

1 ACCEPTED SOLUTION

Accepted Solutions
nmrao
Community Hero

Re: Get the status of a teststep that already has been executed

The step2 actually running the step1 as well to get the status.

 

When go thru the question again, looks you are interested only getting the status not actually running it. 

So, another example for the same, but this wont run the previous step again.

 

import com.eviware.soapui.impl.wsdl.teststeps.WsdlTestStep
import com.eviware.soapui.impl.wsdl.teststeps.WsdlTestStepResult
def step = context.testCase.testStepList[context.currentStepIndex - 1]
assert step instanceof WsdlTestStep
def result = new WsdlTestStepResult(step)
log.info result.status



Regards,
Rao.

View solution in original post

10 REPLIES 10
gsfurtado
Occasional Contributor

Re: Get the status of a teststep that already has been executed

Hello,

What do you mean by "status of a testStep"?

I think that wsdlTestStep doesn't have a status attribute.

Regards,

 

http://www.soapui.org/apidocs/com/eviware/soapui/impl/wsdl/teststeps/WsdlTestStep.html

def testCase;
def testStep;
def myStepName ='someName';
testCase = testRunner.getTestCase();
testStep = testCase.getTestStepByName(myStepName);

nmrao
Community Hero

Re: Get the status of a teststep that already has been executed

Took two steps to try this.

 

1. step1 - groovy script - this dynamically passes at times and fails at times

2. step2 - groovy script - which is actully you are interested in to find the status of step2 in here.

 

I know you may not be interested in step1, just giving  for the testablity for someone.

 

Script that is part of step1

/**

* generate a randon number, fail the step if non-zero

**/

def result = ((new Random().nextInt(2))+1)%2
assert result, "failed the test"

---------------------------------------------------------------------------------------

 

Script that is part of step2 

/**

* get the previous test step index, then get the previous test step name

* run the test step by its name

* get its status

**/

def step1Result = testRunner.runTestStepByName(context.testCase.testStepList[context.currentStepIndex - 1].name)
log.info step1Result.status



Regards,
Rao.
nmrao
Community Hero

Re: Get the status of a teststep that already has been executed

The step2 actually running the step1 as well to get the status.

 

When go thru the question again, looks you are interested only getting the status not actually running it. 

So, another example for the same, but this wont run the previous step again.

 

import com.eviware.soapui.impl.wsdl.teststeps.WsdlTestStep
import com.eviware.soapui.impl.wsdl.teststeps.WsdlTestStepResult
def step = context.testCase.testStepList[context.currentStepIndex - 1]
assert step instanceof WsdlTestStep
def result = new WsdlTestStepResult(step)
log.info result.status



Regards,
Rao.

View solution in original post

HanTest
Occasional Contributor

Re: Get the status of a teststep that already has been executed

This is exactly what I was looking for thank you very much!

HanTest
Occasional Contributor

Re: Get the status of a teststep that already has been executed

When I run this script it always logs an UNKNOWN

 

I've also tried to use getStatus() but unfortunately this also results in an Unkown:

1.jpg2.jpg

 

gsfurtado
Occasional Contributor

Re: Get the status of a teststep that already has been executed

"When I run this script it always logs an UNKNOWN"

 

That's because the instance result it's empty.

You only know the status of a certain step after you run the step.

That's what the TestRunner class does. It loop's all the test steps and invoques the method: runTestStep()

 

Basically I think that you can get the result by two ways:

(a) Run the step again from the groovy script

(b) Try to get the testStep result that testRunner got when it ran the testStep

 

The problem for each option is that:

(a) If you run that step for a second time will you get the same result?

(b) If you run the testCase and you reach your groovy Step in order to pick up the testRunner variable it's because all the previous testSteps were succeeded.

 

For option (a) try the following scritpt:

 

import com.eviware.soapui.impl.wsdl.teststeps.WsdlTestStep;
import com.eviware.soapui.impl.wsdl.teststeps.WsdlTestStepResult;
import com.eviware.soapui.impl.wsdl.testcase.WsdlTestCaseRunner;
def step = context.testCase.testStepList[context.currentStepIndex - 1];
assert step instanceof WsdlTestStep;
def testCase = context.getTestCase();
def testRunner = new WsdlTestCaseRunner(testCase, null);
def result = testRunner.runTestStep(step)
log.info result.getStatus();

 

 

 

HanTest
Occasional Contributor

Re: Get the status of a teststep that already has been executed

The thing is that I allready runned the TestCase so I don't get why I should invoke the runner for a second time.

Isn't there a way to get the result of the previous step without having to do a runTestStep()?

 

for reporting I can use: ${=testRunner.results[testRunner.results.size()-1].status} but isn;'t there something like that in the groovyscript step?

 

Otherwise maybe someone can help me out on hangouts so I can show the project.

gsfurtado
Occasional Contributor

Re: Get the status of a teststep that already has been executed

 

Try this:

 

import com.eviware.soapui.impl.wsdl.teststeps.WsdlTestStep;
def step = context.testCase.testStepList[context.currentStepIndex - 1];
assert step instanceof WsdlTestStep;
testRunner.results[context.currentStepIndex - 1].getStatus()

HanTest
Occasional Contributor

Re: Get the status of a teststep that already has been executed

Unfortunately I get a Null Object

 

Edit: I think I'll just disable the soaprequest step and then use the groovyteststep to run the soaprequest step.

This works but doesn't feel like the right way to do it 😉

New Here?
Join us and watch the welcome video:
Announcements
Top Kudoed Authors