添加链接
link之家
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接

1. vars   API:http://jmeter.apache.org/api/org/apache/jmeter/threads/JMeterVariables.html

vars.get("");

vars.put("",XXX);

2. log

log.info("xxx");

3.ctx   API:http://jmeter.apache.org/api/org/apache/jmeter/threads/JMeterContext.html

ctx.getThreadNum()

4.props

encoding = props.get("sampleresult.default.encoding");
log.info("sampleresult.default.encoding="+encoding);

5.prev  API:http://jmeter.apache.org/api/org/apache/jmeter/samplers/SampleResult.html

System.out.println(prev.getResponseCode());
System.out.println(prev.getResponseDataAsString());
prev.setResponseCode("222");
System.out.println(prev.getResponseCode());
prev.setResponseMessage("qiaoyeye你好");
System.out.println(prev.getResponseMessage());
prev.setResponseData("qiaoyeye你好","UTF-8");
System.out.println(prev.getResponseDataAsString());
System.out.println(${port});
System.out.println(ctx.getThreadNum());

在beanshell中使用。如在BeanShell PreProcessor中:

log.info("内置变量练习开始");
ipString = vars.get("ip");
log.info("ipString="+ipString);
vars.put("newip",ipString);
log.info("newip="+vars.get("newip"));
encoding = props.get("sampleresult.default.encoding");
log.info("sampleresult.default.encoding="+encoding);

运行结果:

在BeanShell PostProcessor中:

System.out.println(prev.getResponseCode());
System.out.println(prev.getResponseDataAsString());
prev.setResponseCode("222");
System.out.println(prev.getResponseCode());
prev.setResponseMessage("qiaoyeye你好");
System.out.println(prev.getResponseMessage());
prev.setResponseData("qiaoyeye你好","UTF-8");
System.out.println(prev.getResponseDataAsString());
System.out.println(${port});
System.out.println(ctx.getThreadNum());

运行结果:

******************************************************************************************************************************************
作者:乔叶叶
博客地址:http://www.cnblogs.com/qiaoyeye/
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
******************************************************************************************************************************************