How to read data from an Json file (stored in Files module) from within my test run
In this example you will see how you can read data from a Json and use the data within your run. For this example, following Json data will be used as reference and the same is expected in the file available in the "Files" module
[ { "ISBN_10": "1951028023", "searchKeywordForProduct": "I AM A LEADER", "productTitle": "I AM A LEADER: A 90-Day Leadership Journal for Kids (Ages 8 - 12)", "author": "Peter J. Liang", "publisher": "Absolute Author Publishing House (July 19, 2019)", "edition": "Kindle" }, { "ISBN_10": "0689711999", "searchKeywordForProduct": "alexander books", "productTitle": "Alexander, Who Used to Be Rich Last Sunday", "author": "Judith Viorst", "publisher": "SILVER BURDETT (August 30, 1987)", "edition": "PaperBack" } ]
In the test run following details from the Json are required and need to be parsed.
- ISBN_10
- searchKeywordForProduct
- author
- publisher
- edition
Worksoft SaaS supports reading data from a Json file to a dataset. Hence a dataset would be initialised with data definition that has same attributes. Once the data is loaded to dataset using command "ddCreateDataSetFromJsonFile" regular array commands can be used for getting values from the dataset.
# | Command | Target | Value |
---|---|---|---|
Creating the dataset and specifying the data definition name of the data file | |||
1 | ddCreateDataSet | dsBookDetails | BookJson(W) |
Reading the data from the Json file into the dataset | |||
2 | ddCreateDataSetFromJsonFile | BookDetails.json | dsBookDetails |
Print number of rows persisted to dataset | |||
3 | ddGetRowCount | dsBookDetails | count |
4 | echo | ${count} | |
Tips, Tricks, Gotchas & Best Practices: