recent posts

How To Use Optional Keyword Arguments in Robot Framework

The Robot Framework documentation explains how to use optional keywords quite clearly, but I wanted to write up a quick example to display the use of default and optional values.

.robot file
*** Test Cases ***
Example Vegetable List
     Fill Grocery List      
     Fill Grocery List      type=Tomato

*** Keywords ***
Fill Grocery List
     [Arguments]      ${type}=Potato     ${category}=Vegetable
     Input Text         id=type                ${type}
     Input Text         id=category          ${category}
  • Values for Grocery List 1 will be Potato, Vegetable
  • Values for Grocery List 2 will be Tomato, Vegetable 
In Grocery List 2, we only changed the type from Potato to Tomato. Note how we don't call category at all since we are not changing it. If we wanted to make a change to category, we can add category=Fruit when we make the Fill Grocery List call.


"Free keyword arguments support variables similarly as named arguments. In practice that means that variables can be used both in names and values, but the escape sign must always be visible literally. For example, both foo=${bar} and ${foo}=${bar} are valid, as long as the variables that are used exist. An extra limitation is that free keyword argument names must always be strings. Support for variables in names is a new feature in Robot Framework 2.8.6, prior to that possible variables were left un-resolved."

Reference Material:
How To Use Optional Keyword Arguments in Robot Framework How To Use Optional Keyword Arguments in Robot Framework Reviewed by JJ The Engineer on 12:31 AM Rating: 5

1 comment:

Powered by Blogger.