Robot Framework is a generic open-source test automation framework for acceptance testing, acceptance test-driven development (ATDD) and robotic process automation (RPA).

It has easy-to-use tabular test data syntax and it utilizes the keyword-driven testing approach. You can build the automated script by integrating all necessary built-in, third-party keywords and users can create new higher-level keywords from existing ones using the same syntax that is used for creating test cases.

In previous blog, we’ve introduced how to customize your own keyword libraries and achieve extendable listener. This article will introduce the expansion of Robot Framework related Selenium library.

Why is this needed?

In some projects, Dilato use Robot framework to make it easier to develop automated test scripts. Even for manual test engineers with less programing skills, only if they’ve got familiar with all the keywords usages.  So the best practices are as below:

  • Automation engineer achieves and customize all the keywords and the project structure.
  • Train manual engineers to write test scripts, because they know better how to test function and ensure the product quality.
  • Automation engineer schedule and regression all the scripts.
  • All engineers take responsibility to the failed scripts.

It looks like a perfect process, but as the team gets bigger and bigger. When the existing keywords cannot meet the testing needs, we may have to extend those third-party libraries, instead of rewriting a new one.

Some people hack the source code of third-party libraries and add new functions in it. Emm…that’s works indeed. But it brings difficulties to update with new version of those libraries, or cannot install them normally from warehouse, or have to add new repositories for them, the whole regression pipeline needs to be updated…more other disadvantages will come with doing so.

After repeated practice, Dilato team found a better choice which is to expand the third-party library of the Robot Framework framework. This article will explain the method in detail.

Runbook

SeleniumLibrary offers three main ways to creating new functionality for it: Plugin API, EventFiringWebDriver and building new libraries on top the SeleniumLibrary. Plugin API and extending SeleniumLibrary allows similar access to the SeleniumLibrary public API and offers their own pros and cons for building custom functionality on top the SeleniumLibrary. The EventFiringWebDriver offers listener-like interface to the Selenium API.

Plugin API
SeleniumLibrary offers plugins as a way to modify, add library keywords and modify some of the internal functionality without creating new library or hacking the source code. You can only load plugins by library import syntax. Creating new plugins is stricter than creating new libraries, but plugins allows more access to the methods that are used to implement the keywords.

EventFiringWebDriver
The EventFiringWebDriver is a listener type of API offered by the Selenium. The EventFiringWebDriver allows to listen Selenium API calls and allows users to fire events before and after Selenium API methods.

Extending SeleniumLibrary
As with any Robot Framework Python library, new libraries can be built on top of the SeleniumLibrary by inheriting the SeleniumLibrary, getting active library instance from Robot Framework or by other means which are available from Python or from Robot Framework. Building new libraries allows library creator freedom to choose which keywords new library offers and more flexibility how new libraries are created than what the plugin API offers.

Public API

The plugin API and extending SeleniumLibrary have same access to the SeleniumLibrary public API. All the methods, which are exposed as keywords, are available in the SeleniumLibrary public API.
Before extending the library, you have to know below public APIs.

Method Description
find_element Finds first element matching locator.
find_elements Find all elements matching locator.
get_keyword_tags Responsible for returning keywords tags for Robot Framework dynamic library API.
register_driver Add’s a Selenium driver to the library WebDriverCache.
run_keyword Responsible for executing keywords by Robot Framework dynamic library API.
failure_occurred Method that is executed when a SeleniumLibrary keyword fails.

Also there are the following public attributes available:

Attribute Description
driver Current active driver.
event_firing_webdriver Reference to a class implementing event firing selenium support.
timeout Default value for timeouts used with Wait … keywords.
implicit_wait Default value for implicit wait used when locating elements.
run_on_failure_keyword Default action for the run-on-failure functionality.
screenshot_root_directory Location where possible screenshots are created

Plugin API

Importing plugins is similar when importing Robot Framework libraries.

Copy to Clipboard

Achieving plugin

Copy to Clipboard

EventFiringWebDriver

The EventFiringWebDriver is an listener type of API offered by the Selenium. In practice EventFiringWebDriver offers way to intercept Selenium API call, made by SeleniumLibrary or by other library keywords and fire separate Selenium events.
Events can be fired before and after Selenium API call.

Copy to Clipboard

Conclusion

With the powerful extensions and plugins, Robot Framework can reduce script creation time, save costs and enable manual engineers to complete automatic script creation.
Find us to know more about Robot Framework and test automation best practices.