如何在Gatling中将token_type和access_token从一个执行块传递到另一个?

时间:2019-02-19 23:27:00

标签: scala gatling scala-gatling

我试图生成访问令牌,然后将访问令牌从另一个执行函数的另一个执行函数专门传递给其余端点的Post方法的标头。加特林不断在下面抱怨 enter image description here

-> -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)
13:53:30.761 [ERROR] i.g.h.a.s.HttpRequestAction - 'httpRequest-5' failed to execute: No attribute named 'token_type' is defined
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)
13:53:30.761 [ERROR] i.g.h.a.s.HttpRequestAction - 'httpRequest-5' failed to execute: No attribute named 'token_type' is defined
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)
13:53:30.761 [ERROR] i.g.h.a.s.HttpRequestAction - 'httpRequest-5' failed to execute: No attribute named 'token_type' is defined
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)
13:53:30.763 [ERROR] i.g.h.a.s.HttpRequestAction - 'httpRequest-5' failed to execute: No attribute named 'token_type' is defined

我定义了token_type如下。

如何解决“未定义名为'token_type'的属性”的错误?

package simulations

import baseConfig.BaseSimulation
import io.gatling.core.Predef._
import io.gatling.core.session
import io.gatling.http.Predef._

import scala.concurrent.duration.DurationInt
import scala.util.Random

class ogrebattledriverPostAccessToken extends BaseSimulation {

  val usersDataSource=jsonFile("input-post.json").circular

   exec(
      http("HTTP Request auth")
        .post("https://api.platform.com/auth/oauth/token")
        .header("Content-Type","application/x-www-form-urlencoded")
        .formParam("grant_type","password")
        .formParam("username", "TableTopEng%40xxxs.com")
        .formParam("password", "fJC2RuVdHB")
        .check(status is 200)
        .check(jsonPath("$.access_token").saveAs("access_token"))
        .check(jsonPath("$.token_type").saveAs("token_type"))
    )


  //val PostData=jsonFile("input-json.json").circular
  def name() = Random.nextInt(Integer.MAX_VALUE).toString



   //val headers_10 = Map("Content-Type" -> """application/json""","Authorization","${token_type} + ${access_token}" )


  def getSpecificOgreID()={
    repeat(140000){
      exec(flushHttpCache)

        feed(usersDataSource)
        .exec(http("PostRequestPerformanceTestingBattleDriver")
          .post("https://api.cloud/dev/battledriver/Organizations")
         // .headers(headers_10)
          .header("Authorization", "${token_type} + ${access_token}")
          .body(StringBody(session =>
            s"""
               |{
               |  "name": "${name()}",
               |  "latitude": 66.256538,
               |  "longitude": -95.934502,
               |  "phoneNumber": "555-555-5555",
               |  "emailAddress": "perftest1@perftest1.com",
               |  "website": "https://perftest1",
               |  "streetLine1": "123 perftest1.",
               |  "streetLine2": "Ste 400",
               |  "city": "Omaha",
               |  "state": "NE",
               |  "zipCode": "98002"
               |}
          """.stripMargin)).asJSON

          .check(status.in(200,201))//checkforaspecificstatus
          .check(jsonPath(path="$.name").saveAs(key="name")))//checkforaspecificstatus
        .exec{session=>println(session);session}//parameterfortheorgIdgoeshere
        .pause(1)

    }
  }

  // add a scenario
  val scn = scenario("Battle Driver Get Orgs ")

    .forever() { // add in the forever() method - users now loop forever
      exec(getSpecificOgreID())
    }



  // setup the load profile
  // example command line: ./gradlew gatlingRun-simulations.RuntimeParameters -DUSERS=10 -DRAMP_DURATION=5 -DDURATION=30
  setUp(
    scn.inject(
      nothingFor(5 seconds),
      rampUsers(900) over (2))
  )
    .protocols(httpConf)
    .maxDuration( 20)
}

我需要生成访问令牌并将其传递给exec函数,我该如何实现

0 个答案:

没有答案