Approach to know LIVE execution duration of a test method

32 views
Skip to first unread message

Sambhav Dave

unread,
Mar 23, 2024, 6:14:33 PMMar 23
to testng-users
So my requirement goes like this:

While the TestNG test method is executing, I want to have a listener tracking the execution time (live). Once it crosses 4 minutes, I basically want to hit an API endpoint to renew a user-access token. 

Folks, can anyone provide some help here? Thanks in advance.


Krishnan Mahadevan

unread,
Mar 23, 2024, 10:18:42 PMMar 23
to testng...@googlegroups.com
Sambhav

You dont need a listener for this. 
You should be able to solve this using a timer. 

You can do something like this. 

1. Create a custom listener which can be used to annotate your test to indicate that a particular test needs this capability of scheduling token refresh 
2. Create a custom listener that parses the custom annotation and if found it schedules a task that refreshes the token. 

If the annotation route sounds complicated you can build the same thing by creating a base class ( which only your token refresh test cases will extend ) and which implements IHookable interface. Within this implementation you can add the logic of creating and starting a timer which you can stop after the test finishes and before you exit the run() method. 


Hope that helps

Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"

From: testng...@googlegroups.com <testng...@googlegroups.com> on behalf of Sambhav Dave <samb...@gmail.com>
Sent: Sunday, March 24, 2024 2:09:56 AM
To: testng-users <testng...@googlegroups.com>
Subject: [testng-users] Approach to know LIVE execution duration of a test method
 
So my requirement goes like this:

While the TestNG test method is executing, I want to have a listener tracking the execution time (live). Once it crosses 4 minutes, I basically want to hit an API endpoint to renew a user-access token. 

Folks, can anyone provide some help here? Thanks in advance.


--
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/f5990c2d-7049-4082-beae-8a31bd9bede2n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages