我们如何使用Set Variable if
关键字,其中关键字返回需要设置的变量RobotFramework
。
例如:${Var} = set variable if ${i}==10 Keyword
。
我们如何使用Set Variable if
关键字,其中关键字返回需要设置的变量RobotFramework
。
例如:${Var} = set variable if ${i}==10 Keyword
。
一种方法是使用“运行关键字 if”和“设置测试变量”,例如。
*** Test cases ***
foo
Run keyword if ${i} == 10 kw that sets test variables
should be equal ${var} HELLO
*** keywords ***
kw that sets test variables
set test variable ${var} HELLO
实际上,最简单的方法是使用Run Keyword If
而不是Set Variable If
如下所示:
Foo
${ret}= Run Keyword If ${i} == 10 Keyword Which Return Something
Should Be Equal ${ret} something
Keyword Which Return Something
${var}= Set Variable something
[Return] ${var}
我会这样做的方式是:
*** Test Cases ***
Test Case Title
${passed} = run keyword and return status
... Should be equal ${i} 10
${var} = set variable if ${passed} It is today
Another Test Example
${var} = set variable if ${i}==10 It is today
*** Keywords ***
It is today
${today} = Get Current Date UTC result_format=%-d-%-m-%Y exclude_millis=true
[Return] ${today}
只需将关键字中的值存储在临时变量中:
${temp} = | Keyword | Param1 | Param2 | .....
${Var} = | ${i} == 10 | ${temp}
如果 i 为 10,${Var} 将被设置为关键字的返回值。