I have a test in Scala…I declared a global variable to share the token with the other user, like advised. however when the next scenario is invoked, access token is null instead of the actual value form global token variable, can you please advise me what i am missing here?
var globalToken = "";
//chainbuilder to get the token
def auth_token: ChainBuilder =
pause(pauseBy(5) seconds)
.exec(
http("Token")
.post("https://token.com")
.basicAuth("346394", "we4rywery")
.queryParam("scope", "read write")
.headers(header)
.check(status.is(200)).check(jsonPath("$.access_token").exists.saveAs("access_token")))
.exec(session => {
globalToken = session("access_token").as[String].trim ---> i assigned the token here, looks like it is not assigning as access_token is null for order scenario
println(session)
session
})
//Token is refreshing here as expected.
val executionTime = 4.hours
val authTimeout =5.minutes
val safetyMargin = 30.seconds
val authenticate: ChainBuilder = exec(auth_token)
.exec(session => session.set("timeout", authTimeout.fromNow))
private val refreshToken: ScenarioBuilder = scenario("Refresh token")
.exec(authenticate)
.during(executionTime) {
doIf(session => {
session("timeout").as[Deadline].timeLeft <= safetyMargin
}) {
exec(authenticate)
}
}
private val order: ScenarioBuilder =
scenario("order")
.exec(session => session.set("access_token", globalToken)) --> set the global token here, but it is null
.exec(getOrder)
setUp(
refreshToken.inject(atOnceUsers(1)),
order.inject(nothingFor(3), atOnceUsers(1))