I'm writing a script in java using selenium to read the new messages received on web WhatsApp by detecting the new message count red bubble and opening it and reading last x unread messages. I'm able to do that successfully. But what I want that is to call that test every time a new message is received and want it to deploy on the server with a web WhatsApp logged in with a number which remains opened like a website and want to run my script whenever I received a new message.
One way which is working is to call infinitely the Test in AfterTest, which is working fine in my case. But I want to know is there any other way to do that?