cancel
Showing results for 
Search instead for 
Did you mean: 

Groovy to run a specific test step and then abort the test case

SOLVED
Highlighted
Occasional Contributor

Groovy to run a specific test step and then abort the test case

In one of my re-usable test case I have 5 steps(requests) and I want to write a groovy step (in the same test case) which should read the property and based on its value should run one of the available 5 steps and ignore rest of them.

Basically dynamically pick and run a test step and then abort the test case.

 

Thanks in advance for help.

1 ACCEPTED SOLUTION

Accepted Solutions
Contributor

Re: Groovy to run a specific test step and then abort the test case

def tc=testRunner.testCase.testSuite.getTestCaseByName("TestCaseName")
tc.getTestStepList().each{

if(it.name.toString()=="StepName"){
it.run(testRunner,context)
testRunner.cancel("just stop the testCase")
return null;
}
log.info(it.name)
}

 

Did my reply answer your question? Give Kudos or Accept it as a Solution to help others.Smiley Wink

View solution in original post

3 REPLIES 3
Contributor

Re: Groovy to run a specific test step and then abort the test case

def tc=testRunner.testCase.testSuite.getTestCaseByName("TestCaseName")
tc.getTestStepList().each{

if(it.name.toString()=="StepName"){
it.run(testRunner,context)
testRunner.cancel("just stop the testCase")
return null;
}
log.info(it.name)
}

 

Did my reply answer your question? Give Kudos or Accept it as a Solution to help others.Smiley Wink

View solution in original post

Occasional Contributor

Re: Groovy to run a specific test step and then abort the test case

Thanks for the response but I just realized (after using your solution) that I forgot to mention that I am using a session start step before this groovy step and to run any specific test case through groovy I also have to pass on  the session.

And the problem is I am not able to pass on the session using groovy.

Here is the test case structure:

Step #1 Session Start

Step#2 Groovy to run a specific test step among next 5 steps (Test1...Test5)

Step#3 Test1

Step#4 Test2

Step#5 Test3

Step#6 Test4

Step#7 Test5

Occasional Contributor

Re: Groovy to run a specific test step and then abort the test case

Never Mind. I figured the way to pass on the session.

Thanks for your help though.

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