Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Expand
titleTest Listeners for Python/Behave

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


pass


def after_command(self, driver, command_tracker):


# your implmentation to be performed after command goes here


pass


def on_exception(self, driver, command_tracker):


# your implmentation to be performed when some exception occurs goes here


pass


Example of such listener is attached here2. : wd_listener.py


WebElement Event Listener

WebElement 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


pass


def after_command(self, driver, command_tracker):


# your implmentation to be performed after command goes here


pass


def on_exception(self, driver, command_tracker):


# your implmentation to be performed when some exception occurs goes here


pass


Example of such listener is attached here: we_listener.py


Behave Listeners

One 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.


...