获取随机文件名
Get the random file name
一个文件夹包含大约 10 个文件(如 1.csv、2.csv...10.csv)我正在使用 beanshell 预处理器将它们上传到我的 http 请求以下脚本,
File folder = new File("C:\User\SYSTEMTESTING\SAMPLENEWFILES\REUPLOADFILES");
File[] fileForUpload = folder.listFiles();
Random rnd = new Random();
vars.put("CURRENT_FILE", fileForUpload[rnd.nextInt(fileForUpload.length)].getAbsolutePath());
想要获取使用 JSR223 post 处理器上传的文件名
log.info("File Uploaded Is :"+${CURRENT_FILE});
我收到了,
javax.script.ScriptException: org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
Script8.groovy: 1: Missing ')' @ line 1, column 79.
"File Uploaded Is ------->"+C:\Users\SY
在请求正文中:
PUT data:
--RhvwJL7ZdnIMBIaE0CoKVhsE68UNUiH
Content-Disposition: form-data; name="file"; filename="CSV_10_MB.csv"
Content-Type: application/vnd.ms-excel
Content-Transfer-Encoding: binary
<actual file content, not shown here>
--RhvwJL7ZdnIMBIaE0CoKVhsE68UNUiH--
我想要 CSV_10_MB.csv
名字。
使用vars.get
:
log.info("File Uploaded Is :" + vars.get("CURRENT_FILE"));
如果你想使用 Groovy's GString,你需要声明这个 CURRENT_FILE
属性,如果这是你正在寻找的,你需要修改你的代码,如:
def CURRENT_FILE = vars.get("CURRENT_FILE")
log.info("File Uploaded Is: ${CURRENT_FILE}")
或使用相同的 vars
shorthand 将文件名打印到 JMeter 日志中,例如:
log.info("File Uploaded Is: " + vars.get("CURRENT_FILE"))
一个文件夹包含大约 10 个文件(如 1.csv、2.csv...10.csv)我正在使用 beanshell 预处理器将它们上传到我的 http 请求以下脚本,
File folder = new File("C:\User\SYSTEMTESTING\SAMPLENEWFILES\REUPLOADFILES");
File[] fileForUpload = folder.listFiles();
Random rnd = new Random();
vars.put("CURRENT_FILE", fileForUpload[rnd.nextInt(fileForUpload.length)].getAbsolutePath());
想要获取使用 JSR223 post 处理器上传的文件名
log.info("File Uploaded Is :"+${CURRENT_FILE});
我收到了,
javax.script.ScriptException: org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
Script8.groovy: 1: Missing ')' @ line 1, column 79.
"File Uploaded Is ------->"+C:\Users\SY
在请求正文中:
PUT data:
--RhvwJL7ZdnIMBIaE0CoKVhsE68UNUiH
Content-Disposition: form-data; name="file"; filename="CSV_10_MB.csv"
Content-Type: application/vnd.ms-excel
Content-Transfer-Encoding: binary
<actual file content, not shown here>
--RhvwJL7ZdnIMBIaE0CoKVhsE68UNUiH--
我想要 CSV_10_MB.csv
名字。
使用vars.get
:
log.info("File Uploaded Is :" + vars.get("CURRENT_FILE"));
如果你想使用 Groovy's GString,你需要声明这个 CURRENT_FILE
属性,如果这是你正在寻找的,你需要修改你的代码,如:
def CURRENT_FILE = vars.get("CURRENT_FILE")
log.info("File Uploaded Is: ${CURRENT_FILE}")
或使用相同的 vars
shorthand 将文件名打印到 JMeter 日志中,例如:
log.info("File Uploaded Is: " + vars.get("CURRENT_FILE"))