Skip to content

How to store data to a Json file in Files module from within a test run



In this example you will see how to store a Json string to a file in Files module.

For saving data to a file in Json format, first you need to build a dataset (data in the form of rows & columns stored in memory) and populate the dataset as this forms input for the file. Steps to follow (the same are shown in the test script snippet)

  • Create dataset (instruction #1)
  • Initialize by adding a Row (instruction #2)
  • Populate values to the Row (instructions #3 thru #8)
  • Save dataset to a file in the format of a Json (instruction #11)

# Command Target Value
Creating the dataset and specifying the data definition name of the data file
1 ddCreateDataSet dsBookDetails BookJson||ISBN_10,searchKeywordForProduct,productTitle,author,publisher,edition
Initializing dataset by adding a row
2 ddAddRows dsBookDetails 1
Setting values for the first row in the dataset
3 ddSetCellValueByName dsBookDetails(0,ISBN_10) 1951028023
4 ddSetCellValueByName dsBookDetails(0,searchKeywordForProduct) I AM A LEADER
5 ddSetCellValueByName dsBookDetails(0,productTitle) I AM A LEADER: A 90-Day Leadership Journal for Kids (Ages 8 - 12)
6 ddSetCellValueByName dsBookDetails(0,author) Peter J. Liang
7 ddSetCellValueByName dsBookDetails(0,publisher) Absolute Author Publishing House (July 19, 2019)
8 ddSetCellValueByName dsBookDetails(0,edition) kindle
Print the number of rows
9 ddGetRowCount dsBookDetails count
10 echo ${count}
Save dataset to a Json file
11 ddPersistDataSetToJsonFile dsBookDetails BookDetails.Json

Tips, Tricks, Gotchas & Best Practices: 

In this example, 

  • Dataset is created using Dynamic Data Definition (not defined in Data Definitions module) and then populating using ddSetCellValueByName. This is one of the many ways of creating and populating dataset in Worksoft SaaS platform. You may want to read more about datasets and populating datasets by referring to the article here.


Feedback and Knowledge Base