Search code examples
robotframework

Unale to create list with element value containing '-' in robot framework


Unable to create list and iterate in for loop with element value containing '-' in robot framework

Example:

  @{w_message}=    Create List    ${"t-Expo"}    ${"n-yiko"}    ${"sf-git"}
    @{w_value}=    Create List    ${"30"}    ${"k1"}    ${"B-2"}     

    FOR    ${param}    IN    @{w_message}    
        FOR    ${number}    IN    @{w_value}
            Log ${param}               
        END
    END

Output:

Resolving variable '${"t-Expo"}' failed: Variable '${"t}' not found.

Solution

  • Because robotframework is looking for variable with the specific name. If you want to create a list loose the variable decorator and make sure to have double spaces in your code.

    This example should work:

    *** Test Cases ***   
    Example
        @{w_message}=    Create List     "t-Expo"    "n-yiko"     "sf-git" 
        @{w_value}=     Create List     "30"    "k1"    "B-2"
        FOR    ${param}    IN    @{w_message}
        Log    ${param} 
        END
        FOR    ${number}    IN    @{w_value}
        Log    ${number}
        END