递减或递增机器人框架中的变量
Decrement or increment a variable in the robot framework
我只想减少最后一行中的变量 N_groups。
这是我的机器人文件:
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
我收到错误:
No keyword with name '${N_groups}-1' found.
我这里做错了什么?
试着把它放在 var 名称中。即
${N_groups-1}
如果变量已经是数字,可以使用:
${N_groups}= ${N_groups-1}
要做到这一点,您需要将其强制转换为一个数字(否则您会收到一条错误提示 failed: TypeError: coercing to Unicode: need string or buffer, int found
),例如
*** Variables ***
${N_groups}= [=12=] # ${} notation coerces value to a number
或者,您可以像这样使用 Evaluate
,无论 ${N_groups} 是否已被强制转换为一个数字,它都有效:
${N_groups}= Evaluate ${N_groups} - 1
试试这个:
${decrement_counter}= set variable 1
-- 循环内部
${N_groups}= Evaluate ${N_groups} - ${decrement_counter}
注意-减号前后只有一个space。
我只想减少最后一行中的变量 N_groups。 这是我的机器人文件:
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
我收到错误:
No keyword with name '${N_groups}-1' found.
我这里做错了什么?
试着把它放在 var 名称中。即
${N_groups-1}
如果变量已经是数字,可以使用:
${N_groups}= ${N_groups-1}
要做到这一点,您需要将其强制转换为一个数字(否则您会收到一条错误提示 failed: TypeError: coercing to Unicode: need string or buffer, int found
),例如
*** Variables ***
${N_groups}= [=12=] # ${} notation coerces value to a number
或者,您可以像这样使用 Evaluate
,无论 ${N_groups} 是否已被强制转换为一个数字,它都有效:
${N_groups}= Evaluate ${N_groups} - 1
试试这个:
${decrement_counter}= set variable 1
-- 循环内部
${N_groups}= Evaluate ${N_groups} - ${decrement_counter}
注意-减号前后只有一个space。