Become a JMeter and Continuous Testing Pro

Start Learning

Test Your Website Performance NOW! |

arrowPlease enter a URL with http(s)
May 02 2017

Getting Started: Scripting with JMeter

Mayday, mayday! Is that how you feel when looking over JMeter? No worries. We wrote the following blog post on a particular May day (see how I did that?), we'll get you through your first JMeter script creation.


Apache JMeter is a great tool for doing performance testing of web-applications, but it may seem a tad bit tricky when looking it over for the first time. In this post we'll show you how to create your first Jmeter script from scratch.


First you need to download Jmeter from the official Apache JMeter site. Unzip the distribution and copy it to any folder you like. Note that you need to have JRE 1.8 ("Java 8") or above to run Jmeter, because it's written in pure JAVA. 

Go to $JMETER_HOME/bin and run jmeter.bat, if you are WINDOWS-user or JMeter, if you're *nix user.

The JMeter window has the following view:


JMeter view - test plan

The Test Plan, is the core element of the test script.


Look at the picture. Here we have two tables and three check-boxes. The first table, User Defined Variables, allows us to set variables, which can be used in any other part of script, and this can be a great time saver when you move between testing environments and need to correct the Host IP (which happens a lot).


In this case you can simply set up this value as a variable and that's it: no problems with updating the script.


The second table is used, when, for example, you are going to create test-plan for databases and you need to make the JDBC driver visible for JMeter to get the SQL queries executed. In this case you need to add JDBC *.jar to this table, and JMeter will pick it up.      


A few comments about check boxes:


learn JMeter easily, JMeter guide, JMeter tutorial


Run Thread Groups consecutively. 

If this option is checked, than all Thread Groups will be executed one by one. This may be useful in cases such as if the first Thread Group prepares test-data for a test, and the next one uses this set.

Run tearDown Thread Groups. 

Some actions, like restoring the system after testing to a default state may be assigned to tearDownThreadGroups. We'll talk about them little bit later.

Any JMeter test-plan should contain at least one Thread Group, which would then be the parent element for any test element (except Test Plan and Listeners). So, it will be the first element that we'll add to our test plan.


JMeter thread groups


The first element we'll add to the Thread Group is the HTTP Request Defaults.


To quote, “this element lets you set default values that your HTTP Request controllers use. For example, if you are creating a Test Plan with 25 HTTP Request controllers and all of the requests are being sent to the same server, you could add a single HTTP Request Defaults element with the "Server Name or IP" field filled in. Then, when you add the 25 HTTP Request controllers, leave the "Server Name or IP" field empty. The controllers will inherit this field value from the HTTP Request Defaults element.”


In our example we are going to use the same URL for all requests. That's why this element, obviously, will be helpful for us. Let's add the site that we will stress test.


Learning JMeter, how to use the HTTP Request defaults, how to build your script

In general, JMeter works as browser-simulator. And to make this simulation more realistic, it has elements which can work with cookies and cache.  These elements are HTTP Cookie Manager and HTTP Cache Manager.
learn to use JMeter elements. Read about the HTTP Cache Manager and HTTP Cookie Manager
HTTP Cookie Manager.

This element is used for emulating browser's work with cookies. 


HTTP Cache Manager.

This element is used for saving downloaded pages in cache during the first request, so they could be returned to Listener without downloading. This approach, obviously, has influence on test results.

One more important detail. Users never click links one by one, without any delay. Usually, there is a delay of seconds between thoughts, deciding whether to go or not to certain URL. That's why we need to emulate user think-time. 

JMeter has a set of Timers, which allows users to set up a pause between different requests. In this example we will add Constant Timer to generate the delay for the fixed amount of time.


Leran JMeter Scripting. Guide to JMeter Timers

The last element we need is the View Results Tree. 
JMeter View Results Tree - Learn how

Note, that this element is only needed during debugging tests. In general, View Results Tree is regards to memory consumption because it stores in memory all the results of requests. Obviously, if we use this element while we have many virtual users, we'll run out of memory and get a OutofMemoryException.


So remove or disable the View Results Tree (and wile you're at it,  all other graphic listeners) before running your test.


Running a Load Test with BlazeMeter


Well, we've created script. And, we're ready to run it in the cloud.


Assuming you already have your BlazeMeter account set up (if not, Sign up for free), you can simply click “Create Test”.


Run your JMeter script

After that, choose "JMeter Test".
Scale your JMeter test
Then upload your JMX file.
JMeter in the cloud
Give your test a name, configure (if needed) the test plan settings using the controls on the right side of the page. Click 'Save'. Go to 'Tests' and 'Run' your test.


Testing results will be available at the 'Reports' tab.


Performance testing results


Well done. Any questions???


Learn more JMeter for free from our JMeter academy.


To try out BlazeMeter, which enhances JMeter abilities, request a demo, or put your URL in the box below and your test will start in minutes.


arrowPlease enter a URL with http(s)

Interested in writing for our Blog?Send us a pitch!