Gatling and JSF viewState

Hi guys,

I’m trying to make a simple get request and save jsf viewState like described here: http://gatling.io/docs/2.0.0-RC2/cookbook/handling_jsf.html

but i’m receiving “regex(=“javax.faces.ViewState” value=”([^"]*)").find(0).exists 1 (100,0%)
, found nothing"

My simulation is pretty simple and all code can be found here: https://github.com/rmpestano/cdi-crud/blob/gatling-jsf-issue/src/test/scala/com/cdi/crud/perf/CdiCrudSimulation.scala

here is some code:

val httpProtocol = http
  .baseURL("http://localhost:8080/cdi-crud")
  .acceptHeader("text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8,application/json;charset=utf-8")
  .acceptEncodingHeader("gzip, deflate")
  .inferHtmlResources()
  .connection( """keep-alive""")
  .contentTypeHeader("*/*")
  .acceptLanguageHeader("pt-BR,pt;q=0.8,en-US;q=0.5,en;q=0.3")
  .userAgentHeader("Mozilla/5.0 (Windows NT 6.3; WOW64; rv:36.0) Gecko/20100101 Firefox/36.0")


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)

val loginScenario = scenario("login")
  .exec(
    jsfGet("saveState","/index.faces")
    .resources(http("request_resources").get( "/"))
   .check(status.is(200))
  )
  /*.exec(openDialogRequest)
  .pause(2)
  .exec(doLogonRequest)
  .pause(1)*/

setUp(
  loginScenario.inject( atOnceUsers(1) )
)
.protocols(httpProtocol)
  .assertions(
    global.successfulRequests.percent.greaterThan(95)
  )

and here is the error:

regex(=“javax.faces.ViewState” value="([^"]*)").find(0).exists 1 (100,0%)
, found nothing

full debug output can be fond here: http://pastebin.com/QCdAgTpx

its probably a detail,

any help is appreciated.

Did you check that your HTML indeed matches this regular expression?

Also, parsing HTML with a regular expression is definitively not convenient. You should try css selectors which is way more versatile (doesn’t break if you have an extra space, or a reverse order in name and value, etc).
http://gatling.io/docs/2.1.6/http/http_check.html#http-check-css

Hi Stephane,

thanks for your reply, css selector like css(“input[name=‘javax.faces.ViewState’]”) did the trick, maybe the docs should be updated?

also note that this selector will not work for partial request (header Faces-Request: partial/ajax)
which returns a partial response where viewState is like this:

thanks again!

Hi Rafael,

Hi Stephane,

Already done: https://github.com/gatling/gatling/issues/2720

that was fast, great!

Interesting. Is this format vendor specific (like PrimeFaces would be different from RichFaces?) or is it specified in the JSR?

Partial request is for dealing with ajax and is in the spec since JSF 2.0 (section 14.2.4 - Request Sending Specifics). In practice every time you use tag f:ajax execute=“some html component” or in primefaces with p:ajax process=“some component” will generate a JSF partial request and response.

Would it be possible for you to provide a Pull Request for this?

sure, I will work on some more JSF examples and then send the PR to update the docs.

Hi again,

I’ve just hacked a little bit and created a sample project which fires JSF requests here: https://github.com/rmpestano/gatling-jsf-demo

basically I’ve used two checkers, one for normal and another for partial requests:

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

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

both examples of partial and non partial requests can be found here: http://www.primefaces.org/showcase/ui/button/commandButton.xhtml and the demo
fires both kinds of requests at that primefaces showcase page.

The example is quite simple, the only gotcha is that it needs a first GET request save the viewState and also buttons and form ids (they are generated by jsf) that will be used in subsequent request.

Note that there are others scenarios to explore in the JSF land and the demo shows very simple but common cases.

I hope it helps.

Thanks Rafael.
I added a link to your sample project: https://github.com/gatling/gatling/commit/cb458c4a8de2bfed4d99bdd1e7d2f99db1e87948

Great! I plan to evolve the examples and if I find something useful I will share it here.

thanks and congratulation for the great work!

Just added an example of JSF ajax event (eg: fire ajax request on keyup). The idea is the same but for this case you need to add 2 additional form params:

.formParam("javax.faces.behavior.event", "keyup")
.formParam("javax.faces.partial.event", "keyup")

I’ve updated the project readme which shows this example: https://github.com/rmpestano/gatling-jsf-demo/#ajax-behaviour-event

I think there is no need to update Gatling docs as it is something a JSF developer must know.