Hi Dheeraj, Listeners “listen” to the event defined in the selenium script and behave accordingly. The main purpose of using listeners is to create logs and reports. There are many types of listeners such as WebDriver Event Listeners and TestNG Listeners. It is used in selenium by implementing Listeners Interface. There are many types of listeners available:
WebDriver works on different automation events whereas TestNG works on different test's related events. The main reason for WebDriver listeners is "Logging" before / after events like click / SendKeys etc. WebDriverEventListener interface allows us to implement the methods once the script is executed, Selenium WebDriver does perform activities such as Type, Click, Navigate etc, To keep track of these activities we use WebDriverEventListeners interface.
While, in case of TestNG there are listeners which listens the test execution events. For eg.onStart() beforeStart() afterFinish() onFinish() etc. Most of the times, In TestNG automation devs implements their own custom listeners for custom Logging and reporting.