listvariablesglobal-variablesrobotframeworksuite

How to make a Global Variable or Suite Variable as List in Robot Framework?


I am Trying to set a List variable that is accessible to all testcases in the suite and the value in the list should not be overwritten but new values should be appended each time.

So that I can use the List variable at the end of the execution of all the testcases for a clean up operation.

For Example the List variable will be holding value of the record created in the DB and at the end I can use this list to delete all the records created. Note each record will be created by different testcases under the same Suite. Any help will be greatly appreciated.


Solution

  • Declare the variable in the *** Variables *** section and it will be accessible in all cases; if you don't give a value to it during this initialization, it will be an empty list:

    *** Variables *** 
    @{my list}
    

    Then just add any members you need in your cases:

    Append To List    ${my list}    value
    

    , and at the end - in the keyword set as Suite Teardown - you'll be able to iterate over it.