I am trying to generate and then pass access token from one exec fundtion other exec function specifically to Header of a Post method of rest end point.Gatling keeps complaining below
1. -> -105.870087, c0c09f5d-6575-4964-a736-8ea2ceab2e8a -> 0, streetLine1 -> 123 Example Ln., b9598023-df1b-4ba3-bc8e-c0061b466e06 -> 12, streetLine2 -> Ste 400),1550613197846,20,KO,List(ExitOnCompleteLoopBlock(b9598023-df1b-4ba3-bc8e-c0061b466e06), ExitOnCompleteLoopBlock(c0c09f5d-6575-4964-a736-8ea2ceab2e8a)),io.gatling.core.protocol.ProtocolComponentsRegistry$$Lambda$397/2037202079@4d4062c9)
1. 13:53:30.761 [ERROR] i.g.h.a.s.HttpRequestAction - 'httpRequest-5' failed to execute: No attribute named 'token_type' is defined
1. Session(Ogre Battle Driver Get Orgs ,296,Map(website -> https://perftest8.com, city -> New Jersey, name -> Perf Test8, phoneNumber -> 555-555-5555, latitude -> 40.058323, gatling.http.cache.dns -> io.gatling.http.resolver.ShuffleJdkNameResolver@42408835, state -> New Jersey, emailAddress -> perftest8@perftest5.com, zipCode -> 980047, longitude -> -74.405663, c0c09f5d-6575-4964-a736-8ea2ceab2e8a -> 0, streetLine1 -> 123 Example Ln., b9598023-df1b-4ba3-bc8e-c0061b466e06 -> 12, streetLine2 -> Ste 400),1550613197893,20,KO,List(ExitOnCompleteLoopBlock(b9598023-df1b-4ba3-bc8e-c0061b466e06), ExitOnCompleteLoopBlock(c0c09f5d-6575-4964-a736-8ea2ceab2e8a)),io.gatling.core.protocol.ProtocolComponentsRegistry$$Lambda$397/2037202079@4d4062c9)
1. 13:53:30.761 [ERROR] i.g.h.a.s.HttpRequestAction - 'httpRequest-5' failed to execute: No attribute named 'token_type' is defined
1. Session(Ogre Battle Driver Get Orgs ,229,Map(website -> https://perftest9.com, city -> Massachusets, name -> Perf Test9, phoneNumber -> 555-555-5555, latitude -> -34.875961, gatling.http.cache.dns -> io.gatling.http.resolver.ShuffleJdkNameResolver@4f119156, state -> Massachusets, emailAddress -> perftest9@perftest5.com, zipCode -> 980047, longitude -> -58.049469, c0c09f5d-6575-4964-a736-8ea2ceab2e8a -> 0, streetLine1 -> 123 Example Ln., b9598023-df1b-4ba3-bc8e-c0061b466e06 -> 12, streetLine2 -> Ste 400),1550613197815,18,KO,List(ExitOnCompleteLoopBlock(b9598023-df1b-4ba3-bc8e-c0061b466e06), ExitOnCompleteLoopBlock(c0c09f5d-6575-4964-a736-8ea2ceab2e8a)),io.gatling.core.protocol.ProtocolComponentsRegistry$$Lambda$397/2037202079@4d4062c9)
1. 13:53:30.761 [ERROR] i.g.h.a.s.HttpRequestAction - 'httpRequest-5' failed to execute: No attribute named 'token_type' is defined
1. Session(Ogre Battle Driver Get Orgs ,315,Map(website -> https://perftest10.com, city -> London, name -> Perf Test10, phoneNumber -> 555-555-5555, latitude -> 51.507351, gatling.http.cache.dns -> io.gatling.http.resolver.ShuffleJdkNameResolver@2cd6884d, state -> London, emailAddress -> perftest10@perftest5.com, zipCode -> 980047, longitude -> -0.127758, c0c09f5d-6575-4964-a736-8ea2ceab2e8a -> 0, streetLine1 -> 123 Example Ln., b9598023-df1b-4ba3-bc8e-c0061b466e06 -> 12, streetLine2 -> Ste 400),1550613197914,23,KO,List(ExitOnCompleteLoopBlock(b9598023-df1b-4ba3-bc8e-c0061b466e06), ExitOnCompleteLoopBlock(c0c09f5d-6575-4964-a736-8ea2ceab2e8a)),io.gatling.core.protocol.ProtocolComponentsRegistry$$Lambda$397/2037202079@4d4062c9)
1. 13:53:30.763 [ERROR] i.g.h.a.s.HttpRequestAction - 'httpRequest-5' failed to execute: No attribute named 'token_type' is defined
Whereas i have defined token_type as below.
How do i fix this error “No attribute named ‘token_type’ is defined”?
1. package simulations
1.
1. import baseConfig.BaseSimulation
1. import io.gatling.core.Predef._
1. import io.gatling.core.session
1. import io.gatling.http.Predef._
1.
1. import scala.concurrent.duration.DurationInt
1. import scala.util.Random
1.
1. class ogrebattledriverPostAccessToken extends BaseSimulation {
1.
1. val usersDataSource=jsonFile("input-post.json").circular
1.
1. exec(
1. http("HTTP Request auth")
1. .post("https://api.platform.com/auth/oauth/token")
1. .header("Content-Type","application/x-www-form-urlencoded")
1. .formParam("grant_type","password")
1. .formParam("username", "TableTopEng%40xxxs.com")
1. .formParam("password", "fJC2RuVdHB")
1. .check(status is 200)
1. .check(jsonPath("$.access_token").saveAs("access_token"))
1. .check(jsonPath("$.token_type").saveAs("token_type"))
1. )
1.
1.
1. //val PostData=jsonFile("input-json.json").circular
1. def name() = Random.nextInt(Integer.MAX_VALUE).toString
1.
1.
1.
1. //val headers_10 = Map("Content-Type" -> """application/json""","Authorization","${token_type} + ${access_token}" )
1.
1.
1. def getSpecificOgreID()={
1. repeat(140000){
1. exec(flushHttpCache)
1.
1. feed(usersDataSource)
1. .exec(http("PostRequestPerformanceTestingOgreBattleDriver")
1. .post("https://api.battledriver/Organizations")
1. // .headers(headers_10)
1. .header("Authorization", "${token_type} + ${access_token}")
1. .body(StringBody(session =>
1. s"""
1. |{
1. | "name": "${name()}",
1. | "latitude": 66.256538,
1. | "longitude": -95.934502,
1. | "phoneNumber": "555-555-5555",
1. | "emailAddress": "perftest1@perftest1.com",
1. | "website": "https://perftest1",
1. | "streetLine1": "123 perftest1.",
1. | "streetLine2": "Ste 400",
1. | "city": "Omaha",
1. | "state": "NE",
1. | "zipCode": "98002"
1. |}
1. """.stripMargin)).asJSON
1.
1. .check(status.in(200,201))//checkforaspecificstatus
1. .check(jsonPath(path="$.name").saveAs(key="name")))//checkforaspecificstatus
1. .exec{session=>println(session);session}//parameterfortheorgIdgoeshere
1. .pause(1)
1.
1. }
1. }
1.
1. // add a scenario
1. val scn = scenario("Battle Driver Get Orgs ")
1.
1. .forever() { // add in the forever() method - users now loop forever
1. exec(getSpecificOgreID())
1. }
1.
1.
1.
1. // setup the load profile
1. // example command line: ./gradlew gatlingRun-simulations.RuntimeParameters -DUSERS=10 -DRAMP_DURATION=5 -DDURATION=30
1. setUp(
1. scn.inject(
1. nothingFor(5 seconds),
1. rampUsers(900) over (2))
1. )
1. .protocols(httpConf)
1. .maxDuration( 20)
1. }