Test Plan
Thread Group1
Thread Group2
Assume that you have a test scenario to pass the session of the Thread Group1 to Thread Group2 in order to create a cookie from that session. In order to achive that here I use hashmapThread Group1
Thread Group2
1 Initialize hash map inside a BeanShell Sampler in top level of Test plan
Map map = new HashMap();
String sessionId = vars.get("SSOAuthSessionID"); // exctracted session
map = bsh.shared.session_map; // set bsh.shared to map
if ("null".equals(sessionId)) {
} else {
String id = vars.get("sessionID_count"); // I have added a counter varibale as the key
map.put(id, sessionId); //Adding elements toMap
}
3. Retrieve the values in bash.shared.session map using BeanShell PreProcessor in Thread Group 2 and createmap = bsh.shared.session_map; // set bsh.shared to map
if ("null".equals(sessionId)) {
} else {
String id = vars.get("sessionID_count"); // I have added a counter varibale as the key
map.put(id, sessionId); //Adding elements toMap
}
import org.apache.jmeter.protocol.http.control.CookieManager;
import org.apache.jmeter.protocol.http.control.Cookie;
map = bsh.shared.session_map;
String id = vars.get("sessionID_count2"); //I have added a counter varibale as the key
if (map.size() == 0) {} else {
String sessionId = map.get(id);
vars.put("portal_session_", sessionId); //Retrieving values in bash.shared.session
CookieManager manager = sampler.getCookieManager();
Cookie cookie = new Cookie("JSESSIONID", sessionId, "${serverHostName}", "/user-portal/", false, 0);
manager.add(cookie); //
}
Hope that this will find helpful for you.import org.apache.jmeter.protocol.http.control.Cookie;
map = bsh.shared.session_map;
String id = vars.get("sessionID_count2"); //I have added a counter varibale as the key
if (map.size() == 0) {} else {
String sessionId = map.get(id);
vars.put("portal_session_", sessionId); //Retrieving values in bash.shared.session
CookieManager manager = sampler.getCookieManager();
Cookie cookie = new Cookie("JSESSIONID", sessionId, "${serverHostName}", "/user-portal/", false, 0);
manager.add(cookie); //
}
can you help me pass a cookie from thread1 to thread2
ReplyDeleteI am using Jmeter5.2.1 , I am not able to create a bean shell sampler at test plan level. can you please help.
ReplyDelete