Forum Discussion

MarcovS's avatar
MarcovS
Contributor
9 years ago

DataSink: Timestamp in filename

Hi all,

 

In a testcase, I have a Datasink step, where I want to save data I've collected form DataSource Step and data from executed REST Request TestStep. Every time the testcase/Datasink is executed, I want a unique outputfile to be created with a timestamp in the filename:

 

TestCase
-> DataSource
-> REST GET Request
-> Groovy Script
-> Datasink

 

I wonder if it is possible to add some variable(s) to the "Out file" field of the Datasink? Any examples how to approach this?

  • [SOLVED]

     

    Created a DataGen Step with a script-property "CurrentTimestamp" and the following code:

     

    def timestamp = new java.text.SimpleDateFormat('yyyy-MM-dd.HH.mm.ss')
    return timestamp.format(new Date()) 

    Used in the DataSink Step as output path:

     

    H:/PATH/Output/MembershipOptions_output${DataGen#CurrentTimestamp}.xlsx
  • UPDATE:

     

    I have this defined as Custom Property on TestCase level: 

     

    Name = CurrentTimeStamp
    Value = ${=new java.text.SimpleDateFormat(“yyyy-MM-dd’T’HH:mm:ss”).format(new Date())

    And this code as Out Filename in the DataSink Step:

     

    H:/Path/Output/MembershipOptions_output${#TestCaseName#CurrentTimeStamp}.xlsx

    Still it's not generating any timestamp in the filename...

    • MarcovS's avatar
      MarcovS
      Contributor

      [SOLVED]

       

      Created a DataGen Step with a script-property "CurrentTimestamp" and the following code:

       

      def timestamp = new java.text.SimpleDateFormat('yyyy-MM-dd.HH.mm.ss')
      return timestamp.format(new Date()) 

      Used in the DataSink Step as output path:

       

      H:/PATH/Output/MembershipOptions_output${DataGen#CurrentTimestamp}.xlsx