Continuous Test Orchestration And Execution Platform Online

Perform automated and live-interactive testing on 3000+ real desktop and mobile devices online.

What are Listeners in Selenium?

Let’s consider a scenario where you are working on Java automation using Selenium and want to log the order of each event run and capture screenshots when a test ends, or there is an exception. To achieve this, you can add a function call after each event, like click which logs it, and add a function to take a screenshot after each case ends.

However, this would be a cumbersome task and require a lot of effort. This is where Listeners comes into the picture.

Automated testing tools like Selenium provides numerous functionalities to allow interaction between different web pages. One of these functionalities is Listeners. It can listen to a specific event, like entering data, clicking a button, etc. It is often used for customizing reports and logs. Listeners serve as an interface that can alter system behavior.

In Selenium, there are two types of Listeners.

  • WebDriver Listeners: It contains predefined methods that let you implement methods and classes. For example, WebDriverEventListener and EventFiringWebDriver. These events help to view the events triggered by the Webdriver.

  • TestNG Listeners: It allows you to customize test logs and reports according to your project requirements. In Selenium WebDriver, they are modules that listen to specific events and track test execution while performing some action at each stage.
LambdaTest

Test your websites, web-apps, or mobile apps seamlessly with LambdaTest.

Start Free Testing
LambdaTest

Earn resume-worthy Selenium certifications that help you land a top job.

Learn More
LambdaTest

Test your web or mobile apps

Test orchestration and execution cloud of 3000+ browsers and OS

Support

24/7 support

Security

Enterprise grade security

Cloud

Fastest test execution cloud