Skip to main content

JMeter handling dynamic ViewState parameter in Seam framework

Testing applications built with Seam Java framework is possible with JMeter like any other web applications, though there are some nuances to take into account.

One of them is ViewState parameter. This parameter is dynamic and it means that we cannot just leave it hardcoded in our JMeter script because it will be broken the next time you try to execute it. Why this happens? Let's dig a little deeper. Black-box testing doesn't require us to know how Seam framework works, right? Okay, in this case we only need to know how it affects our tests.
As testers we need to make sure that ViewState parameter in the POST request has the same value as returned by a previous GET request. For example you have two subsequent requests:

  1. GET http://x.x.x.x:8080/some_page.seam
  2. POST http://x.x.x.x:8080/some_page.seam
The first request opens a page and the second one performs an action on the page (for instance - expands some tab, tree, etc).
If you analyze the response data with a listener you may notice ViewState parameter that is returned as part of a response to the first GET request (that opens the page):
...
<input type="hidden" name="javax.faces.ViewState" id="javax.faces.ViewState" value="j_id5" />
...
To make it work properly you should pass javax.faces.ViewState parameter value in the second request, and the value must be the same, j_id5 in our case.
But this is a dynamic parameter, so we cannot just pass j_id5 value every time, it will eventually change and our test will be broken. We need to parse it from the first request, store in a variable and then use it in the second request instead of hardcoded value. Let's see how we can do it.
At first we need to create JMeter user variable, let's call it VIEWSTATE.
Add -> Config Element -> User Defined Variables
Then we need to add Regular Expression Extractor as a child to the first request.
Add -> Post Processors -> Regular Expression Extractor

Regular expression would be: id=\"javax.faces.ViewState\" value=\"(.+?)\"
It will extract the value of javax.faces.ViewState parameter from the response data and assign it to VIEWSTATE variable.
Then we use this variable in the second request:

Now your JMeter tests can successfully cover applications built with Seam framework.

Popular posts from this blog

Integrating TestRail and Gitlab CI/CD

Perhaps you are using Gitlab CI/CD at your project. Every project requires some test cases for regression testing, and Gitlab actually provides this feature, but it’s only available in Ultimate version that is more expensive. TestRail is another popular platform for managing your test suite that provides way more extensive capabilities and options than Gitlab’s own test case management feature. So the chances are that you are still willing to use TestRail for your acceptance and regression testing efforts. Why not combining the best of two worlds — the flexibility of Gitlab CI/CD and rich test case management capabilities of TestRail? In the following example I’ll demonstrate how this goal could be achieved with ease. Let’s assume that we need to create a new Milestone in TestRail that contains two test runs — the one with Acceptance tests, and another one with Regression tests. The step in your .gitlab-ci.yml Gitlab configuration file would look like this: This step is reading CI

Switching between keyboard layouts in Openbox (Arch Linux)

Switching between two (or more) keyboard layouts in Openbox DE is a task that's quite easy to accomplish, although it might not be so obvious as in other desktop environments. This solution was tested on Arch Linux. You just need to edit this file (assuming you want to switch between English and Ukrainian Phonetic layouts with Alt-Shift): /etc/X11/xorg.conf.d/01-keyboard-layout.conf Section "InputClass" Identifier "keyboard-layout" Driver "evdev" MatchIsKeyboard "yes" Option "XkbLayout" "us,ua(phonetic)" Option "XkbModel" "pc105" Option "XkbOptions" "grp:alt_shift_toggle" EndSection If you have Nvidia card, don't forget to edit /etc/X11/xorg.conf.d/20-nvidia.conf and change Driver from "kbd" to "evdev" in InputDevice section: Section "InputDevice" Identifier "Keyboard0" Driver "evdev" EndSection Y

Solution for com.jcraft.jsch.JSchException: reject HostKey problem on Ubuntu

Just a random investigation with a workaround. So trying to connect to SFTP server using jsch library, but getting a nasty com.jcraft.jsch.JSchException: reject HostKey exception. This host is already present in ~/.ssh/known_hosts file, so it should not be problem, but it is. It turns out this problem happens if SFTP server is running on Ubuntu and strictHostKey is set to true, but it doesn't happen on Linux Fedora. I suppose this is because host entries in the known_hosts file on Ubuntu are encrypted in a different way than in known_hosts on Fedora, so it cannot be recognized or decrypted by JSch library. Now all you need to do is manually add host entries to the file. Basically you just get the public key for the host where SFTP server is running using this command: ssh-keyscan -t rsa sftp_server_ip_address_or_hostname Then copy-paste the output to your local ~/.ssh/known_hosts file. That's all, it should work now. If it doesn't, try to empty known_hosts file complet