Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Decrement or increment a variable in the robot framework

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?

like image 447
kame Avatar asked Jan 28 '16 08:01

kame


People also ask

What are the 3 different types of variables in the robot framework?

There are three types of variables supported in robot framework − scalar, list and dictionary.

What is argument in Robot Framework?

Robot Framework supports free named arguments, often also called free keyword arguments or kwargs, similarly as Python supports **kwargs. What this means is that a keyword can receive all arguments that use the named argument syntax (name=value) and do not match any arguments specified in the signature of the keyword.

What is suite setup and suite teardown in Robot Framework?

This is a set of keywords or instruction to be executed after the start of test suite or test case execution. We will work on a project setup, where will use both setup and teardown. The opening and closing of browser are the common steps in test cases.


2 Answers

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

${N_groups-1}
like image 180
shicky Avatar answered Sep 21 '22 23:09

shicky


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

like image 36
qbert220 Avatar answered Sep 21 '22 23:09

qbert220