Wednesday 26 October 2016

Jmeter, IF controller checking empty variable using


Sometimes you need to add HTTP samplers with dynamic URL or with dynamic part of the URL which are stored in some variable after HTTP sampler post-processing.



But if Regular Expression Extractor will not find any matching string result variable will be set to default value (empty value in our case). We should test this variable for emptyness before we will use it.


Now if the News page has not any news we are sure that JMeter will handle this situation correctly.

HTTP Request sampler with dynamic URL in JMeter


If you need to add HTTP Request sampler with dynamic URL that can be different each time from testing to testing you must use one of the Post-Processors offered by JMeter. I usually use Regular Expression Extractor for this purposes.

So, let's imaging that you have "Popular News" web page which contains the links to "News Story" web pages that contains the full texts of news and you want to write a test which will include both "News" page and random "News Story" page.

For this you must include "News" page HTTP Request sampler inside Simple Controller with a Regular Expression Extractor to store random "News Story" page URL to a variable:


Then use the variable with the stored random "News Story" page URL in "News Story" HTTP sampler:

Jmeter performance testing of search functionality Testing website search

Almost every modern website has search feature and it must be carefully and thoroughly tested. You will know from this post how to do it using JMeter.

First record necessary HTTP requests (including search page and search results page) using JMeter's recording proxy and group them into separate transactions.


Then go to HTTP Request sampler which corresponds to search results page and replace the keyword (which you used during recording) with some variable name, e.g., ${KEYWORD}.


Then prepare the list of keywords you want to use for search testing, save them to the text file and add CSV Data Set Config element to Thread Group. Specify the name of just created file and the variable name which will contain your keywords from file, e.g., KEYWORD (see above).


Now you are ready to test the search on your website.

How to add cookie support to your Test Plan (Jmeter)



Performance Testing
If you want JMeter to handle cookies automatically you need to add HTTP Cookie Manager to Thread Group.

Be sure that Cookie Policy option is set to "compatibility" value, it will work in most cases. As for "Clear cookies each iteration?" checkbox I always check it and never had the situation when I was need it to be unchecked.
Cookie manger Jmeter
Cookie Manager

How to Use JMeter Properties


Sometimes I need to modify some parameters in the Test Plan and it requires me to start JMeter, open the Test Plan file and edit these parameters there. But it's better to use JMeter properties for this task. Look at the image below.


There are JMeter properties used as values of "Number of Threads (users)" and "Loop Count" options: ${__P(users)} and ${__P(count)}. Also we must add two parameters to JMeter command line:

jmeter -t TestPlan.jmx -Jusers=10 -Jcount=50

Now you can specify necessary parameters on the fly. I recommend you to use properties for the following options: number of users, loop count, host, port, results and data filenames, etc.