Hi guys,
In BaseSimulation I have below code:
protected String url = “xxx”;
protected HttpProtocolBuilder httpProtocol = HttpDsl.http
.baseUrl(url)
.inferHtmlResources(
CoreDsl.AllowList(),
CoreDsl.DenyList(“.\.js", ".\.css”, “.\.gif", ".\.jpeg”, “.\.jpg", ".\.ico”,
“.\.woff", ".\.woff2”, “.\.(t|o)tf", ".\.png”, “.\.svg",
“.detectportal\.firefox\.com.”))
.acceptHeader("/*”)
.acceptEncodingHeader(“gzip, deflate”)
.acceptLanguageHeader(“en-US,en;q=0.9”)
.contentTypeHeader(“application/json; charset=UTF-8”)
.userAgentHeader(
“Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/112.0.0.0 Safari/537.36”);
public static ChainBuilder getAuthenticate() {
return exec(
http(“first endpoint”)
.get(“xxx”)
.header(“Content-Type”,“application/json”)
.header(“Connection”, “close”)
.body(StringBody(“{ \n”
+ " "password": "xxx", \n"
+ " "username": "xxx" \n"
+ " }“))
.check(status().is(200))
.check(jsonPath(”$.csrfToken").notNull().saveAs(“csrfToken”)))
.exec(
http(“second endpoint”)
.post(“xxx”)
.header(“Content-Type”,“application/json”)
.header(“Connection”, “close”)
.header(“CSRF-Token”, “#{csrfToken}”)
.check(status().is(200)))
.exec(getCookieValue(CookieKey(“securityToken”).saveAs(“securityToken”)))
.exec(getCookieValue(CookieKey(“JSESSIONID”).saveAs(“JSESSIONID”)));
}
public static ChainBuilder getAnalysis() {
return exec(http(“getAnalysis”)
.post(“xxx”)
.headers(HEADERS)
.check(status().is(200)));
}
protected static Map<String, String> HEADERS = Map.of(
“Accept”, “application/json”,
“Content-Type”, “application/json”,
“Cookie”, “JSESSIONID= #{JSESSIONID}; securityToken= #{securityToken}”);
In TestSimulation:
ChainBuilder getAnalysis =
getAuthenticate()
.exitHereIfFailed()
.forever().on(
getAnalysis()
.exitHereIfFailed()
.pause(1));
ScenarioBuilder scn = scenario(“TestSimulation”).exec(getAnalysis);
{
setUp(scn.injectOpen(atOnceUsers(1))).protocols(httpProtocol);
}
How I can pass cookie from getAuthenticate (JSESSIONID and securityToken from second endpoint) to getAnalysis?
I read documentation about cookies but I don’t understand how I can fit it to my problem
Thanks for help