Ask a Question

Can we get the test case name in BeforeTestCase

SOLVED
SanthoshShetty
Occasional Contributor

Can we get the test case name in BeforeTestCase

Hi All,

 

We are implementing a custom framework for our project and for that we need to know the test case name in the Event handler - BeforeTestCase, so that we using the Testcase name we will write a groovy logic do the implementation for the next steps.

 

Can some please help me how to achieve this.

 

E.g.,

 

1) TestCase1

2) TestCase2

3) TestCase3

 

I have the above three testcases and an Event - BeforeTestCase. So am writing a logic in Groovy script and I need the testcasename that is "TestCase1" before the execution of "TestCase1" and testcasename "TestCase2" before the execution of TestCase2...

 

Thank you.

3 REPLIES 3
Radford
Super Contributor

Assuming that you are referring to the "TestSuiteRunListener.beforeTestCase" event handler, it provides you with a variable "testCase" for you to use. Thus the test case name cand be accessed via:

 

log.info('Current Test Case = ' + testCase.getName())

 

If you haven't already spotted, each script editor will indicate what variables it provides (see screenshot below). These will be dependent on the specific editor you are looking at.

 

scripteditor.png

 

SanthoshShetty
Occasional Contributor

Radford,

Thanks a lot it worked.

HimanshuTayal
Community Hero

you can simply write:

 

log.info testRunner.testCase.getName()

 

if using groovy script as a TestStep, it will show you the Name of current TestCase.


Click "Accept as Solution" if my answer has helped,
Remember to give "Kudos" 🙂 ↓↓↓↓↓



Thanks and Regards,
Himanshu Tayal
cancel
Showing results for 
Search instead for 
Did you mean: