Selenium WebDriver Java Framework Course Limited Time Offer for $20

Selenium WebDriver Java Framework Course Limited Time Offer for $20

 

Print

Dictionary Should Contain Key Robot Framework

Dictionary Should Contain Key keyword is used to verify if a given key is found in the dictionary. If not, the keyword will Fail. See the implementation below. 

 

*** Settings ***
Library           Collections

*** Test Cases ***
Dictionary Should Contain Key Test
    Comment    Fails if key is not found from dictionary
    ${MyDict}=    Create Dictionary
    Set To Dictionary    ${MyDict}    A1    Value1
    Set To Dictionary    ${MyDict}    A2    Value2
    Log Dictionary    ${MyDict}
    Dictionary Should Contain Key    ${MyDict}    A1
    Comment    You can use Dictionary Should Not Contain Key in similar ways

Run the script above. The test passed. 

Starting test: RobotCollectionsExample.Collections Keyword Test Suite.Dictionary Should Contain Key Test
20150426 08:23:18.669 :  INFO : ${MyDict} = {}
20150426 08:23:18.669 :  INFO : 
Dictionary size is 2 and it contains following items:
A1: Value1
A2: Value2
Ending test:   RobotCollectionsExample.Collections Keyword Test Suite.Dictionary Should Contain Key Test