-
-
Save alanphil/52d03338ba85c9ee0bd894b73ee3f999 to your computer and use it in GitHub Desktop.
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) | |
} |
This is exactly what I wanted to do, thanks a lot!
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
.body(StringBody("{\"password\":\"ugly898p\",\"username\":\"x019785\",\"options\":{\"warnBeforePasswordExpired\":true,\"multiOptionalFactorEnroll\":true},\"stateToken\":\"00P8sbB2MC-fuCv4FzfZVMvM7QJlwHYfOsiL1DtuOZ"\"}"))))
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.
Thank you! This was very useful
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.
Thanks alot man!
Thanks,
A very useful example for beginner Gatling users!