...
Expand | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Automation ListenersYou can create listener by implementing appropriate listener interface of by extending appropriate adapter class. To register one or more listener you need to set appropriate property. Listeners API Table
There is additional Adapter Class TestStep ListenerIn order to create teststep listener, you need to implement listener interface
Creating Listener
Registering listenerTo register listener set property teststep.listeners. For example to register above created listener you need to set property as below:
WebDriver ListenerIn order to create webdriver command listener, you need to implement listener interface
Creating listener
Registering listenerTo register listener set property wd.command.listeners. For example to register above created listener you need to set property as below:
WebElement ListenerA simple but very useful example of listener is “listener for sendkeys”. As you know in webdriver send keys will append the text box, so each time we need to first call clear command and then use send keys command. Code Without listener:
Code With use of listener:
Creating listener:In order to create webelement command listener, you need to implement listener interface
Below example illustrates how we can write a listener that clears element text before sending text.
In this example we had extended adapter class for webelement command listener and provided implementation for Registering listenerTo register listener set property we.command.listeners. For example to register above created listener you need to set property as below:
TestNG ListenersOne can create and use different kind of TestNG listeners. Please refer TestNG documentation for more information and examples. |
Expand | ||
---|---|---|
| ||
In Behave, listeners are often referred as hooks. Automation ListenersIn resources/application.properties file you can mention your test listener python classes. e.g. wd.command.listeners=model.listener.Listener There are two types of Automation Listeners
def after_command(self, driver, command_tracker): def on_exception(self, driver, command_tracker): Example of such listener is attached here 2. WebElement Event Listener - specify using `we.command.listeners` key, separated by ';' def after_command(self, driver, command_tracker): def on_exception(self, driver, command_tracker): Example of such listener is attached here Behave ListenersOne can create and use different kind of Behave listeners. Refer to Behave documentation for more information and examples. |