Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Gatling login example and showing how to pull out the HTTP authorization header into a variable
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
val scn = scenario("login_test")
// LogIn
.formParam("organization_id", "4666")
.formParam("email", "")
.formParam("password", "put_password_here")
.body(StringBody("""{"description":"This is just a sample description.","name":"Junk"}"""))
Copy link

Itex commented Jul 22, 2018

A very useful example for beginner Gatling users!

Copy link

danilomo commented Sep 27, 2019

This is exactly what I wanted to do, thanks a lot!

Copy link

RandyJStevenson commented Feb 28, 2020

This is exactly what I am trying to do right now: Capture a stateToken and a SAMLResponse. Apparently, I am below a beginner, because I cannot understand the code provided. The .check(jsonPath("$..token").exists.saveAs("authToken")) code makes sense, but I cannot figure out where to insert it in my existing Scala code.

when I add the .check to my Scala, I get the error "cannot resolve symbol check"

And what is the "extra" parenthesis on the next line. It seems to be unmatched.

In my existing code I have this


The stateToken is already being provided in the login step, so I somehow need to capture it earlier.

I am taking a Gatling class on Udemy now, but since I have never written Json or Scala, I feel like I am reading Hindi.

Copy link

romecam16 commented Sep 8, 2021

Thank you! This was very useful

Copy link

rik12s commented Apr 6, 2022

Can you also show example where you hit the oAuth server to fetch the bearer token and then use this token to hit api from different server. Since I am beginner, sample usage will be really appreciated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment