I want to store the session variable: ‘fromSessionToken’ and pass it into a Scala function. Below is the code:
//API definitions
object myAPIs {
//Extract Token Test:
val getToken = http(“Get Token”)
.post(host + “/access_token”)
.headers(some_headers)
.body(some_body)
.check(status is 200)
.check(jsonPath("$.access_token").saveAs(“token”))
val createUser =
http(“Use Token to create user”)
.post(host + “/user”)
.header(“Authentication”, decodedToken)
.header(“Content-Type”,“application/json”)
.body(some_body)
.check(status is 201)
def decodedToken(fromSessionToken: String) = decodeTheAccessToken(fromSessionToken)
}
// Scenarios:
object e2eFlow {
val fromSessionToken : String = _
val e2eTest = scenario(“E2E Flow”)
.exec(myAPIs.getToken)
.exec(session => {
var token = session.get(“token”).as[String]
println ("TOKEN -------> " + token)
session.set(fromSessionToken, token)
})
.exec(myAPIs.createUser)
}
//Simulation
class E2ETest extends Simulation {
val runTest = List(
e2eFlow.e2eTest.inject(atOnceUsers(numberOfConcurrentUsers))
)
setUp(runTest).assertions(global.failedRequests.count is 0)
}