Robot Framework – quit writing ugly robot code, just write proper python

Robotframework is not a programming language. As soon as the test logic is not trivial, writing robot code becomes a nightmare. Robot does not have the  proper structures of a very basic programming language. Just try to write an if-else statement or a while loop and you’ll see.
But Robotframework does something very good: it presents the test in a human friendly form, very usefull for non programmer.

A robot test could be presented either as an HTML table, or under the form of a txt file (.txt or .robot) with tests written in robot language. When the test is presented as an HTML table, each row is nothing but the call to a keyword, usually written in robot language, in some text file.

The approach I propose is the following: Always use the HTML format for the test presentation. Business people can understand the tables, test and documentation are described in a single document, blah blah blah.  Then, for each single keyword, you implement it directly in python. No need to implement the keywords in the textual robot language which can only make your life difficult. In the html file, import your python files as Libraries:


There are some things that will make your life easy when implementing keywords in python.

  • In the python implementation of a keyword, you can access all variables available in your robot test

from robot.libraries.BuiltIn import BuiltIn
def perform_login():
    user_name= BuiltIn().get_variable_value("${USERNAME}")
    pwd= BuiltIn().get_variable_value("${PASSWORD}")
  • You can call any of your java keywords (basically any java API available in the classpath)
from com.mycompany.myproject.testtools import LoginRobotKeywords

def perform_login(user, pwd):
    LoginRobotKeywords().login(user, pwd)
  • You can call any of your robot keywords
    You might already have low level keywords written in robot and don’t want to re-implement them in python. Don’t worry, you can just call them from your python code
<pre>from com.mycompany.myproject.testtools import LoginRobotKeywords
from robot.libraries.BuiltIn import BuiltIn

def perform_login(user, pwd):
    LoginRobotKeywords().login(user, pwd)
    BuiltIn().run_keyword("check user connected", user)
    BuiltIn().run_keyword_and_expect_error("*", "check user can format primary disk ", user)

That’s it. I hope I will never again have to use robotframework language as if it was a programming language.

This entry was posted in robot framework, testing. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s