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

Events and Listeners in Robot Framework

Cerosh Jacob

--

An event listener is a procedure or function in a computer program that waits for an event to occur. Example of events are before changing text, after clicking an element, before URL is loaded, etc. Creating effective logging and test script maintenance are the main conventions of event listener in automated testing. Collecting these details through standard logging is an alternative but explicit triggering would be required. Reducing the lines of code and make programmatic interface cleaner can be extra benefit of event listener.

While executing the automation scripts Selenium WebDriver track the numerous events that happen. By design, the listener will react to an event by calling the event’s handler. In Selenium WebDriver EventFiringWebDriver, class throws an event and an interface named EventListener catches that event. Through EventFiringWebDriver, the user can have control to transform the default behavior of the driver. For example, a test failure event activates the automatic screen capture method defined in the EventListener and starts logging screenshots.

SeleniumLibrary 4.0 has enabled importing EventFiringWebDriver listener class as a parameter while importing the SeleniumLibrary. Current implementation supports only EventFiringWebDriver listener class written in Python.

*** 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

The sample script

  1. Launch a chrome browser.
  2. Navigate to the specified URL.
  3. Enter text in text box.
  4. Close the browser opened.
from robot.api import logger…

--

--