How to execute a javascript and store the result in a variable for use in the Katalon script?

I’ve been using selenium ide for many years and now it will no longer be supported/updated to work with firefox 55+. I’m not a developer, more of a front end manual tester, but I have been able to use IDE to do most of my day to day testing.

Now I am trying to figure out how to use Katalon as a replacement.

I have many sites where I have to make records unique and currently I do so by using selenium to run a js to give me the current time in a format that I want, store it in a variable, then use that variable throughout the record as needed.

This would be a js I’d run:

javascript{var fd=new Date(); var date_month=fd.getMonth()+1; if (date_month < 10){ date_month = “0” + date_month; }; date_day = fd.getDate().toString(); var n=date_day.length; if (n < 2){ date_day = “0” + date_day; }; date_hour = fd.getHours().toString(); var n=date_hour.length; if (n < 2){ date_hour = “0” + date_hour; }; date_min = fd.getMinutes().toString(); var n=date_min.length; if (n < 2){ date_min = “0” + date_min; }; date_sec = fd.getSeconds().toString(); var n=date_sec.length; if (n < 2){ date_sec = “0” + date_sec; }; date_year=fd.getFullYear().toString(); date_year+“”+date_month+“”+date_day+“”+date_hour+date_min+“”+date_sec; }

I would use “store|<theaboveJS>|currentTime” as my command. How do I do something similar in KS? Is it possible?

Is there a part of the site where there are examples of what can be done with KS? I’ll look more on youtube to see what walkthroughs I can find as well.

Thanks for that. However, I was looking more to find out how to manipulate data via js so I could parse stored variables and what not as needed. Getting a js replacement for time helps with uniqueness. Not sure what “groovy” is, so will look into that as well.

Thanks for the help!

If all you need is just the current date & time, you can do that with groovy using the below code.

def now = new Date()
def currentTime = now.format("MM/dd/yyyy -HH:mm:ss.SSS", TimeZone.getTimeZone('UTC'))

You can format the output to any format you want, I have separated the day, month & year with / and time with : … Hope this helps!!