Jmeter,常见参数 vars、prev、ctx 、props 类的api--beanshell

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");

转载于:https://www.cnblogs.com/SZLLQ2000/p/6911780.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值