1

I'm trying to write test results to a time stamped file in ReadyAPI. I have a DataGen that creates the timestamp in the first step and then later in the DataSink, I use that timestamp in the filename of the out file. I've heard that Property Expansion is allowed in DataSinks but my file isn't being created.

Do I need to initialize and create the file first (Groovy Script)?

Out File Configuration in DataSink: C:/Users/xxxxxx/Desktop/Projects/xxx/TestResults/OutFile_${DataGen#time}.xlsx

DataGen Config: enter image description here

enter image description here

Test Steps

enter image description here

UPDATE:
The last run's timestamp is being used in the datasink. So let's say these are the runs:
Run 1: 8:00:00 AM -> Timestamped value ??
Run 2: 8:15:00 AM -> Timestamped value 8:00:00 AM
Run 3: 8:30:00 AM -> Timestamped value 8:15:00 AM

It seems like the datasink is left with the last cached version of the property and this doesn't get updated BEFORE the new run begins

Fueled By Coffee
  • 2,467
  • 7
  • 29
  • 43

2 Answers2

2

That is strange.

If DataGen step isn't doing anything other than timestamp creation, then I would suggest to try the following:

  • Replace DataGen step with Groovy Script test step.
  • Have the below script content into the Groovy Script.
def dateTime = new Date().format('yyyy_MM_ddHHmmss')
def fileName = "C:/Users/xxxxxx/Desktop/Projects/xxx/TestResults/OutFile_${dateTime}.xlsx"
context.testCase.setPropertyValue('DATA_SINK_FILE_PATH', fileName as String)
  • And for the file name, please use - ${#TestCase#DATA_SINK_FILE_PATH}
Rao
  • 20,781
  • 11
  • 57
  • 77
  • Thanks, definitely a step in the right direction. Something weird is happening though.. Please see update – Fueled By Coffee Aug 23 '16 at 12:54
  • Glad to that helped. And that proves property expansion works. `DataGen` we can't fix as it's not our hands. And I believe that this answer helps to proceed further while achieving the desired functionality. So appreciate if you can accept it as answer. – Rao Aug 23 '16 at 13:34
0

The problem wasn't with timestamps or file creation at all. The issue was trying to use a property expansion in the DataSink. The only way to use a timestamp as the filename is to create it in the Test Case TearDown Script. This ensures that all outfiles are closed and no locks are in place.

To fix this problem, use a temp file to write to during the test - in the DataSink. Then in the TearDown Script, create your timestamp, create the new out file, and write the contents of the old file to it.

Here is the Groovy script I ended up using:

import jxl.*
import jxl.write.*
import java.text.SimpleDateFormat

def timestamp = ''
timestamp = new Date().format('yyyy_MM_dd_HH_mm_ss')

def tempFile = context.testCase.getPropertyValue('tempFile')

def output = tempFile +"_" + timestamp + ".xlsx"
tempFile += ".xlsx"

new File(output) << new File(tempFile).bytes
Fueled By Coffee
  • 2,467
  • 7
  • 29
  • 43