1

我正在尝试将测试结果写入 ReadyAPI 中的时间戳文件。我有一个 DataGen,它在第一步中创建时间戳,然后在 DataSink 中,我在输出文件的文件名中使用该时间戳。我听说 DataSinks 中允许进行属性扩展,但没有创建我的文件。

我是否需要先初始化和创建文件(Groovy 脚本)?

DataSink 中的输出文件配置: C:/Users/xxxxxx/Desktop/Projects/xxx/TestResults/OutFile_${DataGen#time}.xlsx

数据生成配置: 在此处输入图像描述

在此处输入图像描述

测试步骤

在此处输入图像描述

更新:
上次运行的时间戳正在数据接收器中使用。因此,假设这些是运行:
运行 1:上午 8:00:00 -> 时间戳值?
运行 2:上午 8:15:00 -> 时间戳值8:00:00 AM
运行 3:上午 8:30:00 -> 时间戳值 8:15:00 AM

似乎数据接收器留下了该属性的最后一个缓存版本,并且在新运行开始之前没有得到更新

4

2 回答 2

2

这很奇怪。

如果step 除了创建时间戳DataGen之外没有做任何事情,那么我建议尝试以下操作:

  • DataGenGroovy Script测试步骤替换步骤。
  • 将以下脚本内容放入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)
  • 对于文件名,请使用 -${#TestCase#DATA_SINK_FILE_PATH}
于 2016-08-23T06:36:19.763 回答
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
于 2016-08-26T13:09:31.470 回答