How to use stored variables

It’s great idea, for my test I’m using localStorage instead. The only difference between localStorage and sessionStorage is that data in sessionStorage will be deleted after session is closed i.e. closing the browser.

Dennis_Hohn You can add this solution to http://forum.katalon.com/c/katalon-recorder/tips-and-tricks

And little tip from me: if you have a lot of data to store you can use object in JavaScript. It works like this:

  1. Create object with your data like this:

var person = {name:“John”, lastName:“Smith”, age:28};

Whit Katalon variables it will be like this:

var person = {name:“${personName}”, lastName:“${personLastName}”, age:${personAge}};

  1. Then when you want to save it, use:

var newvar = JSON.stringify(person); // It convert object to string
sessionStorage.setItem(“myData”, newvar); // It saves string newvar in sessionStorage using myData as key

Now when you Inspect Element on page and go to “Application” tab on the left, under “Storage” open “Session Storage” and there will be your data displayed in elegant way.

  1. When you want to take the data back to Katalon use:

var localData = sessionStorage.getItem(“myData”); //It takes data from sessionStorage to localData var
var parsedData = JSON.parse(localData); // It change data from string to object

and to get one of the fields use:

var personName = parsedData.name;

To return this data use trick from: Katalon Automation Recorder - Tips and tricks point 6 because you need to return variables one by one.

1 Like