Decrement or increment a variable in the robot framework

25,752

Solution 1

Try putting it inside the var name. i.e.

${N_groups-1}

Solution 2

If the variable is already a number, you can use:

${N_groups}= ${N_groups-1}

To do this you need to coerce it to a number (otherwise you'll get an error saying failed: TypeError: coercing to Unicode: need string or buffer, int found), e.g.

*** Variables *** ${N_groups}= ${0} # ${} notation coerces value to a number

Alternatively, you can use Evaluate like this, which works whether ${N_groups} has been coerced to a number or not:

${N_groups}= Evaluate ${N_groups} - 1

Share:
25,752
kame
Author by

kame

I live in the area between Basel and Zürich. Nice to meet you. :)

Updated on June 12, 2021

Comments

  • kame
    kame almost 3 years

    I just want to decrement the variable N_groups in the last line. This is my robot file:

    Preconditions - Delete Groups But Not First
        ${N_groups}    Setup Groups Count Groups
        Log to console    N_groups: ${N_groups}
        : FOR    ${INDEX}    IN RANGE    1    20
        \    Run Keyword If    '${N_groups}' == '1'    Exit For Loop
        \    Setup Groups Delete Group    ${group}
        \    ${N_groups}=    ${N_groups}-1
    

    I get the error:

    No keyword with name '${N_groups}-1' found.

    What I am doing wrong here?