3

I want to use If-Condition with multiple actions in Robot Framework

${x}    Set Variable    5   
Run Keyword If  ${x} == 5       
... ${Test1} =  Set Variable    MyName
... ${Test2} =  Set Variable    MyLastName
... Else        
... ${Test1} =  Set Variable    MyAddress
... ${Test2} =  Set Variable    MyTelephone

But it is not working Error show FAIL : Variable '${Test1}' not found. Could you please tell me about using IF-Condition with multiple actions

Bell Aimsaard
  • 483
  • 3
  • 5
  • 16

5 Answers5

3

You can use "Run Keywords" keyword to perform multiple actions in IF condition

Kindly go through below link:

IF ELSE in robot framework with variables assignment

Community
  • 1
  • 1
Rakesh
  • 1,525
  • 1
  • 15
  • 25
  • 1
    oh, my. RF guys really think this kind of syntax better than raw python syntax? Why not just use python to write test cases? IMO, that's much easier. – Jcyrss Jun 27 '18 at 02:28
  • @Jcyrss I guess that conditional statements were added as an afterthought, and had to shoehorned into the existing syntax. Note that "If" has to written with a lowercase "f", while "ELSE" needs to be all caps. Yep, fits into the syntax scheme, but is...uh..."unconventional". So far, I am very happy that the WHILE statement, which was promised quite a few years ago, has not yet crossed my way. – Klaws Nov 04 '21 at 16:34
1

You have to either cover both actions with one custom keyword and then call Run Keyword If or call the keyword Set Variable If twice or write such logic into python (jython...) library.

Jan Kovařík
  • 1,542
  • 1
  • 11
  • 18
1

Please notice "And" while using "Run Keywords"; also ensure tab used.

Run Keyword If  <condition1>  <action1>
    ...   ELSE IF  <condition1>
    ...   Run Keywords
    ...   <action1>
    ...   AND  <action2>
1
Set Test Variable    ${temp}    rxu
Run Keyword if    '${temp}'=='rxu'
...    Run Keywords
...    Log To Console    this is one
...    AND    Log To Console    This is two
...    ELSE    Run Keyword    Log To Console    another block
0

Refer following keyword :

Run Keyword If  ${x} == 5     Set Variable    MyName
Run Keyword If  ${x} == 1     Set Variable    LastName

Or

Run Keyword If  ${x} == 5     Set Variable    MyName
... ELSE IF  ${x} == 2        Set Variable    MyName
... ELSE IF  ${x} == 3        Set Variable    Middle Name
Akash W
  • 371
  • 1
  • 10