WebDriverEvenListner interface and EventFiringWebDriver class
When you are running test using WebDriver Interface in Selenium there are many events that get fired before and after navigation to an URL.
EventFiringWebDriver class is a wrapper for normal WebDriver interface, that gives the capability to WebDriver to fire Events. EventListener class (let’s say) which implements WebDriverEventListner handles all the events that are dispatched by EventFiringWebDriver class
To capture even there are two different type of implementations
- By creating a class say EventListner implements WebDriverEventListner
OR
2. By creating a class say EventListner extends AbstractWebDriverEventListner
class EventListner implements WebDriverEventListener
{
@Overriding method
////////// NAVIGATION RELATED METHODS ////////////////
/////////////////// FINDBY RELATED METHODS ///////////////
//////////////////// CLICKON RELATED METHODS ///////////////
///////////////// CHANGE OF VALUE RELATED METHODS //////////////
/////////////// SCRIPT EXECUTION RELATED METHODS ///////////////
/////////////// EXCEPTION RELATED METHODS ///////////////////////
}
/***
* Step -02 Register the WebDriverEventListner (Listener) with the WebDriver
* instance. 1. Create WebDriver instance 2. Create EventFiringWebDriver
* instance and pass the WebDriver object to EventFiringWebDriver
* constructor argument. 3. Create an instance of EventListener.
* EventListner class created at step-01 4. Register the listener i.e
* EventFiringWebDriver efwd = new EventFiringWebDriver(driver)
* efwd.register(object of EventListner)
*
*/
public static void registerListener(WebDriver driver) {
// 1. Create WebDriver instance
driver = new ChromeDriver();
// * 2. Create EventFiringWebDriver instance and pass the WebDriver
// object to EventFiringWebDriver constructor argument.
EventFiringWebDriver efwd = new EventFiringWebDriver(driver);
// * 3. Create an instance of EventListener. EventListner class created
// at step-01
EventListner listner = new EventListner();
// * 4. Register the listener
efwd.register(listner);
}
No comments:
Post a Comment