Search code examples
robotframeworkselenium2library

How to using global variable robotframework?


I want to increase my variable through loop. How and where can I declare it (such as: {myvar} = 0)

*** Test Cases ***

Start to Login
    Log     ${myvar}

*** Keywords ***

Start to Login
    [Arguments]    ${LIST}
    : FOR    ${LINE}    IN    @{LIST}
    \    ${myvar}=    Evaluate    ${myvar} + 1
    \    Log    ${myvar}

Solution

  • An alternative to the answer from @pankaj-mishra is the following. This removes the evaluate and uses Set Variable with simple arithmetics to increase the value. It is important to start with a numerical value. This is why the variable is created with ${0} to ensure that the 0 is indeed a number and not a string.

    *** Test Cases ***
    test counter
        ${counter}    Set Variable     ${0}
    
        :FOR    ${item}    IN RANGE    10
        \    ${counter}    Set Variable    ${counter+1}
        \    Log    ${counter}