(二)beanshell内置变量用法

介绍beanshell几个内置变量常见用法,基本就这些,其他遇到再补充

一、vars - (JMeterVariables) - gives read/write access to variables

这个变量实际引用了JMeter线程中的局部变量容器(本质上是Map),因此可以通过put和get方法访问JMeter中的变量。这个变量是所有内置变量中最有用的,它是测试用例与BeanShell交互的桥梁。

常用方法

vars.get(key);

vars.getObject(key);
vars.put(key,val);
vars.putObject("OBJ1",new Object());

 

二、prev - (SampleResult) - gives access to the previous SampleResult (if any:如果有的话)

获取前面的sample返回的信息

常用方法:

getResponseDataAsString():获取响应信息

getResponseCode() :获取响应code

 

三、log - (Logger) - can be used to write to the log file

相当于Java中System.out 将其打印到日志文件中

日志文件在安装路径下bin\Jmeter.log中

log.info("数量统计"+count);

 

四、将断言中失败信息打印在report中

断言结果字段是Failure=true/false; 运行结果需要打印出的信息写在FailureMessage = "XXXX";

  • Failure - boolean; read-write; used to set the Assertion status
  • FailureMessage - String; read-write; used to set the Assertion message
if(!"${uid}".equals("774170"))
{
    Failure=true;
    FailureMessage = "error, check";
}

jmeter有哪些bean shell

  • BeanShell Sampler
    直接使用BeanShell来编写样例(sampler)
  • BeanShell PreProcessor
    样例触发前,使用BeanShell进行加工处理。
  • BeanShell PostProcessor
    样例触发后,使用BeanShell进行加工处理。
  • BeanShell Assertion
    使用BeanShell进行断言处理。
  • BeanShell Listener
    使用BeanShell做监听器

 

posted @ 2019-06-04 18:39  测试开发分享站  阅读(214)  评论(0编辑  收藏  举报