Search code examples
robotframework

Robotframework testing dictionary values


I have a dictionary (json) that looks like this

[{"foo":"fooval1a",type:"xfs"},{"foo":"fooval2a",type:"ext2"},{"foo":"fooval3a",type:"nfs"},{"foo":"fooval4a",type:"ntfs"}]

I would like to check in this list, when "foo" is value "fooval3a" it should be "nfs". I have like 20 of these sort of tests. Is there a way to do this easily with robotframework?


Solution

  • You miss quote on "type"

    ${listOfDict}    Evaluate    [{"foo":"fooval1a","type":"xfs"},{"foo":"fooval2a","type":"ext2"},{"foo":"fooval3a","type":"nfs"},{"foo":"fooval4a","type":"ntfs"}]
    FOR    ${dict}    IN    @{listOfDict}
        IF    "${dict}[foo]"=="fooval3a"
            Should Be Equal    ${dict}[type]    nfs
        END
    END