MainMenu

Home Core Java Overview Maven Tutorials

Tuesday, 30 July 2019

test

<nav class="menu"> <ul class="active"> <li class="current-item"><a href="#">Home</a></li> <li><a href="#">My Work</a></li> <li><a href="#">About Me</a></li> <li><a href="#">Get in Touch</a></li> <li><a href="#">Blog</a></li> </ul> <a class="toggle-nav" href="#">&#9776;</a> <form class="search-form"> <input type="text"> <button>Search</button> </form> </nav>

Wednesday, 24 July 2019

Listeners In Selenium and TestNG

Listeners in TestNG



Listeners

Listeners are interfaces used in selenium webdriver script that modifies the default behaviour of the system.


The main purpose of listeners is to create Logs and reports.


We can fully customize the logs using Listeners.


Types of Listeners
1). WebDriver Listeners
2). TestNG Listeners

Types of Listeners in TestNG :-
There are several interfaces that allow you to modify TestNG behaviour.
Here are few listeners :-
1).IAnnotation Transformer
2).IAnnotation ransformer2
3). IHookable
4). IInvokeMethodListener
5). IMethodInterceptor
6). Ireporter
7). ISuiteListener
8). ITestListener


How to implement the Listener :-
a). Extends 'TestListenerAdapter' Class
b). Implement Interface 'ITestListener'
also we implement Listeners in Class Level as well as Suite Level




TestNG Listeners
TestNG provides the @Listeners annotation whic listens to every event that occurs in your selenium script.
As the name suggests Listeners "listen" to the event defined in the selenium script and behave accordingly. It is used in selenium by implementing Listeners Interface.
Listener is an interface that modifies the TestNG behaviour.
Types of Listeners in TestNG
There are many types of listeners which allows you to change the TestNG's behavior.
Below are the few TestNG listeners:

1.IAnnotationTransformer ,
2.IAnnotationTransformer2 ,
3.IConfigurable ,
4.IConfigurationListener ,
5.IExecutionListener,
6.IHookable ,
7.IInvokedMethodListener ,
8.IInvokedMethodListener2 ,
9.IMethodInterceptor ,
10.IReporter,
11.ISuiteListener,
12.ITestListener .
Listeners are implemented by the ITestListener interface.
An ITestListener interface has the following methods:
onTestStart(): An onTestStart() is invoked only when any test method gets started.

onTestSuccess(): An onTestSuccess() method is executed on the success of a test method.

onTestFailure(): An onTestFailure() method is invoked when test method fails.

onTestSkipped(): An onTestSkipped() run only when any test method has been skipped.

onTestFailedButWithinSuccessPercentage(): This method is invoked each time when the test method fails but within success percentage.

onStart(): An onStart() method is executed on the start of any test method.

onFinish(): An onFinish() is invoked when any test case finishes its execution.