我们可以将beanhell断言变量(在线程中)传递给jmeter中的cookie管理器用户定义变量(线程外)吗?
This is the image of user defined cookies which are been used on my request
答案 0 :(得分:0)
我认为它不会这样,你可以使用类似的东西:
" init"线程组:
import org.apache.jmeter.protocol.http.control.CookieManager;
CookieManager manager = ctx.getCurrentSampler().getProperty("HTTPSampler.cookie_manager").getObjectValue();
props.put("cookiecount",String.valueOf(manager.getCookieCount()));
for (int i=0;i<manager.getCookieCount();i++){
// code to convert Cookie information to JMeter Properties
props.put("cookie_name_" + i, manager.get(i).getName());
//…..
}
In&#34; Action&#34;线程组:
import org.apache.jmeter.protocol.http.control.CookieManager;
import org.apache.jmeter.protocol.http.control.Cookie;
import org.apache.jmeter.testelement.property.JMeterProperty;
CookieManager manager = ctx.getCurrentSampler().getProperty("HTTPSampler.cookie_manager").getObjectValue();
int count = Integer.parseInt(props.getProperty("cookiecount"));
for (int i=0;i<count;i++) {
Cookie cookie = new Cookie(props.getProperty("cookie_name"+i),props.getProperty("cookie_value"+i), props.getProperty("cookie_domain"+i),props.getProperty("cookie_path"+i), Boolean.parseBoolean(props.getProperty("cookie_secure"+i)), Long.parseLong(props.getProperty("cookie_expires"+i)));
manager.add(cookie);
}
JMeterProperty cookieprop = ctx.getCurrentSampler().getProperty("HTTPSampler.cookie_manager");
cookieprop.setObjectValue(manager);
ctx.getCurrentSampler().setProperty(myprop);
不要使用全局HTTP Cookie管理器,最好使用Thread Groups本地的2(或3)个独立的。