简体   繁体   English

WebDriver侦听器和TestNG侦听器有什么区别?

[英]What is the difference between WebDriver listener and TestNG listener?

What is the difference between WebDriver listener and TestNG listener? WebDriver侦听器和TestNG侦听器有什么区别? 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. WebDrier事件侦听器将侦听由网络驱动程序触发的事件,例如beforeClickOn,afterClickOn,beforeFindBy,afterFindBy等,并采取措施。 It is mainly used to write log file for selenium test execution. 它主要用于编写用于硒测试执行的日志文件。

TestNG listener mainly used to generate the report for the test. TestNG侦听器主要用于生成测试报告。 Also, you can capture screenshot when there is test failure. 另外,您可以在测试失败时捕获屏幕截图。 TestNG events are like onTestFailure, onTestSkipped, onTestSuccess, etc. TestNG事件类似于onTestFailure,onTestSkipped,onTestSuccess等。

The generic word " Listener " has a common meaning to listen " Events ". 通用词“ Listener ”具有侦听“ Events ”的共同含义。 For example for a button, click is event and the method which is called on click is OnClick (). 例如,对于一个按钮,click是事件,单击时调用的方法是OnClick ()。

So in above example whenever anyone clicks on the button automatically some method (actionPerformed() in ActionListener case) will be called. 因此,在上面的示例中,只要有人自动单击按钮,就会调用某些方法(在ActionListener情况下为actionPerformed())。

In case of TestNG there are listeners which listens (that means, method get called automatically) the test execution events. 在使用TestNG的情况下,有一些侦听器可以侦听(即,方法将自动调用)测试执行事件。 examples are onStart () beforeStart () afterFinish () onFinish () etc. 例如onStart () beforeStart () afterFinish () onFinish ()等。

Most of the times, In TestNG automation devs implements their own custom listeners for custom Logging and reporting . 在大多数情况下,在TestNG中,自动化开发人员实现自己的自定义侦听器,以进行自定义日志记录和报告

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还具有侦听器,它们的工作非常相似,例如记录和/或报告的TestNG侦听器,但两者都适用于不同的事件。 WebDriver works on different automation events whereas TestNG works on different test's related events. WebDriver处理不同的自动化事件,而TestNG处理不同的测试的相关事件。

The main reason for WebDriver listeners is "Logging" before / after events like click / SendKeys etc. WebDriver侦听器的主要原因是在诸如click / SendKeys等事件发生之前/之后进行“记录”。

You can find more info here - https://www.packtpub.com/mapt/book/web_development/9781782168850/5/ch05lvl1sec29/exploring-different-webdriver-event-listeners 您可以在这里找到更多信息-https: //www.packtpub.com/mapt/book/web_development/9781782168850/5/ch05lvl1sec29/exploring-different-webdriver-event-listeners

Vikas. 维卡斯

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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