Test Automation tips and tricks

When you write automated tests using Robot Framework, most of your work involves using keywords. You write keywords. You use keywords other developers have written and reuse your own keywords. And of course, you read Robot Framework keyword documentation.

That’s one of the beautiful things about keyword-driven test development.

Latest and greatest version

But change happens. And we appreciate when developers add new features to a library we use and release a new version. Sometimes, though, it is not an option to upgrade your library version right away when a new one is published. For instance, when you are closing in on a release deadline.

In general, that is no problem. Except, when you start looking at the librarys keyword documentation, only to find out, that it is also updated for the latest release. You know, the one that you have not upgraded to.

Take the popular Selenium Library as an example. At the time of writing, the current documentation for the Selenium Library is in version 5.0.0a3.

robot framework seleniumlibrary version 5
Figure 1: SeleniumLibrary documentation V5.0.0a3 – Source: https://robotframework.org/SeleniumLibrary/SeleniumLibrary.html

By the way, this image shows a preview of the new look and feel of Robot Framework documentation. Some really nice improvements have been included, especially the keywords being listed to the left. Credit goes to Mikko Korpela for this update.

Now, I’m usually a bit conservative and hesitant to jump straight into alpha versions, unless I am feeling very adventurous.

So, I use the Selenium Library release 4.5.0. How do I get the keyword documentation matching my installed library?

Create it yourself with Libdoc

By far the easiest way to get the documentation for your installed version of the library is to generate the keyword documentation yourself. And Robot Framework gives you the tool to easily do this.

Looking in the source file for Selenium Librarys elements.py, you see that all keywords are well documented:

class ElementKeywords(LibraryComponent):

    @keyword(name='Get WebElement')
    def get_webelement(self, locator):
        """Returns the first WebElement matching the given ``locator``.

        See the `Locating elements` section for details about the locator
        return self.find_element(locator)

    @keyword(name='Get WebElements')
    def get_webelements(self, locator):
        """Returns a list of WebElement objects matching the ``locator``.

        See the `Locating elements` section for details about the locator

        Starting from SeleniumLibrary 3.0, the keyword returns an empty
        list if there are no matching elements. In previous releases, the
        keyword failed in this case.
        return self.find_elements(locator)

You can convert this documentation to the human readable format that know from all the Robot Framework documentation by using Libdoc. For my installed version of Selenium Library I can run:

python -m robot.libdoc SeleniumLibrary SeleniumLibrary-4.5.0.html

This outputs the documentation I was looking for:

robot framework seleniumlibrary version 4
Figure 2: Selenium Library documentation V4.5.0

You can find the full documentation of how to use Libdoc in the Robot Framework User Guide, the latest version of course 😉

That’s it!

Share this post with your friends and followers: