Skip to content

yoochar/readme-robotframework-dictallpaths

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 

Repository files navigation

DictAllPaths Library

robot framework - To get all paths of dictionary

Installation

Use the package manager pip to install robotframework-dictkeyallpaths.

pip install robotframework-dictkeyallpaths

Usage

# - Example:
#json_string as below:
{
	  	"SuperMarket": {
		    "Fruit": [
		      {
		        "Name": "Apple",
		        "Manufactured":"USA",
		        "price": 7.99
		      },
		      {
		        "Name": "Banana",
		        "Manufactured":"Japan",
		        "price": 3.99
		      }
		    ],
		    "Drink": {
				"SoftDrink":{
					"Cola": [
				      	{
				      		"Color":"Red",
				      		"Price":15.00
				      	},
				      	{
				      		"Color":"Green",
				      		"Price":17.99
				      	}
				      ],      
				      "Coffee": {
				      	"Hot":[
					      	{
					      		"Type":"Espresso",
					      		"Price":15.90
					      	},
					      	{
					      		"Type":"Cappuccino",
					      		"Price":10.90
					      	}
					    ],
					    "Ice":[
					      	{
					      		"Type":"Espresso",
					      		"Price":20.90
					      	},
					      	{
					      		"Type":"Cappuccino",
					      		"Price":15.90
					      	}
					    ]
				    }
				}     
		    }
	  	}
	}


# - How to use keyword in robotframework
# keyword >> 'Get Dict Paths'
# Returns all key paths of the given dictionary as a list.
*** Settings ***
Library    DictAllPaths

*** Test Cases ***
Test case get all paths of dictionary
    ${dictData}=    Evaluate    json.loads("""${json_string}""")    json
    @{allDictKeys}=    Get Dict Paths    ${dictData}
    :FOR    ${item}    IN    @{allDictKeys}
        Log To Console    key:${item} >> value:${dictData${item}}
    END


# - Console display
key:['SuperMarket']['Fruit'][0]['Name'] >> value:Apple
key:['SuperMarket']['Fruit'][0]['Manufactured'] >> value:USA
key:['SuperMarket']['Fruit'][0]['price'] >> value:7.99
key:['SuperMarket']['Fruit'][1]['Name'] >> value:Banana
key:['SuperMarket']['Fruit'][1]['Manufactured'] >> value:Japan
key:['SuperMarket']['Fruit'][1]['price'] >> value:3.99
key:['SuperMarket']['Drink']['SoftDrink']['Cola'][0]['Color'] >> value:Red
key:['SuperMarket']['Drink']['SoftDrink']['Cola'][0]['Price'] >> value:15.00
key:['SuperMarket']['Drink']['SoftDrink']['Cola'][1]['Color'] >> value:Green
key:['SuperMarket']['Drink']['SoftDrink']['Cola'][1]['Price'] >> value:17.99
key:['SuperMarket']['Drink']['SoftDrink']['Coffee']['Hot'][0]['Type'] >> value:Espresso
key:['SuperMarket']['Drink']['SoftDrink']['Coffee']['Hot'][0]['Price'] >> value:20.90
key:['SuperMarket']['Drink']['SoftDrink']['Coffee']['Hot'][1]['Type'] >> value:Cappuccino
key:['SuperMarket']['Drink']['SoftDrink']['Coffee']['Hot'][1]['Price'] >> value:10.90
key:['SuperMarket']['Drink']['SoftDrink']['Coffee']['Ice'][0]['Type'] >> value:Espresso
key:['SuperMarket']['Drink']['SoftDrink']['Coffee']['Ice'][0]['Price'] >> value:20.90
key:['SuperMarket']['Drink']['SoftDrink']['Coffee']['Ice'][1]['Type'] >> value:Cappuccino
key:['SuperMarket']['Drink']['SoftDrink']['Coffee']['Ice'][1]['Price'] >> value:15.90

Contributing

I will continue to develop to make it more complete.

Best Regards,
Yoochar

License

MIT

About

Read me of robotframework-dictallpaths

Resources

Stars

Watchers

Forks

Packages

No packages published