将文件移动到 Jmeter 中的另一个目录

Move file to another directory in Jmeter

我正在尝试在 Jmeter 中进行性能测试,所以在 运行 我的测试之前我必须获取新数据,基本上我需要在完成测试执行后移动我使用过的 csv 文件。

解决方案 1

您必须 运行 特定于您的操作系统的命令(Windows、Mac、Linux)

您可以使用 OS Process Sampler 将 CSV 文件移动到其他位置。

The OS Process Sampler is a sampler that can be used to execute commands on the local machine. It should allow execution of any command that can be run from the command line. Validation of the return code can be enabled, and the expected return code can be specified.

  1. setUp Thread Group 添加到您的测试计划

  2. JSR223 Sampler 添加到设置线程组

  3. 将以下代码放入“脚本”区域:

    org.apache.commons.io.FileUtils.moveFile(new File('/current/path/to/csv.file'),new File('/new/path/to/csv.file'))
    
  4. 就是这样,设置线程组在“主”线程组之前执行,代码将移动文件

解决方案 2

您可以使用Groovy来执行命令。 使用以下脚本添加 JSR223 采样器

在 Mac/Linux

"mv pathToSrcFile targetFolder".execute()
SampleResult.setIgnore()

在 Windows

"move pathToSrcFile targetFolder".execute()
SampleResult.setIgnore()