Load Testing ForgeRock's AM Login Form Using Gatling

In this example, we are going to use Gatling to send a form request to simulate Forgerock’s Access Management login.

This sample project is built using Gatling with Scala and Gradle build tool.

In a previous article, we also saw how to do Oauth2 Authentication with Gatling.

Pre-requisite:

To setup your Gatling project follow the steps defined in Performance Testing Framework with Gatling and Maven

Defining Parameters in Configuration

First we define our variables in the Configuration.scala object file under the config folder:

object Config {

  val ENV: String = System.getProperty("ENV")
  val AM_ADMIN_PWD: String = System.getProperty("ADMIN_PWD")
  val CLIENT_SECRET: String = System.getProperty("CLIENT_SECRET")
  val AM_ADMIN_LOGIN_URL: String = ENV+"/am/oauth2/realms/root/access_token"

}

Requests

In the login request, we are submitting a form using formParam to simulate the Forgerock’s Access Management login form.

import io.devqa.config.Config.{AM_ADMIN_LOGIN_URL, AM_ADMIN_PWD, CLIENT_SECRET}
import io.gatling.core.Predef._
import io.gatling.http.Predef._

object AdminLogin {

  val login = exec(http("Login as admin and save access token")
    .post(AM_ADMIN_LOGIN_URL)
    .header("Content-type", "application/x-www-form-urlencoded")
    .formParam("grant_type", "password")
    .formParam("client_id", "YOUR_CLIENT_ID")
    .formParam("client_secret", s"${CLIENT_SECRET}")
    .formParam("scope", "*")
    .formParam("username", "amadmin")
    .formParam("password", s"${AM_ADMIN_PWD}")
    .check(status.is(200))
    .check(jsonPath("$.access_token").saveAs("access_token"))
  )

}

In the above code snippet, we are saving the access_token to the session.

Scenario

Next, we will use the scenario to call the login request:

import io.devqa.requests.AdminLogin
import io.gatling.core.Predef.scenario

object LoginScenarios {

  val adminLoginScenario = scenario("")
    .exec(AdminLogin.login)
}

Simulation

Finally our simulation file called LoginSimulation.scala is saved under the simulations folder.

import io.devqa.scenarios.LoginScenarios
import io.gatling.core.Predef._

import scala.concurrent.duration.DurationInt
import scala.language.postfixOps

class LoginSimulation extends Simulation {

  setUp(
    LoginScenarios.adminLoginScenario.inject(
      nothingFor(3),
      constantUsersPerSec(1) during(60 second))
  )
}

You can then play around with different numbers for users and duration to simulate desired load.