Image for post
Image for post
https://www.developer.com/java/data/understanding-and-using-the-java-delegation-event-model.html

Events and Listeners in Robot Framework

*** Settings ***
Library SeleniumLibrary event_firing_webdriver=${CURDIR}/RobotFrameworkListener.py
Suite Teardown Close Browser
*** Variables ***
${URL} http://www.google.com
${SEARCH} q
***Keywords***
Open ${URL} in The Browser ${browser_name}
Create Webdriver ${browser_name} executable_path=/usr/local/bin/chromedriver
Go To ${URL}
Find ${locator} Element And Enter ${text}
Input Text ${locator} ${text}
*** Test Cases ***Test Case For Event Firing And Listener
Open ${URL} in The Browser Chrome
Find ${SEARCH} Element And Enter Event Firing
from robot.api import logger
from selenium.webdriver.support.events import AbstractEventListener
class RobotFrameworkListener(AbstractEventListener):
def before_navigate_to(self, url, driver):
logger.info("URL before navigation: '%s'." % url)
def after_navigate_to(self, url, driver):
logger.info("URL after navigation: '%s'." % driver.current_url)
def before_change_value_of(self, element, driver):
dict= element.get_property('attributes')
element_value = dict[2]['value']
logger.info("Before clearing/entering the text field '%s'." % element_value)
def after_change_value_of(self, element, driver):
dict= element.get_property('attributes')
element_value = dict[2]['value']
logger.info("After clearing/entering the text field '%s'." % element_value)
Given below is the console log when event_firing_webdriver parameter is not used.
Given below is the console log when event_firing_webdriver parameter is not used.
Console log when event_firing_webdriver parameter is not used.
Image for post
Image for post
Console log when listener class is passed to event_firing_webdriver parameter.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store