http://www.cnblogs.com/fnng/p/5827577.html---------jmeter 性能测试
jmeter常见参数 vars、prev、ctx 、props 类的api
- ctx - ( JMeterContext ) - gives access to the context
- vars - ( JMeterVariables ) - gives read/write access to variables: vars.get(key); vars.put(key,val); vars.putObject("OBJ1",new Object()); vars.getObject("OBJ2");
- props - (JMeterProperties - class java.util.Properties) - e.g. props.get("START.HMS"); props.put("PROP1","1234");
- prev - ( SampleResult ) - gives access to the previous SampleResult (if any)
- sampler - (Sampler)- gives access to the current sampler
ctx 地址:http://jmeter.apache.org/api/org/apache/jmeter/threads/JMeterContext.html
vars 地址:http://jmeter.apache.org/api/org/apache/jmeter/threads/JMeterVariables.html
prev地址:http://jmeter.apache.org/api/org/apache/jmeter/samplers/SampleResult.html
beanshell--------------
import org.apache.jmeter.protocol.http.control.CookieManager;
CookieManager manager = ctx.getCurrentSampler().getProperty("HTTPSampler.cookie_manager").getObjectValue();
sampler.setCookieManager(manager);
CookieManager Newmanager = sampler.getCookieManager();
props.put("cookiecount", String.valueOf(manager.getCookieCount()));
for (int i = 0; i < manager.getCookieCount(); i++)
{
props.put("cookie_name" + i, manager.get(i).getName());
props.put("cookie_value" + i, manager.get(i).getValue());
props.put("cookie_domain" + i, manager.get(i).getDomain());
props.put("cookie_path" + i, manager.get(i).getPath());
props.put("cookie_expires" + i, String.valueOf(manager.get(i).getExpires()));
props.put("cookie_secure" + i, String.valueOf(manager.get(i).getSecure()));
}
log.info("\n"+Newmanager.getCookieCount());
log.info("\n"+Newmanager.get(0).getName());
log.info("\n"+Newmanager.get(1).getName());
log.info("\n"+Newmanager.get(0).getValue());
log.info("\n"+Newmanager.get(1).getValue());
log.info("\n"+Newmanager.get(0).getDomain());
log.info("\n"+Newmanager.get(1).getDomain());
Newmanager.get(1).setValue("'"+Newmanager.get(1).getValue()+"'");
Newmanager.get(0).setDomain("unipus.cn");