Skip to content

Instantly share code, notes, and snippets.

@neilghosh
Created August 19, 2014 05:11
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save neilghosh/7f1ef88e45c44791210f to your computer and use it in GitHub Desktop.
Save neilghosh/7f1ef88e45c44791210f to your computer and use it in GitHub Desktop.
Gatling Test 1
package computerdatabase
import io.gatling.core.Predef._
import io.gatling.http.Predef._
import scala.concurrent.duration._
import io.gatling.jsonpath._
class Test1 extends Simulation {
val httpConf = http
.baseURL("http://demo1263864.mockable.io/") // Here is the root for all relative URLs
.acceptHeader("application/json") // Here are the common headers
.doNotTrackHeader("1")
.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 headers_10 = Map("Content-Type" -> "application/json") // Note the headers specific to a given request
val scn = scenario("Scenario Name") // A scenario is a chain of requests and pauses
.exec(http("Request_10")
.get("gatling1")
.headers(headers_10)
.check(jsonPath("$.result").is("SUCCESS")
,jsonPath("$.data[*]").findAll.saveAs("pList")))
.foreach("${pList}", "player") {
exec(session => {
val playerId = JsonPath.query("$.playerId", "${player}")
session.set("playerId", playerId)
})
.exec(http("Request_10")
.post("endPoint")
.headers(headers_10)
.body(StringBody("""{"playerId":"${playerId}"}""")).asJSON
.check(jsonPath("$.result").is("SUCCESS")))
}
setUp(scn.inject(atOnceUsers(1)).protocols(httpConf))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment