使用Apache JMeter
第一个问题:我能够从一个目录中读取一个文件(包含所有数据)并使用它的数据。
但是,现在的要求是为每个数据点设置一个单独的文件,这意味着我必须将多个数据文件放在一个目录中,然后从该目录中读取文件。我有一组数据文件,但我不知道如何读取循环中的每个文件并将其发送到JMeter。
第二个问题:我们这里讨论的数据是一个JSON,它是缩进和多行,如何将多行文件读入单输入变量?同样,当JSON是一行时,我也没有问题。
发布于 2015-09-02 18:22:16
- Add a [Beanshell Sampler](https://blazemeter.com/blog/queen-jmeters-built-componentshow-use-beanshell) to your test plan
- Put the following code into the Sampler's "Script" area:
文件文件夹=新文件(“/path/to/your/文件夹”);File[]文件= folder.listFiles();int计数器= 1;for (文件文件:文件){ vars.put("file_“+计数器,file.getAbsolutePath();counter++};
它将产生如下所设置的变量:
file_1=/path/to/your/文件夹/file1.txt文件2=/path/to/your/文件夹/file2.txt等。
- Input variable prefix: `file`
- Start index for loop: `0`
- End index for loop: leave blank
- Output variable name: anything meaningful, i.e. `current_file`
- Check `Add "_" before number`
${__FileToString(${current_file},,)}
来处理每个文件内容发布于 2020-10-15 03:51:19
如果使用目录列表数据源,为了循环遍历,应该使用使用$current_file
的位置。__FileToString()
函数为${__FileToString(${current_file},,)}
,由Dmitri和alexandrul提出。
看上去很简单。
发布于 2022-07-01 09:45:33
可以使用下面的代码读取文件数据。
FileWriter fWriter = new FileWriter("D:\\report\\Results.csv",true);
BufferedWriter buff = new BufferedWriter(fWriter);
buff.write("file created \n");
buff.close();
fWriter.close();
https://stackoverflow.com/questions/32321745
复制相似问题