Ankur M
Ankur M

Reputation: 31

Robot Framework: Run Keyword If

I have a scenario where i need to set a variable value based on the input.

If input is 'A', i need to set ${var} = valA

If input is 'B', i need to set ${var} = valB

So i have following code

${columnObject}=    Run Keyword If  '${sortBy}'=='A'    Set Variable    valA
${columnObject}=    Run Keyword If  '${sortBy}'=='B'    Set Variable    valB

I am getting ${columnObject} as None if ${sortBy} has value 'A' as its also executing second statement and setting ${columnObject}

Upvotes: 1

Views: 1100

Answers (1)

ILostMySpoon
ILostMySpoon

Reputation: 2409

You can use the keyword Set Variable If

${columnObject}=    Set Variable If    '${sortBy}'=='A'    valA
...     '${sortBy}'=='B'    valB

${sortBy} will be assigned to None if neither of those conditions are met.

Upvotes: 3

Related Questions