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:
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