Search code examples
robotframework

Cannot set a RobotFramework dictionary


I wrote this simple minimal script to show how I suffer:

main.robot

Library  Collections
Library          BuiltIn
Library          String


*** Variables ***
&{info}    Create Dictionary


*** Test Cases ***
Case_00_Initialization
    Log     Hello 1     WARN
    Set To Dictionary    ${info}   field1=A sample string
    Log     Hello 2     WARN

Running this code by

python -m robot -L TRACE --NoStatusRC main.robot

Gives me errors:

[ ERROR ] Error in file 'C:\test\main.robot' on line 7: Setting variable '&{info}' failed: Invalid dictionary variable item 'Create Dictionary'. Items must use 'name=value' syntax or be dictionary variables themselves.
==============================================================================
Main
==============================================================================
[ WARN ] Hello 1
Case_00_Initialization                                                | FAIL |
No keyword with name 'Set To Dictionary' found.
------------------------------------------------------------------------------
Main                                                                  | FAIL |
1 critical test, 0 passed, 1 failed
1 test total, 0 passed, 1 failed
==============================================================================
Output:  C:\test\output.xml
Log:     C:\test\log.html
Report:  C:\test\report.html

The application is supposed to set a variable info in the initialization and it will be used in the next test cases. I do not want to use Set Global Variable however.

Please note that this is a minimal working example, do not suggest to set field1 at Variables section. It is not possible. Even that one will not solve the problem of No keyword with name 'Set To Dictionary' found.


Solution

  • I eventually found what is wrong. I was missing the line for *** Settings *** I couldn't imagine that it does matter. Shame that RF does not have many full examples online.

    This is the working code:

    *** Settings ***
    Library  Collections
    
    
    *** Variables ***
    &{info}
    
    
    *** Test Cases ***
    Case_00_Initialization
        Log     Hello 1     WARN
        Set To Dictionary    ${info}   field1=A sample string
        Log     Hello 2     WARN