Differences between revisions 4 and 5
Revision 4 as of 2009-09-20 23:02:02
Size: 3367
Editor: localhost
Comment: converted to 1.6 markup
Revision 5 as of 2013-04-15 13:01:44
Size: 3337
Comment: now really the last edit
Deletions are marked like this. Additions are marked like this.
Line 3: Line 3:
Line 5: Line 4:

[[http://jakarta.apache.org/jmeter/|JMeter]] is an open-source performance testing tool that is useful for stress-testing web applications. !JavaServer Faces presents interesting challenges with scripted testing because of the special request parameters needed and the requirement for POST requests. This document attempts to boil the requirements down in a simple fashion. 
[[http://jakarta.apache.org/jmeter/|JMeter]] is an open-source performance testing tool that is useful for stress-testing web applications. !JavaServer Faces presents interesting challenges with scripted testing because of the special request parameters needed and the requirement for POST requests. This document attempts to boil the requirements down in a simple fashion.
Line 11: Line 9:
To simulate the !ViewState parameter create a JMeter !RegEx Extractor. The best approach is to apply the extractor to the Thread Group so it applies across the whole test script. Use the following parameters:
||'''Reference Name''' ||jsfViewState ||
||'''Regular Expression''' ||{{{<input type="hidden" name="javax\.faces\.ViewState" id="javax\.faces\.ViewState" value="([^"]+)".*/>}}} ||
||'''Template''' ||$1$ ||
||'''Match No.''' ||0 ||
Line 12: Line 15:
To simulate the !ViewState parameter create a JMeter !RegEx Extractor. The best approach is to apply the extractor to the Thread Group so it applies across the whole test script. Use the following parameters:
Line 14: Line 16:
|| '''Reference Name''' || jsfViewState ||
|| '''Regular Expression''' || {{{<input type="hidden" name="javax\.faces\.ViewState" id="javax\.faces\.ViewState" value="(.+?)" />}}} ||
|| '''Template''' || $1$ ||
|| '''Match No.''' || 0 ||
Line 22: Line 21:
Line 26: Line 24:
Create an HTTP Request using the POST method for all JSF requests. Again, the best way to approach this is to record a session with the web application and change the dynamic variables. All JSF requests will have a few request parameters that need to be part of the request. All of these parameter names will start with the name of the form, then a "%3A", then the parameter name. For example if the form is named "myForm" you will see at least the following parameters:
||'''Parameter Name''' ||'''Parameter Value''' ||
||myForm%3A_SUBMIT ||1 ||
||myForm%3A_link_hidden_ ||(No value) ||
||myForm%3A_idcl ||Hard to script. Best to use the recorded value, but you can figure it out if you have to. ||
||javax.faces.!ViewState ||${jsfViewState} ||
Line 27: Line 31:
Create an HTTP Request using the POST method for all JSF requests. Again, the best way to approach this is to record a session with the web application and change the dynamic variables. All JSF requests will have a few request parameters that need to be part of the request. All of these parameter names will start with the name of the form, then a "%3A", then the parameter name. For example if the form is named "myForm" you will see at least the following parameters:
Line 29: Line 32:
|| '''Parameter Name''' || '''Parameter Value''' ||
|| myForm%3A_SUBMIT || 1 ||
|| myForm%3A_link_hidden_ || (No value) ||
|| myForm%3A_idcl || Hard to script. Best to use the recorded value, but you can figure it out if you have to. ||
|| javax.faces.!ViewState || ${jsfViewState} ||
Line 38: Line 37:
Line 41: Line 39:
For the rest of the values, try to use the already encoded id, eg:
use: myForm%3A_link_hidden_
and you should leave the "Encoded" checkbox off
For the rest of the values, try to use the already encoded id, eg: use: myForm%3A_link_hidden_ and you should leave the "Encoded" checkbox off
Line 45: Line 41:
You could also use the whole id, eg:
Use: myForm'':''link_hidden_
but if you do that, you must remember to mark the Encoded checkbox on JMeter

You could also use the whole id, eg: Use: myForm'':''link_hidden_ but if you do that, you must remember to mark the Encoded checkbox on JMeter
Line 52: Line 44:

Testing a JSF Application with JMeter

JMeter is an open-source performance testing tool that is useful for stress-testing web applications. JavaServer Faces presents interesting challenges with scripted testing because of the special request parameters needed and the requirement for POST requests. This document attempts to boil the requirements down in a simple fashion.

There are two main requirements to scripting a JSF application. First, you must simulate the JSF ViewState request parameter. Second, you must include all form elements in a POST request. The easiest way to create the initial script is to set up JMeter to record your request/response streams and use the scripts JMeter creates as a starting point.

ViewState Extractor

To simulate the ViewState parameter create a JMeter RegEx Extractor. The best approach is to apply the extractor to the Thread Group so it applies across the whole test script. Use the following parameters:

Reference Name

jsfViewState

Regular Expression

<input type="hidden" name="javax\.faces\.ViewState" id="javax\.faces\.ViewState" value="([^"]+)".*/>

Template

$1$

Match No.

0

This extractor will find the ViewState parameter and store it in a JMeter variable called jsfViewState so it can be passed down in future requests.

The First Request

The first request to most applications will be a GET request and will not contain any JSF information. Script this request as you would any initial request for a non-JSF web application.

Subsequent Requests

Create an HTTP Request using the POST method for all JSF requests. Again, the best way to approach this is to record a session with the web application and change the dynamic variables. All JSF requests will have a few request parameters that need to be part of the request. All of these parameter names will start with the name of the form, then a "%3A", then the parameter name. For example if the form is named "myForm" you will see at least the following parameters:

Parameter Name

Parameter Value

myForm%3A_SUBMIT

1

myForm%3A_link_hidden_

(No value)

myForm%3A_idcl

Hard to script. Best to use the recorded value, but you can figure it out if you have to.

javax.faces.ViewState

${jsfViewState}

In addition to the above "standard" variables you will need to add parameters in the same format for all form elements that are part of your request.

Some notes

For the extracted view, remember to check the "Encoded" box, otherwise the view will be sent as-is including special characters and it will not be restored in the server. This leads to unexpected behaviour, one of them is an _ErrorPageWriter.isText exception (as of myfaces 1.1.7), or a "view cannot be restored" message

For the rest of the values, try to use the already encoded id, eg: use: myForm%3A_link_hidden_ and you should leave the "Encoded" checkbox off

You could also use the whole id, eg: Use: myForm:link_hidden_ but if you do that, you must remember to mark the Encoded checkbox on JMeter

Alternative

You could also use the xPath extractor instead of the Regex for getting the view information

PerformanceTestingWithJMeter (last edited 2013-04-15 13:01:44 by AleksandarKostadinov)