Search code examples
if-statementsyntax-errorkeywordrobotframeworkreserved

'Else' is a reserved keyword Error in Robot Framework script


I am getting error

'Else' is a reserved keyword

the code snipet goes as follows , can anyone guide me the resolution ?

   :FOR ${key} IN @{keys}
   \           ${item}= Get From Dictionary ${services} ${key}
   \           Run Keyword If '${item}' == '1' Log Service: ${key} is Running
   \          Else If '${item}' == '2' Log
   \          ... Service: ${key} is not running

Solution

  • You are forgetting to use the continuation characters. All of the "else" and "elseif" words, and the other keywords and arguments, must all be arguments to the "run keyword if" keyword.

    :FOR ${key} IN @{keys}
    \    ${item}= Get From Dictionary ${services} ${key}
    \    Run Keyword If    '${item}' == '1' 
    \    ...    Log    Service: ${key} is Running
    \    ...    Else If    '${item}' == '2' Log
    \    ...    Log    Service: ${key} is not running