如何在JMeter bean shell断言中打印变量的值

Udh*_*hay 4 api verification web-services jmeter assertion

使用Jmeter,我通过REST API将值传递给Web服务.在成功时,API会将值更新为mongo DB.使用JMeter BeanShell Assertion断言时,我想显示请求中发送的值和存储在DB中的值.

我使用下面的脚本..

String req_data="${Request_Configuration}";
String res_data="${mongo_db_Configuration}";


if(res_data.equalsIgnoreCase(req_data)){
   Failure=false;
   FailureMessage = "Data stored in DB is correct";
   System.out.println("ReqData="+req_data);
   System.out.println("ResData="+res_data);
}
else{
   Failure = true;
   FailureMessage = "Data Stored in DB is NOT correct";
   System.out.println("ReqData="+req_data);
   System.out.println("ResData="+res_data);
}
Run Code Online (Sandbox Code Playgroud)

我只是无法打印ReqData和ResData.请帮忙.

Dmi*_*i T 6

您的脚本中存在问题.在Beanshell中,您无法访问类似的变量${Request_Configuration},而是需要使用vars.get("Request_Configuration").

vars是当前上下文的JMeterVariables类实例的简写.

因此,您的Beanshell断言代码应如下所示:

String req_data=vars.get("Request_Configuration");
String res_data=vars.get("mongo_db_Configuration");


if(res_data.equalsIgnoreCase(req_data)){
   Failure=false;
   FailureMessage = "Data stored in DB is correct";
   System.out.println("ReqData="+req_data);
   System.out.println("ResData="+res_data);
}
else{
   Failure = true;
   FailureMessage = "Data Stored in DB is NOT correct";
   System.out.println("ReqData="+req_data);
   System.out.println("ResData="+res_data);
}
Run Code Online (Sandbox Code Playgroud)

我也建议使用log.info()而不是System.out.println()在那种情况下,结果将转到jmeter.log文件,并且不会因超过屏幕缓冲区大小而被"吃掉".

有关Beanshell脚本和Beanshell解释中的各种JMeter API对象的更多信息,请参见如何使用BeanShell:JMeter最喜欢的内置组件指南.


Bru*_*eri 5

我没有用在剪断下面的代码BeanShell Assertion中我HTTP Request-sampler打印出我的三个变量idtype以及value

log.info(Thread.currentThread().getName()+": "+SampleLabel+": id: " + vars.get("id"));
log.info(Thread.currentThread().getName()+": "+SampleLabel+":  +-type: " + vars.get("type"));
log.info(Thread.currentThread().getName()+": "+SampleLabel+":  +-value: " + vars.get("value"));
Run Code Online (Sandbox Code Playgroud)