Search code examples
pythonrobotframework

Robot Framework: How to know that variable is list, dictionary or regular


I need to process several types of data from one Keyword - which will call another necessary Keyword according to the defined data type.

Using Evaluate type() is good for Lists and Dictionaries but fails when we have just a string without quotes. If I add quotes - the data will be defined as string all times - even if it is in a List or Dictionary.

For example

${list}=    Create List    1    two
${type_list}=    Evaluate    type(${list})
# returns <type 'list'>

${dict}=    Create Dictionary  first=1  second=two
${type_dict}=  Evaluate  type(${dict})
# returns <type 'dict'>

${string}=  Set Variable  withoutQuotes
${type_string}=  Evaluate  type(${string})
# FAILS with:
Evaluating expression 'type(withoutQuotes)' failed: NameError: name 'withoutQuotes' is not defined

Could you please recommend some way to define a type of a variable which won't fail?


Solution

  • Run Keyword And Return Status has helped me!

    ${passed}=    Run Keyword And Return Status   Evaluate    type(${value})
    ${type}=      Run Keyword If     ${passed}    Evaluate    type(${value})