Skip to content

Instantly share code, notes, and snippets.

@ztolley
Created September 9, 2015 21:01
Show Gist options
  • Save ztolley/d89ea641f9e772ddf4a4 to your computer and use it in GitHub Desktop.
Save ztolley/d89ea641f9e772ddf4a4 to your computer and use it in GitHub Desktop.
How to use cross site tokens in gatling
package com.scropt
import scala.concurrent.duration._
import io.gatling.core.Predef._
import io.gatling.http.Predef._
import io.gatling.jdbc.Predef._
class LoginAndAddDecision extends Simulation {
val httpProtocol = http
.baseURL("https://opg.scropt.com")
.inferHtmlResources()
val uri1 = "https://opg.scropt.com:443"
val scn = scenario("LoginAndAddDecision")
.exec(http("request_0")
.get("/login"))
.check(
regex("""<input name="login[_token]" type="hidden" value="([^"]*)" />""")
.saveAs("loginToken")))
.pause(6)
.exec(http("request_1")
.post("/login")
.formParam("login[email]", "laydeputy@publicguardian.gsi.gov.uk")
.formParam("login[password]", "PDEtnLay1234")
.formParam("login[login]", "")
.formParam("login[_token]", "${loginToken}"))
.pause(3)
.exec(http("request_2")
.get("/report/1/decisions"))
.pause(2)
.exec(http("request_3")
.get("/report/1/decisions/add"))
.check(
regex("""<input name="login[_token]" type="hidden" value="([^"]*)" />""")
.saveAs("addDecisionToken")))
.pause(13)
.exec(http("request_4")
.post("/report/1/decisions/add")
.formParam("decision[description]", "Very important Stuff")
.formParam("decision[clientInvolvedBoolean]", "1")
.formParam("decision[clientInvolvedDetails]", "We talked")
.formParam("decision[save]", "")
.formParam("decision[_token]", "${addDecisionToken}"))
.pause(5)
.exec(http("request_5")
.get("/report/1/overview"))
setUp(scn.inject(atOnceUsers(1))).protocols(httpProtocol)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment