1
votes

I have a User ID text field in a form. I need to enter some text along with current timestamp value [ex: "abc_23022014_061600"] into "User ID" text field. I can do this in Java like below.

In Java:

"abc_"+new SimpleDateFormat("ddMMyyyy_hhmmss").format(new Date());

But, using Robot Framework how can we add this timestamp value to User ID text field? i.e., Any keyword or library for getting timestamp?

Using Robot Framework:

input text | userId | abc_ | ???
2

2 Answers

6
votes

Yes, try ${secs} = Get Time epoch which returns the familiar unix count of seconds after the UNIX epoch (1970-01-01 00:00:00 UTC). The return value is always an integer.

Docs link: Get Time.

1
votes

To get the specific format you want, you can create a python or java keyword, or write your own robot keyword that builds it. As @MarkHu points out, the Get Time keyword will get the time you need. Unfortunately it can't return the time in an artibtrary format, you have to build it yourself. Something like this:

${yr} | ${mth} | ${day} | ${hr} | ${min} | ${sec}= | Get Time | year month day hour min sec
${dtStr}= | Catenate | SEPARATOR= | ${day} | ${mth} | ${yr} | _ | ${hr} | ${min} | ${sec}

Incidentally, when I needed to do this, I got the time from a database, which allowed me to format it they way I wanted. If you are using a JDBC-wrapping library, this option is can be handy, esepecially if the generated time is to be compared to something generated server-side.