Create random date string and use in variable and use that variable in test objects

I’d like to create a string variable like the following where DDMMYYYYHHMM is the date format generated at runtime.

projectName = “Project DDMMYYYYHHMM”

I’d like to use the variable created to verify objects using their xpaths like below.

//textarea[contains(text(),'$projectName')]

Any help would be greatly appreciated!

I was able to create the string variable with the following code below:

Date today = new Date()

String todaysDate = today.format('MMddyy-hhmm')

String projectName = 'Regression Project ' + todaysDate

I created an object with the following xpath code (in the object repository) but it cannot be verified.

//textarea[contains(text(),'${projectName}')]

Any help is greatly appreciated! :slight_smile:

How to convert String to Date,

example :
String currentDate = 22-04-2019;
I would like to type cast to date format.
Expecting quick help.
Thanks.
shiva