2016-01-28 81 views
3

我只想減少最後一行中的變量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.

我在做什麼錯在這裏?

回答

7

試着把它放入var名稱中。即

${N_groups-1} 
+2

這是不直觀 – kame

+1

是的,我記得幾個月前碰到同樣的絆腳石,來自開發它只是感覺不對,就像我使用完全不同的變量而不是改變變量的值。但我猜的語法是語法 – shicky

+1

@ kame:它不直觀,但它是一個記錄的功能:http://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#extended-variable-syntax –

0

如果變量已經是一個數,你可以使用:

${N_groups}= ${N_groups-1}

要做到這一點,你需要將其強制爲數字(否則你會得到一個錯誤說failed: TypeError: coercing to Unicode: need string or buffer, int found ),例如

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

或者,你可以使用Evaluate這樣,其工作是否$ {N_groups}已強制轉換爲數字或不:

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