【发布时间】:2011-11-08 05:45:50
【问题描述】:
我正在测试具有“加载文档”功能的服务。我需要为每个请求发送一个独特的文档。在 HTTP 请求采样器配置菜单中,我看到我可以随请求一起发送文档。但是,我不知道如何为每个请求发送不同的文档。有没有办法让 JMeter 稍微修改一个文档,生成一个指定的文档,或者甚至可以选择一系列外部生成的文档来提交请求?
【问题讨论】:
我正在测试具有“加载文档”功能的服务。我需要为每个请求发送一个独特的文档。在 HTTP 请求采样器配置菜单中,我看到我可以随请求一起发送文档。但是,我不知道如何为每个请求发送不同的文档。有没有办法让 JMeter 稍微修改一个文档,生成一个指定的文档,或者甚至可以选择一系列外部生成的文档来提交请求?
【问题讨论】:
您可以使用 While Controller 下的 CSV Data Set Config 循环读取和发送预先创建的测试文档名称。
这看起来像:
详细说明:
${__javaScript("${testFile}"!="<EOF>",)} - 读取列表直到文件末尾
BeanShell Sampler 代码生成测试文件列表:
import java.text.*;
import java.io.*;
import java.util.*;
String [] params = Parameters.split(",");
String contentList = params[0];
String testDataDir = params[1];
File dir = new File(System.getProperty("user.dir") + File.separator + testDataDir);
BufferedWriter out = null;
try {
if (!dir.exists()) {
throw new Exception ("Directory " + dir.getName() + " not found.");
}
File contentFile = new File(System.getProperty("user.dir") + File.separator + contentList);
if (contentFile.exists()) {
contentFile.delete();
}
FileWriter fw = new FileWriter(contentFile, true);
out = new BufferedWriter(fw);
System.out.println("\n--------------------------------------------------------------------------------------");
System.out.println("CONTENT LIST:\n");
if ((dir.exists()) && (dir.listFiles() != null) && (out != null)) {
for (File f : dir.listFiles()) {
if (contentFile.length() == 0) {
out.write(f.getName());
} else {
out.write("\n" + f.getName());
}
out.flush();
System.out.println("Content " + f.getName() + " added to " + contentFile.getName() + ".");
}
}
System.out.println("--------------------------------------------------------------------------------------\n");
}
catch (Exception ex) {
IsSuccess = false;
log.error(ex.getMessage());
System.err.println(ex.getMessage());
}
catch (Throwable thex) {
System.err.println(thex.getMessage());
}
finally {
out.close();
}
【讨论】: