How to get testName used in testNG annotation?

117 views
Skip to first unread message

vinod kumar

unread,
Aug 13, 2019, 4:34:24 AM8/13/19
to testng-users
I want to print the testName which is used in TestNG annotation below;

Please help me out to print testName

@Test(priority = 1,testName="SANITY-TEST-001")
    public void loginVerificationSuccess() {
        //code here
    }

Thanks,
Vinod Kumar K

⇜Krishnan Mahadevan⇝

unread,
Aug 13, 2019, 6:48:06 AM8/13/19
to testng...@googlegroups.com
Where exactly are you trying to get the "testName" in? Is it within the same test method or somewhere else ?

Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"
My Scribblings @ http://wakened-cognition.blogspot.com/
My Technical Scribblings @ https://rationaleemotions.com/


--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to testng-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/testng-users/3812d2a7-9c29-4798-9621-409c1f8651e5%40googlegroups.com.

vinod kumar

unread,
Aug 13, 2019, 6:58:33 AM8/13/19
to testng-users

within the same method.


On Tuesday, August 13, 2019 at 4:18:06 PM UTC+5:30, Krishnan Mahadevan wrote:
Where exactly are you trying to get the "testName" in? Is it within the same test method or somewhere else ?

Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"
My Scribblings @ http://wakened-cognition.blogspot.com/
My Technical Scribblings @ https://rationaleemotions.com/


On Tue, Aug 13, 2019 at 2:04 PM vinod kumar <k.vin...@gmail.com> wrote:
I want to print the testName which is used in TestNG annotation below;

Please help me out to print testName

@Test(priority = 1,testName="SANITY-TEST-001")
    public void loginVerificationSuccess() {
        //code here
    }

Thanks,
Vinod Kumar K

--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to testng...@googlegroups.com.

vinod kumar

unread,
Aug 13, 2019, 7:07:03 AM8/13/19
to testng-users
And outside method as well

⇜Krishnan Mahadevan⇝

unread,
Aug 13, 2019, 7:07:13 AM8/13/19
to testng...@googlegroups.com
Try something like this


Reporter.getCurrentTestResult().getMethod().getConstructorOrMethod().getMethod().getAnnotation(Test.class).testName();

Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"
My Scribblings @ http://wakened-cognition.blogspot.com/
My Technical Scribblings @ https://rationaleemotions.com/

To unsubscribe from this group and stop receiving emails from it, send an email to testng-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/testng-users/374ca508-6c03-4a48-a37c-f48958f324ea%40googlegroups.com.

⇜Krishnan Mahadevan⇝

unread,
Aug 13, 2019, 7:10:31 AM8/13/19
to testng...@googlegroups.com
Outside as in where ?? Please be specific.

Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"
My Scribblings @ http://wakened-cognition.blogspot.com/
My Technical Scribblings @ https://rationaleemotions.com/

To unsubscribe from this group and stop receiving emails from it, send an email to testng-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/testng-users/f0e4f8f8-9415-4eba-8ae1-b76d5173452b%40googlegroups.com.

vinod kumar

unread,
Aug 13, 2019, 7:20:58 AM8/13/19
to testng-users
Thanks,  it worked in within the same @Test annotated method..


I was trying to access it in @BeforeMethod annotated method from @Test annotated method and it's returning NULL


On Tuesday, August 13, 2019 at 4:40:31 PM UTC+5:30, Krishnan Mahadevan wrote:
Outside as in where ?? Please be specific.

Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"
My Scribblings @ http://wakened-cognition.blogspot.com/
My Technical Scribblings @ https://rationaleemotions.com/


⇜Krishnan Mahadevan⇝

unread,
Aug 13, 2019, 7:29:05 AM8/13/19
to testng...@googlegroups.com
"BeforeMethod" annotated method, lets you access a Method object [ which represents the Test Method that will be executed ] You can try querying the Method object directly using reflection for the annotation value.

Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"
My Scribblings @ http://wakened-cognition.blogspot.com/
My Technical Scribblings @ https://rationaleemotions.com/

To unsubscribe from this group and stop receiving emails from it, send an email to testng-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/testng-users/9f17c240-346e-4597-8843-ccabf78bee37%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages