[FIXED] So übergeben oder erhalten Sie den Wert von Map (Zufallsgenerator) an PebbleStringBody in Gatling mit Scala

Ausgabe

So übergeben oder erhalten Sie den Wert von Map (Zufallsgenerator) an PebbleStringBody in Gatling mit Scala

  val names = Iterator.continually {
    Map("name" -> s"PerfTest ${Random.alphanumeric.take(10).mkString}")
  }

.feed(names)
    .exec(http("PerfTest")
      .post("/PerfTest/bulk")
      .body(PebbleStringBody(
       """| [
          |  {% set Iteratecount = 2 %}
          | {% for t in range(1,Iteratecount) %}
          |    {
          |   "name": "{{name}}",    //cannot get the value from feeder :Map or from Json path 
          |   "TestID": "9888988FRFRFDD887887ESES",
          |   "typeId": "9888988FRFRFDD887887ESES",
          |   "statusId": "9888988FRFRFDD887887ESES",
          |   "excludedFromAutoHyperlinking": true
          |    }
          |  {% if loop.last %}
          |  {% else %},{% endif %}
          |  {% endfor %}
          |  ]""".stripMargin)).asJson
      .check(status.is(200))
    )

konnte den Wert auch nicht von jsonPath an pebbleString body übergeben

.check(jsonPath("$.result.name").saveAs("name")

Bitte helfen Sie bei der Lösung

Lösung

Ich habe Ihr Beispiel (gegen google.com) mit aktivierter TRACE-Protokollierung mit Gatling 3.8.4 ausgeführt und es funktioniert einwandfrei:

class PebbleSimulation extends Simulation {

  val names = Iterator.continually {
    Map("name" -> s"PerfTest ${Random.alphanumeric.take(10).mkString}")
  }

  val httpProtocol =
    http.baseUrl("https://google.com")
      .acceptHeader("text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8")
      .acceptLanguageHeader("en-US,en;q=0.5")
      .acceptEncodingHeader("gzip, deflate")
      .userAgentHeader(
        "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:16.0) Gecko/20100101 Firefox/16.0"
      )

  val users = scenario("Users")
    .feed(names)
    .exec(http("PerfTest")
      .post("/PerfTest/bulk")
      .body(PebbleStringBody(
        """| [
           |  {% set Iteratecount = 2 %}
           | {% for t in range(1,Iteratecount) %}
           |    {
           |   "name": "{{name}}",    //cannot get the value from feeder :Map or from Json path
           |   "TestID": "9888988FRFRFDD887887ESES",
           |   "typeId": "9888988FRFRFDD887887ESES",
           |   "statusId": "9888988FRFRFDD887887ESES",
           |   "excludedFromAutoHyperlinking": true
           |    }
           |  {% if loop.last %}
           |  {% else %},{% endif %}
           |  {% endfor %}
           |  ]""".stripMargin)).asJson
      .check(status.is(200))
    )

  setUp(
    users.inject(atOnceUsers(1))
  ).protocols(httpProtocol)
}

HTTP request:
POST https://google.com/PerfTest/bulk
headers:
    content-type: application/json
    accept-language: en-US,en;q=0.5
    accept-encoding: gzip, deflate
    accept: application/json
    user-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:16.0) Gecko/20100101 Firefox/16.0
    host: google.com
    content-length: 564
body:StringRequestBody{charset=UTF-8, content= [
       {
   "name": "PerfTest mAQ6evSHPW",    //cannot get the value from feeder :Map or from Json path
   "TestID": "9888988FRFRFDD887887ESES",
   "typeId": "9888988FRFRFDD887887ESES",
   "statusId": "9888988FRFRFDD887887ESES",
   "excludedFromAutoHyperlinking": true
    }
  ,      {
   "name": "PerfTest mAQ6evSHPW",    //cannot get the value from feeder :Map or from Json path
   "TestID": "9888988FRFRFDD887887ESES",
   "typeId": "9888988FRFRFDD887887ESES",
   "statusId": "9888988FRFRFDD887887ESES",
   "excludedFromAutoHyperlinking": true
    }
        ]}

Entweder verwenden Sie eine alte fehlerhafte Version von Gatling oder Ihr Problem liegt woanders.


Beantwortet von –
Stéphane LANDELLE


Antwort geprüft von –
Katrina (FixError Volunteer)

0 Shares:
Leave a Reply

Your email address will not be published. Required fields are marked *

You May Also Like