I have a URL after posting to which I get my access token
def Authorize(scenarioName: String) : ChainBuilder ={
exec(http(scenarioName)
.post("/token")
.body(StringBody(""“grant_type=client_credentials”""))
.check(status is 200)
.check(jsonPath("$.access_token").saveAs(“token”))
)
}
Now I want to make this saved "token " variable globally accessible.
Please suggest a way to do the same. complete code file is attached.
Thanks !!
token code.txt (1.3 KB)
Something like this (it is idea only!):
vat t=""
…
Your code here and:
.exec{ session =>
t = session(“token”) // Now you have token in “global” variable
session
}
Sorry, I don’t have computer now and can’t write correct code ^(
Hi … thanks for your suggestion. I tried but it gives error “reassignment of to variable” … so I tried below.
Can you please help me analyze it further.
below code in part of AuthorizationSimulation class
val tokenString = “”
.exec(session => {
println(session.get(“token”))
session.set(“tokenString”,session.get(“token”))
session
})
Now while trying to access this variable in a different scala class of same project I get an error that variable is not found.
Below code is part of OrgFuncSimulation class
val sentHeaders = Map(“Content-Type”->“application/json”,“sourceName”->“MDM”,“destinationName”->“org360”,“Authorization”->AuthorizationSimulation.tokenString)