Created
August 16, 2016 14:04
-
-
Save alanphil/52d03338ba85c9ee0bd894b73ee3f999 to your computer and use it in GitHub Desktop.
Gatling login example and showing how to pull out the HTTP authorization header into a variable
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package test | |
import scala.concurrent.duration._ | |
import io.gatling.core.Predef._ | |
import io.gatling.http.Predef._ | |
import io.gatling.jdbc.Predef._ | |
class LoginTest extends Simulation { | |
val sessionHeaders = Map("Authorization" -> "Bearer ${authToken}", | |
"Content-Type" -> "application/json") | |
val httpProtocol = http | |
.baseURL("http://xx.xx.xx.xx:3000") | |
val scn = scenario("login_test") | |
// LogIn | |
.exec(http("login") | |
.post("/api/login") | |
.formParam("organization_id", "4666") | |
.formParam("email", "[email protected]") | |
.formParam("password", "put_password_here") | |
.check(jsonPath("$..token").exists.saveAs("authToken")) | |
) | |
.exec(http("get_alerts") | |
.get("/api/alerts") | |
.headers(sessionHeaders) | |
) | |
.exec(http("create_widget") | |
.post("/api/widgets") | |
.headers(sessionHeaders) | |
.body(StringBody("""{"description":"This is just a sample description.","name":"Junk"}""")) | |
.check(jsonPath("$..id").exists.saveAs("newWidgetId")) | |
) | |
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
Thanks alot man!