Chỉnh sửa cookie trước khi request

1. Tạo BeanShell PreProcessor

2. Thêm code dưới và thay đổi giá cookie tương ứng

import org.apache.jmeter.protocol.http.control.Cookie;
import org.apache.jmeter.protocol.http.control.CookieManager;

CookieManager manager = sampler.getCookieManager();

//remove cookie theo tên
for (int i=0;i<manager.getCookieCount();i++){
Cookie cookie = manager.get(i);
if (cookie.getName().equals(“abc”)){
sampler.getCookieManager().remove(i);
}
}

//thêm mới cookie

CookieManager manager = ctx.getCurrentSampler().getProperty(“HTTPSampler.cookie_manager”).getObjectValue();
Cookie cookie = new Cookie(“abc”, “abc”, sampler.getDomain(), sampler.getPath(), false, System.currentTimeMillis());
manager.add(cookie);
sampler.setCookieManager(manager);

Leave a Reply

Your email address will not be published. Required fields are marked *