简体   繁体   中英

What is the difference between WebDriver listener and TestNG listener?

What is the difference between WebDriver listener and TestNG listener? How to implement the same?

WebDrier Event Listener is to listen the events triggered by webdriver like beforeClickOn, afterClickOn, beforeFindBy, afterFindBy, etc and take actions. It is mainly used to write log file for selenium test execution.

TestNG listener mainly used to generate the report for the test. Also, you can capture screenshot when there is test failure. TestNG events are like onTestFailure, onTestSkipped, onTestSuccess, etc.

The generic word " Listener " has a common meaning to listen " Events ". For example for a button, click is event and the method which is called on click is OnClick ().

So in above example whenever anyone clicks on the button automatically some method (actionPerformed() in ActionListener case) will be called.

In case of TestNG there are listeners which listens (that means, method get called automatically) the test execution events. examples are onStart () beforeStart () afterFinish () onFinish () etc.

Most of the times, In TestNG automation devs implements their own custom listeners for custom Logging and reporting .

WebDriver also has listeners which is doing very much similar job like TestNG listeners of logging and/or reporting but both works on different events. 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.

You can find more info here - https://www.packtpub.com/mapt/book/web_development/9781782168850/5/ch05lvl1sec29/exploring-different-webdriver-event-listeners

Vikas.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM