如何使用jmeter重命名Windows上的文件?
我尝试使用OS Process Sampler重命名桌面上的文件,这是我的配置:如何使用jmeter重命名Windows上的文件?,jmeter,Jmeter,我尝试使用OS Process Sampler重命名桌面上的文件,这是我的配置: 命令:ren 工作目录:桌面路径 命令参数1:文件名 命令参数2:我要更改为的名称 查看结果树时出错: Exception occurred whilst executing system call: java.io.IOException: Cannot run program "ren" (in directory "Working directory i specified"): CreateProces
- 命令:ren
- 工作目录:桌面路径
- 命令参数1:文件名
- 命令参数2:我要更改为的名称
Exception occurred whilst executing system call: java.io.IOException: Cannot run program "ren" (in directory "Working directory i specified"): CreateProcess error=2, The system cannot find the file specified
如果无法使用OS process sampler完成,我可以使用任何其他解决方案
提前感谢。更新
操作系统采样器配置
以下是您需要在OS Process Sampler
命令:cmd
命令参数:
将每个值添加到单独的行中
/C
ren C:\Test\Oldfilename.txt newfilename.txt
替代溶液
下面是使用BeanShell后处理器
try {
String oldfile = "C:\\TestingTools\\apache-jmeter-3.2\\apache-jmeter-3.2\\bin\\test.txt";
File file = new File(oldfile);
File newfile = new File("C:\\TestingTools\\apache-jmeter-3.2\\apache-jmeter-3.2\\bin\\test123.txt");
boolean success = file.renameTo(newfile);
if (success)
log.info("file renamed successfully");
}
catch (Throwable e) {
log.error("Error in Beanshell",e);
}
输出
更新
操作系统采样器配置
以下是您需要在OS Process Sampler
命令:cmd
命令参数:
将每个值添加到单独的行中
/C
ren C:\Test\Oldfilename.txt newfilename.txt
替代溶液
下面是使用BeanShell后处理器
try {
String oldfile = "C:\\TestingTools\\apache-jmeter-3.2\\apache-jmeter-3.2\\bin\\test.txt";
File file = new File(oldfile);
File newfile = new File("C:\\TestingTools\\apache-jmeter-3.2\\apache-jmeter-3.2\\bin\\test123.txt");
boolean success = file.renameTo(newfile);
if (success)
log.info("file renamed successfully");
}
catch (Throwable e) {
log.error("Error in Beanshell",e);
}
输出
您不能直接拨打电话,您需要通过以下方式进行:
相关的操作系统进程采样器配置如下所示:
一个参数-一行
有关在JMeter测试范围内运行第三方应用程序的不同方法的更多信息,请参阅文章。您不能直接调用,您需要通过以下方式进行调用:
相关的操作系统进程采样器配置如下所示:
一个参数-一行
有关在JMeter测试范围内运行第三方应用程序的不同方法的更多信息,请参阅文章。您可以使用BeanShell Sampler执行此任务。 BeanShell是最先进的JMeter内置组件之一。信息技术 支持Java语法,并通过loose等脚本功能对其进行扩展 类型、命令和方法闭包。如果您的测试用例不常见 通过嵌入式JMeter组件的实现变得很棘手或复杂 即使不可能,BeanShell也可以成为实现您的目标的绝佳选择 目标 要执行此操作,请首先在测试计划中声明Jmeter变量 添加线程组、BeanShell采样器、HTTP请求、查看结果树后[首选项] 请注意,您不能仅仅通过增加 线程组中的线程(用户)数,因为jmeter不是以这种方式实现的。 从技术上讲,所有线程都会尝试一次更改一个文件名,但该文件名不起作用。 解决方案是为尝试执行测试的用户数创建一个文件夹结构,并设置映射线程数的每个文件夹的路径。 如下图所示
您可以使用BeanShell取样器执行此任务。 BeanShell是最先进的JMeter内置组件之一。信息技术 支持Java语法,并通过loose等脚本功能对其进行扩展 类型、命令和方法闭包。如果您的测试用例不常见 通过嵌入式JMeter组件的实现变得很棘手或复杂 即使不可能,BeanShell也可以成为实现您的目标的绝佳选择 目标 要执行此操作,请首先在测试计划中声明Jmeter变量 添加线程组、BeanShell采样器、HTTP请求、查看结果树后[首选项] 请注意,您不能仅仅通过增加 线程组中的线程(用户)数,因为jmeter不是以这种方式实现的。 从技术上讲,所有线程都会尝试一次更改一个文件名,但该文件名不起作用。 解决方案是为尝试执行测试的用户数创建一个文件夹结构,并设置映射线程数的每个文件夹的路径。 如下图所示
您能展示一下您是如何配置组件的吗?您能展示一下您是如何配置组件的吗?
Below Code is the Sample BeanShell Code which I implemented.
try{
int count=0;
String renamedFile = "";
File imageFile;
String image ="E:\\MCMS\\USR1\\issue"+(int) (Math.random()*1000000000)+".PNG";
if(vars.get("counter").equals("A"))
{
imageFile = new File("E:\\MCMS\\USR1\\issue657327357.PNG");
//vars.put("fileName",imageFile.getAbsolutePath());
log.info("First File Identification");
log.info("First File Name : "+imageFile.getAbsolutePath());
vars.put("counter","B");
}
else
{
imageFile = new File(vars.get("nextFile"));
log.info("Next File Iterations");
log.info("Current System file : "+imageFile.getAbsolutePath());
}
File imageFile2 = new File(image);
log.info("System Ram gerated File :"+imageFile2.getAbsolutePath());
log.info("System is giong to replace ram generated file with current system file :");
if (imageFile.renameTo(imageFile2))
{
vars.put("nextFile", ""+imageFile2.getAbsolutePath());
log.info("Conversion successful");
log.info("Assigning the new file name to the jmeter variable");
vars.put("fileName",imageFile2.getAbsolutePath());
log.info(imageFile.getAbsolutePath());
log.info(imageFile2.getAbsolutePath());
}
else
{
log.info("Rename failed");
log.info("I failed but the file in the directory is"+imageFile.getAbsolutePath());
}
}
catch(Exception e){
log.info("Exception Occured"+e);
}