In Behave, listeners are often referred as hooks. Automation Listeners
In resources/application.properties file you can mention your test listener python classes. e.g. wd.command.listeners=model.listener.Listener we.command.listeners=model.listener.ElementListener There are two types of Automation Listeners1.
WebDriver Event Listener WebDriver Event Listener - specify using `wd.command.listeners` key, separated by ';' Listener class should extend/implement below methods.
Code Block |
---|
def before_command(self, driver, command_tracker): |
# your implmentation to be performed before command goes here |
def after_command(self, driver, command_tracker): |
# your implmentation to be performed after command goes here |
def on_exception(self, driver, command_tracker): |
# your implmentation to be performed when some exception occurs goes here |
Example of such listener is attached here2. : wd_listener.py
WebElement Event ListenerWebElement Event Listener - specify using `we.command.listeners` key, separated by ';' Listener class should extend/implement below methods Code Block |
---|
def before_command(self, driver, command_tracker): |
# your implmentation to be performed before command goes here |
def after_command(self, driver, command_tracker): |
# your implmentation to be performed after command goes here |
def on_exception(self, driver, command_tracker): |
# your implmentation to be performed when some exception occurs goes here |
Example of such listener is attached here: we_listener.py
Behave ListenersOne can create and use different kind of Behave listeners. Refer to Behave documentation for more information and examples. One such listener/hook is environment.py file, which controls the driver management and execution.
|