1
我正在測試具有「加載文檔」功能的服務。我需要爲每個請求發送一個獨特的文檔。在HTTP請求採樣器配置菜單中,我發現我可以發送一個文檔以及我的請求。但是,我不知道如何隨每個請求發送不同的文檔。有沒有辦法讓JMeter稍微修改一個文檔,生成一個指定的文檔,或者甚至可能選擇一系列外部生成的文檔來提交請求?使用JMeter測試加載文檔功能
我正在測試具有「加載文檔」功能的服務。我需要爲每個請求發送一個獨特的文檔。在HTTP請求採樣器配置菜單中,我發現我可以發送一個文檔以及我的請求。但是,我不知道如何隨每個請求發送不同的文檔。有沒有辦法讓JMeter稍微修改一個文檔,生成一個指定的文檔,或者甚至可能選擇一系列外部生成的文檔來提交請求?使用JMeter測試加載文檔功能
您可以使用While控制器下的CSV數據集配置在循環中讀取和發送預先創建的測試文檔名稱。
這將是這樣的:
詳細:
${__javaScript("${testFile}"!="<EOF>",)}
- 耕種文件
BeanShell取樣器代碼生成測試文件列表:
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();
}