Selenium WebDriver Java Framework Course Limited Time Offer for $20

Selenium WebDriver Java Framework Course Limited Time Offer for $20

 

Print

Dictionary Should Contain Item Robot Framework

Dictionary Should Contain Item keyword is used to check if the dictionary contain an item of key/value pair. See the implementation below.

 

*** Settings ***
Library           Collections

*** Test Cases ***
Dictionary Should Contain Item Test
    Comment    An item of key/value must be found in a dictionary
    ${MyDict}=    Create Dictionary
    Set To Dictionary    ${MyDict}    Foo1    Value1
    Set To Dictionary    ${MyDict}    Foo2    Value2
    Log Dictionary    ${MyDict}
    Dictionary Should Contain Item    ${MyDict}    Foo1    Value1

Run the script above. The test passed because ${MyDict} contains the item Foo1/Value1

Starting test: RobotCollectionsExample.Collections Keyword Test Suite.Dictionary Should Contain Item Test
20150426 08:17:22.786 :  INFO : ${MyDict} = {}
20150426 08:17:22.786 :  INFO : 
Dictionary size is 2 and it contains following items:
Foo1: Value1
Foo2: Value2
Ending test:   RobotCollectionsExample.Collections Keyword Test Suite.Dictionary Should Contain Item Test