Gatling and JSF viewState

718 views
Skip to first unread message

Rafael Pestano

unread,
May 14, 2015, 3:17:33 PM5/14/15
to gat...@googlegroups.com
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" 



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. 


Stéphane LANDELLE

unread,
May 14, 2015, 3:52:16 PM5/14/15
to gat...@googlegroups.com
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).

Stéphane Landelle
Lead developer


--
You received this message because you are subscribed to the Google Groups "Gatling User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to gatling+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Rafael Pestano

unread,
May 14, 2015, 5:10:21 PM5/14/15
to gat...@googlegroups.com
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:

<update id="j_id1:javax.faces.ViewState:0"><![CDATA[-1648281269875901741:4017909102611689881]]></update>


thanks again!

Stéphane LANDELLE

unread,
May 14, 2015, 5:18:57 PM5/14/15
to gat...@googlegroups.com
Hi Rafael,

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:

<update id="j_id1:javax.faces.ViewState:0"><![CDATA[-1648281269875901741:4017909102611689881]]></update>

Interesting. Is this format vendor specific (like PrimeFaces would be different from RichFaces?) or is it specified in the JSR?
Would it be possible for you to provide a Pull Request for this?
I can't say I'm into JSF at the moment...


Cheers

Rafael Pestano

unread,
May 14, 2015, 7:38:01 PM5/14/15
to gat...@googlegroups.com
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.

Rafael Pestano

unread,
May 14, 2015, 11:32:04 PM5/14/15
to gat...@googlegroups.com
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.

Stéphane LANDELLE

unread,
May 15, 2015, 6:20:23 AM5/15/15
to gat...@googlegroups.com

Stéphane Landelle
Lead developer


Rafael Pestano

unread,
May 15, 2015, 7:10:11 AM5/15/15
to gat...@googlegroups.com
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! 

Rafael Pestano

unread,
May 15, 2015, 7:33:33 PM5/15/15
to gat...@googlegroups.com
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.
Reply all
Reply to author
Forward
0 new messages