Niketa Chellani
Niketa Chellani

Reputation: 33

How to assign value to a variable depending on IF/ELSE condition in Robot?

I am trying to assign a variable the return value of the Keyword (Get Ipsec Pkt Stat) if a condition is true. The following is the syntax I am using, however my variable ${ipsec_stats} gets assigned None, even though the condition is being satisfied:

Run Keyword If    '${chassis_cluster}' == 'True'
...    ${ipsec_stat} =  Get Ipsec Pkt Stats   ${R0}     node=local
...    ELSE
...    ${ipsec_stat} =  Get Ipsec Pkt Stats   ${R0} 
[Return]    ${ipsec_stat}

Upvotes: 3

Views: 331

Answers (1)

Bryan Oakley
Bryan Oakley

Reputation: 385970

run keyword if requires keywords as arguments, not variable names followed by keywords.

The correct way to assign a variable with run keyword if is to set the variable to the result of that keyword:

${ipsec_stat}=  Run keyword if  '${chassis_cluster}' == 'True'
...  Get ipsec Pkt Stats  ${R0}  node=local
...  ELSE
...  Get ipsec Pkt Stats  ${R0}

Upvotes: 3

Related Questions