No Attribute named "authToken" is defined - parameter properly passed though

I am capturing auth token as part of first request and trying to use it in the second, but getting the same error “failed to execute: No attribute named ‘authToken’ is defined”. Can someone tell me what am i doing wrong? Because in the execution results, i can see authToken being captured in the session data.

`
package computerdatabase

import io.gatling.core.Predef._
import io.gatling.http.Predef._
import scala.concurrent.duration._

class Test1 extends Simulation {

val httpProtocol = http.baseUrl(“https://trustbroker.com”)
val httpProtocol_1 = http.baseUrl(“https://services.com”)

val header = Map(
“Content-Type” → “application/soap+xml;charset=UTF-8”,
“Connection” → “alive”,
“User-agent” → “Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:16.0) Gecko/20100101 Firefox/16.0”)

val header_1 = Map(
//“Authorization”->"${authToken}",
“actor”->“TEST”,
“log_token”->“LOG”,
“scope”->“read”,
“timestamp”->“123456789”
)

val layer7 = scenario(“getauth”).exec(http(“GetAuthToken”)
.post("/auth/oauth/v2/token")
.queryParam(“client_id” , “123abcndfhgj”)
.queryParam(“client_secret” , “khkdh188d868d68d68f68”)
.queryParam(“grant_type” , “clienttest”)
.asJson.check(status.is(200)).check(jsonPath("$.access_token").find.saveAs(“authToken”)))

val pl1 = scenario(“claim”).exec(http(“claims”)
.post("/v1.0/search")
.headers(header_1)
.header(“Authorization”,“bearer ${authToken}”)
.body(StringBody("""<?xml version="1.0" encoding="utf-8"?>

123456



20


“”")))

setUp(layer7.inject(rampUsers(1) during (1 seconds)).protocols(httpProtocol_1),
pl1.inject(nothingFor(10 seconds),
rampUsers(10) during (5 seconds)).protocols(httpProtocol))
}
`

Layer7 and p11 are in 2 different chains. So “authToken” captured in layer7 will not be visible in p11 requests. Combine these in 1 scenario and inject the requests.

Unfortunately, I can’t combine the two scenarios as I need to execute the second set of scenarios in parallel. Also, layer7 needs to be executed only one in the beginning and not for every single user.

If it is only once, one approach is to make a “curl” request to get authToken from shell script and pass it as system property to gatling test.

Then you can read in gatling test like this
val authToken = System.getProperty(“authToken”)

It’s hacky, but you can do this by storing the access token from layer7 in a scala variable and then setting it into the session in p11.

so have a var like…

var authToken=""

then in layer7 have a final exec to set the scala var…

`
.exec(session =>{
authToken = session(“authToken”).as[String]
session
}

`

then in p11 have an initial exec to put it in the session…

exec(session=>{ session.set("authToken", authToken) }

note that your call to layer7 will have to complete within the 10 seconds you’ve specified

Thank you, it worked!

Hi Santosh,
Can you please give a code example of curl request and way of setting access token.

Hi Vikram,
Can you please give a code example of the curl request you are making to get the authToken
Regards,
Sanket