2
votes

I tried to check the given dictionary is empty or not in robot framework but it is giving an error saying syntax error. Here is the following example of how I compared it:

Run Keyword If '${source_list_data}'=='[]' FAIL and the error which i got is:

Evaluating expression ''[{'data':'value'}]'=='[]'' failed: SyntaxError: invalid syntax (, line 1)

2
1. First calculate length of your list by Get Length keyword 2. Run simple if condition to take action written below ->> code written in RIDE - vijayw

2 Answers

5
votes

Your syntax works for me. Strange it does not work for you.

Here is another way to achieve it using Get Length:

*** Settings ***
Library  Collections

*** Test Cases ***
dict_empty
    ${source_list_data} =  create dictionary
    ${length} =  Get Length  ${source_list_data}
    Run Keyword If  ${length} == 0  log to console  Empty Dict
0
votes

To check if dictionary is empty in robot framework, automatic dictionary variable "&{EMPTY}" can be used:

Run Keyword if  ${dict} == &{EMPTY}  'Some Action Keyword'