Skip to content Skip to sidebar Skip to footer

How To Define A Variable Being A Dictionary With List Values In Robot Framework

In one of my testcases I need to define a dictionary, where the keys are string and the values are arrays of strings. How can I do so in Robot Framework? My first try using a const

Solution 1:

You have a couple more options beside using the Evaluate keyword.

  1. You could use a Python variable file:

    DICTIONARY = { "A" : ["StringA1",  "StringA2"], "B": ["StringB1","StringB2"]}
    

    Suite:

    *** Settings ***
    Variables    VariableFile.py
    
    *** Test Cases ***
    Test
        Log    ${DICTIONARY}
    
  2. You can define your lists separately, and then pass them as scalar variables when defining the dictionary.

    *** Variables ***
    @{list1}    StringA1    StringA2
    @{list2}    StringB1    StringB1
    &{Dictionary}    A=${list1}    B=${list2}
    
    *** Test Cases ***
    Test
        Log    ${Dictionary}
    
  3. You can create a user keyword using the Create List and Create Dictionary keywords. You can achieve the same in Python by writing a small library.

    *** Test Cases ***
    Test
        ${Dictionary}=    Create Dict With List Elements
        Log    ${Dictionary}
    
    
    *** Keyword ***
    Create Dict With List Elements
        ${list1}=    Create List    StringA1    StringA2
        ${list2}=    Create List    StringB1    StringB1
        ${Dictionary}=    Create Dictionary    A=${list1}    B=${list2}
        [return]    ${Dictionary}

Post a Comment for "How To Define A Variable Being A Dictionary With List Values In Robot Framework"