Selenium WebDriver Java Framework Course Limited Time Offer for $20

Selenium WebDriver Java Framework Course Limited Time Offer for $20

 

Print

Dictionary Should Contain Sub Dictionary Robot Framework

Dictionary Should Contain Sub Dictionary keyword is used to check if all items in dict1 are from dict2. The keyword will fail if there are differences between the keys and values. See the implementation below. 

 

*** Settings ***
Library           Collections

*** Test Cases ***
Dictionary Should Contain Sub Dictionary Test
    Comment    Fails unless all items in dict2 are found from dict1
    ${dict2}=    Create Dictionary
    Set To Dictionary    ${dict2}    Foo1    Value1
    Set To Dictionary    ${dict2}    Foo2    Value2
    Log Dictionary    ${dict2}
    ${dict1}=    Create Dictionary
    Set To Dictionary    ${dict1}    Foo1    Value1
    Set To Dictionary    ${dict1}    Foo2    Value2
    Set To Dictionary    ${dict1}    Foo3    Value3
    Set To Dictionary    ${dict1}    Foo4    Value4
    Log Dictionary    ${dict1}
    Dictionary Should Contain Sub Dictionary    ${dict1}    ${dict2}

Run the script below. The test passed. 

Starting test: RobotCollectionsExample.Collections Keyword Test Suite.Dictionary Should Contain Sub Dictionary Test
20150426 08:33:25.678 :  INFO : ${dict2} = {}
20150426 08:33:25.678 :  INFO : 
Dictionary size is 2 and it contains following items:
Foo1: Value1
Foo2: Value2
20150426 08:33:25.678 :  INFO : ${dict1} = {}
20150426 08:33:25.678 :  INFO : 
Dictionary size is 4 and it contains following items:
Foo1: Value1
Foo2: Value2
Foo3: Value3
Foo4: Value4
Ending test:   RobotCollectionsExample.Collections Keyword Test Suite.Dictionary Should Contain Sub Dictionary Test