I have a scenario where I need to do different set of actions depending on dictionary key and value
Dictionary can be any of the below
&{DICT_VAL_APPLINPUT}= Create Dictionary status=Single employmentType=PAYG income=
&{DICT_VAL_APPLINPUT}= Create Dictionary name= status=Single employmentType=PAYG income=
&{DICT_VAL_APPLINPUT}= Create Dictionary name=ABC status=Single employmentType=PAYG income=
*** Test Cases ***
Test
&{DICT_VAL_APPLINPUT}= Create Dictionary status=Divorced employmentType=PAYG income=
Check Dictionary Key or Value Exist ${DICT_VAL_APPLINPUT} name
*** Keywords ***
Check Dictionary Key or Value Exist
[Documentation] checks whether dictionary key and value exists
[Arguments] ${sp_dict_keyvalue} ${key}
${sp_retkeystatus}= run keyword and return status dictionary should contain key ${sp_dict_keyvalue} ${key}
${sp_retstatus}= run keyword if '${sp_retkeystatus}'=='False' return from keyword False
... ELSE IF '${sp_dict_keyvalue}[${key}]'=='${EMPTY}' return from keyword False
... ELSE return from keyword True
[Return] ${sp_retstatus}
I am getting below error when I send dictionary with no key even after validating key.
Dictionary '${sp_dict_keyvalue}' has no key 'name'.
It is failing at step
... ELSE IF '${sp_dict_keyvalue}[${key}]'=='${EMPTY}' return from keyword False
*** Settings ***
Library Collections
*** Test Cases ***
Test
&{DICT_VAL_APPLINPUT}= Create Dictionary status=Divorced employmentType=PAYG income=
# Set To Dictionary ${DICT_VAL_APPLINPUT} name=
Log ${DICT_VAL_APPLINPUT}
Check Dictionary Key or Value Exist ${DICT_VAL_APPLINPUT} name
*** Keywords ***
Check Dictionary Key or Value Exist
[Documentation] checks whether dictionary key and value exists
[Arguments] ${sp_dict_keyvalue} ${key}
${sp_retkeystatus}= run keyword and return status dictionary should contain key ${sp_dict_keyvalue} ${key}
${sp_retstatus}= run keyword if '${sp_retkeystatus}'=='False' return from keyword False
... ELSE IF '${sp_dict_keyvalue}[${key}]'=='${EMPTY}' return from keyword Empty
... ELSE return from keyword True
[Return] ${sp_retstatus}