0

I want to construct Run Keyword if in such a way so that it can handle multiple negative conditions

I took help in constructing Run Keyword if for multiple conditions in the following way:

Run keyword if   ${Param1} in ['${value1}', '${value2}]    Log to Console   Some Message

Help taken from: How to write multiple conditions of if-statement in Robot Framework

Now I want to construct the same function so that the keyword runs if few conditions are not met.

The obvious code can be as follows: Run keyword if ${Param1}!=${value1} and ${Param1}!=${value2} Log to Console Some Message

The code that I am expecting:

Run keyword if   ${Param1} !in  ['${value1}', '${value2}]    Log to Console   Some Message

What is the correct syntax for !in?

Samadhi Ghosh
  • 31
  • 2
  • 3
  • 9

1 Answers1

1

The syntax is not in, and you also need to make sure there is only a single space after in, and make sure you properly quote your values:

Run keyword if   '${Param1}' not in ['${value1}', '${value2}']    
...  Log to Console   Some Message

if any of the variables could themselves have quotes, you can use the variables directly in the expression by omitting the curly brackets, like so:

Run keyword if   $Param1 not in [$value1, $value2]    
...  Log to Console   Some Message
Bryan Oakley
  • 370,779
  • 53
  • 539
  • 685
  • Thanks Bryan. The extra piece of information(variable can be used directly if they have quotes) was not known to me. Thanks for the knowledge :) Have a great day! – Samadhi Ghosh Jul 24 '19 at 14:25