i am using Gatling 3.3 version and It seems session variable used in below code is not able to pass the Token Type → Bearer and access_token using session variable,here is the full code ,is it possible with you to have a look ,here is code provided …no worries all tokens are dummy tokens as i haven changed before pasting code here.Test expects the login method to be executed first and then the CreatePrivateEvent method as the latter takes tokens from Login method hence i have written
From Logs It looks Token Type → Bearer and access_token are successfully generated by Login Method but the same token is not propagated to CreatePrivateEvent method.
any other way you can suggest to use session variable would be highly welcomed?
package simulations
import baseConfig.BaseSimulation
import com.jayway.jsonpath.JsonPath
import io.gatling.core.Predef._
import io.gatling.core.session
import io.gatling.http.Predef._
import scala.concurrent.duration._
import scala.concurrent.forkjoin.ThreadLocalRandom
import scala.language.postfixOps
import scala.math._
import scala.concurrent.duration.DurationInt
import scala.io.Source
class gamekeeper extends BaseSimulation {
val uri2 = "https://api.platform.abc.com"
val headers_3 = Map(
"accept" -> "application/json, text/plain, */*",
"cache-control" -> "no-cache",
"origin" -> "https://myaccounts.wi.com",
"pragma" -> "no-cache",
"referer" -> "https://myaccounts.abc.com/login?redireretailer- stage.abc.com%2F",
"sec-fetch-mode" -> "cors",
"sec-fetch-site" -> "same-site")
val headers_10 = Map("Content-Type" -> "application/json","Authorization" -> "${token_type} +
${access_token}" )
val headers_PrivateEvent = Map(
"Content-Type" -> "application/json",
"Authorization" -> "${token_type} + ${access_token}"
)
val usersDataSource=jsonFile("C:/Gatling2/gatling3james/src/gatling/resources/data/input-
gamekeeper.json").circular
val nameDataSource=jsonFile("C:/Gatling2/gatling3james/src/gatling/resources/data/input-
gamekeeper-StringBody.json").random
val source: String = Source.fromFile("C:/Gatling2/gatling3james/src/gatling/resources
/data/input-gamekeeper.json").getLines.mkString
def userCount: Int = JsonPath.parse(source).read("$.[0].user")
def testDuration: Int = JsonPath.parse(source).read("$.[0].testDuration")
def rampDuration: Int = JsonPath.parse(source).read("$.[0].rampDuration")
// print out the properties at the start of the test
before {
println(s"Running test with ${userCount} users")
println(s"Ramping users over ${rampDuration} seconds")
println(s"Total Test duration: ${testDuration} seconds")
}
def createPrivateEvent()={
exec(http("Create Private Event")
.post("https://api.tabletop-stage.tiamat-origin.cloud/dev/event-reservations-service
/PrivateEvents")
.headers(headers_PrivateEvent)
.body(StringBody(
"""
>{
> "eventId": 0,
> "name": "new Event",
> "description": "This event is gonna be uh-maaaazing",
> "format": "draft",
> "gamesToWin": 2
>}
""".stripMargin)).asJSON
.check(status.in(200,201))
.check(jsonPath(path="$.name").is("new Event"))
.check(jsonPath(path="$.eventId").saveAs(key="eventId")))
.exec{session=>println(session);session}
.pause(1)
}
val login = exec( exec(http("PlatForm Auth Url")
.post(uri2 + "/auth/oauth/token")
.headers(headers_3)
.formParam("grant_type", "password")
.formParam("username", "automation-store-admin1@abc.com")
.formParam("password", "c0Ba5PBdvVl2")
.basicAuth("NznShwKmLPMErYkfuvyynfA9","r2Rgx89aCFTfjbj7TU59sL8q")
.check(jsonPath("$.access_token").exists.saveAs("access_token"))
.check(jsonPath("$.token_type").exists.saveAs("token_type")))
)
val scenario4 = scenario("Create Private Events ").exec(login).exec(createPrivateEvent())
setUp(
scenario4.inject(
nothingFor(5 seconds),
rampUsers(userCount) over ( rampDuration ))
.protocols(httpConf))
.maxDuration(testDuration)
}
Here is detailed Gatling console logs:-