Handling JSF

Handling Jakarta Server Faces with Gatling DSL

Basic JSF

JSF requires a parameter named javax.faces.ViewState to be captured on every page and be passed in every POST request.

Adding a check for capturing the value and a param on very request would be very cumbersome. Hopefully, we can factor out these operations.

Define factory methods for building JSF requests that would automatically perform those operations:

import io.gatling.core.session.Expression

val jsfViewStateCheck = css("input[name='javax.faces.ViewState']", "value")
  .saveAs("viewState")

val jsfPartialViewStateCheck = xpath("//update[contains(@id,'ViewState')]")
  .saveAs("viewState")

def jsfGet(name: String, url: Expression[String]) =
  http(name)
    .get(url)
    .check(jsfViewStateCheck)
def jsfPost(name: String, url: Expression[String]) =
  http(name)
    .post(url)
    .formParam("javax.faces.ViewState", "${viewState}")
    .check(jsfViewStateCheck)
def jsfPartialPost(name: String, url: Expression[String]) =
  http(name)
    .post(url)
    .header("Faces-Request", "partial/ajax")
    .formParam("javax.faces.partial.ajax", "true")
    .formParam("javax.faces.ViewState", "${viewState}")
    .check(jsfPartialViewStateCheck)

You can then build your requests just like you’re used to:

val scn = scenario("Scenario Name")
  .exec(jsfGet("request_1", "/showcase-labs/ui/pprUpdate.jsf"))
  .pause(80.milliseconds)
  .exec(
    jsfPost("request_2", "/showcase-labs/ui/pprUpdate.jsf")
      .formParam("javax.faces.partial.ajax", "true")
      .formParam("javax.faces.source", "form:btn")
      .formParam("javax.faces.partial.execute", "@all")
      .formParam("javax.faces.partial.render", "form:display")
      .formParam("form:btn", "form:btn")
      .formParam("form", "form")
      .formParam("form:name", "foo")
  )

See Rafael Pestano’s demo project for a complete sample.

Trinidad

Trinidad’s _afPfm query parameter can be handled similarly:

val jsfPageFlowCheck = regex("""\?_afPfm=([^"]*)"""").saveAs("afPfm")
val jsfViewStateCheck = regex("""="javax.faces.ViewState" value="([^"]*)"""")
  .saveAs("viewState")

def jsfGet(name: String, url: Expression[String]) =
  http(name)
    .get(url)
    .check(jsfViewStateCheck)
def jsfPost(name: String, url: Expression[String]) =
  http(name)
    .post(url)
    .formParam("javax.faces.ViewState", "${viewState}")
    .check(jsfViewStateCheck)
    .check(jsfPageFlowCheck)

def trinidadPost(name: String, url: Expression[String]) =
  http(name)
    .post(url)
    .formParam("javax.faces.ViewState", "${viewState}")
    .queryParam("_afPfm", "${afPfm}")
    .check(jsfViewStateCheck)
    .check(jsfPageFlowCheck)
def trinidadDownload(name: String, url: Expression[String]) =
  http(name)
    .post(url)
    .formParam("javax.faces.ViewState", "${viewState}")
    .queryParam("_afPfm", "${afPfm}")

Edit this page on GitHub