如何使用全局变量robotframework?
How to using global variable robotframework?
我想通过循环增加我的变量。如何以及在哪里声明它(例如:{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}
看看这个
*** Settings ***
*** Variables ***
@{LIST} 5 6 7
${myvar}
*** Test Cases ***
Check
Start to Login ${LIST}
*** Keywords ***
Start to Login
[Arguments] ${LIST}
:FOR ${LINE} IN @{LIST}
\ ${myvar}= Evaluate ${myvar} + 1
\ Log to console ${myvar}
输出
Check
1
2
3
@pankaj-mishra 的答案的替代方法如下。这将删除 evaluate
并使用 Set Variable
和 simple arithmetics to increase the value. It is important to start with a numerical value. This is why the variable is created with [=14=] to ensure that the 0
is indeed a number 而不是字符串。
*** Test Cases ***
test counter
${counter} Set Variable [=10=]
:FOR ${item} IN RANGE 10
\ ${counter} Set Variable ${counter+1}
\ Log ${counter}
我想通过循环增加我的变量。如何以及在哪里声明它(例如:{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}
看看这个
*** Settings ***
*** Variables ***
@{LIST} 5 6 7
${myvar}
*** Test Cases ***
Check
Start to Login ${LIST}
*** Keywords ***
Start to Login
[Arguments] ${LIST}
:FOR ${LINE} IN @{LIST}
\ ${myvar}= Evaluate ${myvar} + 1
\ Log to console ${myvar}
输出
Check
1
2
3
@pankaj-mishra 的答案的替代方法如下。这将删除 evaluate
并使用 Set Variable
和 simple arithmetics to increase the value. It is important to start with a numerical value. This is why the variable is created with [=14=] to ensure that the 0
is indeed a number 而不是字符串。
*** Test Cases ***
test counter
${counter} Set Variable [=10=]
:FOR ${item} IN RANGE 10
\ ${counter} Set Variable ${counter+1}
\ Log ${counter}