Reputation: 81
How can we use Set Variable if
with a keyword, where Keyword is returning a variable that needs to be Set in RobotFramework
.
Eg: ${Var} = set variable if ${i}==10 Keyword
.
Upvotes: 8
Views: 41608
Reputation: 187
The way I would do it is:
*** 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}
Read further in the documentation here and here.
Upvotes: 2
Reputation: 361
Actually, the easiest way to do it is by using Run Keyword If
instead of Set Variable If
like below:
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}
Upvotes: 4
Reputation: 876
One way to do this would be the usage of "Run keyword if" with "set test variable" eg.
*** 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
Upvotes: 3
Reputation: 888
Just store the value from Keyword in a temp variable:
${temp} = | Keyword | Param1 | Param2 | .....
${Var} = | ${i} == 10 | ${temp}
If i is 10, ${Var} will be set to the return of Keyword.
Upvotes: 0