Search code examples
pythonrobotframework

How to specify empty list, empty dict and Boolean as a default value for a robot framework keyword.?


I want to specify default values like in python

def my_function(arg1="my_string", arg2=[], arg3={}, arg4=True):
    pass

The following is a sample keyword definition equivalent to above. I want to specify default values.

*** Keywords ***
My Function

    [Arguments]     ${ARG1}=my_default_string    ${ARG2}= <How to specify empty list)    ${ARG3}= <How to specify empty dict)    ${ARG4}= <How to specify boolean true)

    some statements
    some more statements

Solution

  • While the given answer is useful, it does not really answer the question, since the question was asking how to do so in Robot Framework, and not in Python. Here's how you'd do it in Robot Framework:

    My Function
        [Arguments]    ${arg1}=my_string    ${arg2}=${None}    ${arg3}=${None}    ${arg4}=${True}
    

    Notice I used lower case names for your args as well. If you want to follow best practices, you should use upper case variable names for global variables, not for local or argument variable names.