An Introduction to JMeter Part-2
Building your first script
Let us understand the following before creating our first script.
Thread groups:Thread groups are the fundamental thing that delivers loader or demands with jmeter gets the virtual users of perform the actions.
Samplers: The HTTP sampler request:samplers are which is an example of how load is delivered to a target,how the request has made we will see how http sampler request works.
Timers: Constant and uniform random: Timer are how you add delays to your test and make them more realistic.
Assertions: Response assertion:assertion help us to make sure right things are happening in your test which you validate the test is doing which you wanted it to do.
Listeners: View results Tree:Listeners is the most important which let you observe all of the task and actually listen to what is happening and watch what is happening during the test. We will use the view result tree for that.
Thread groups
Open the jmeter and right click on test plan and open thread group
On thread group menu see the thread properties you can add virtual users, which means how man users load test you want on the target server/application
Ramp up period is how long we want those user to come up with full speed. e.g. we set to 60 seconds which in 60 seconds the users will go from 0 to 100 users.
Loop count is to see how many time a user error rates in your test.
In the sampler option following options
Continue: keep the test running and ignore the errors.
Start Next Thread Loop: this option will stop on the error loop and move on the next loop
Stop Thread: it will stop the thread on error.
Stop Test: It will stop the test on error with gracefully which mean if any users on the flight of test it will allow them to complete and then stop the test.
Stop Now: Will stop the test forcefully no matter how many users are on the flight of the test.
Samplers: The HTTP sampler request
Right click on Thread Group click add > sampler > http request
In Web Server section you can see the following.
Server Name or IP: www.domain.com
You can put the IP address if you have it.
Port Number:
add the port number if it is other then 80.
Path:/
Path of the asset of the server on which you want to perform the test. For home page which just put slash /
Protocol [http]:
Add https if you are site is on SSL.
Method: Get
Get is used to get request
Post is used for login or etc, if you are using post you need to add parameters or body option for json.
For basic test we will use get.
Timers: Constant and uniform random
Right click on Http request and go to timer choose constant timer. It is simple only have one option.
Thread Delay (in milliseconds): 800
We can also set timer on the thread group as per your requirement.
Now we will add other type of timer which is uniform random timer, in here we need to set constant timer same as we set previously 800 and 200 on random delay which means on it will upto 2 seconds delay on top of 8 seconds.
We use this option to make the users not to act like robots and have some variability like real users in the real world.
Assertions: Response assertion
Right click on http request add > assertion and click on response assertion.
On response field you see following options
Text Response: is the response comes back from the server the html body. (this option is the most commonly used)
Document (text): is the special case which really meant for functional testing, when you examining the Microsoft office document for meta data or content
Url sampled: is the option on which url we want to hit.
Response code: receive request from the server in numbers like 200 for OK, 404 for not found, 500 for server error and etc.
Response message: this option receive the response message for e.g. for 200 it will receive OK.
Response headers: receive the header comes back with the page
Pattern Matching rules option has following options
Contains: is used regular expressions which matches something on the page.
Matches: is regular expression all you get back or exactly what you get.
Equals: is used for just playing with text and will get exactly what you type
Substring: is used for just playing with text and get some part of the text you want.
Not or Or: is used that you do not get pages which has message something like "something went wrong"
We will use subtring and add the word Welcome as shown in the image below.
We use patterns because sometime server deliver 200 ok response but the page/url is have errors, it make sure response is OK and have the pattern in it.
Listeners: View results Tree
Go to thread group and add a Listener View result
On the filename field is used to read from a existing result test file or write to a file.
We can configure what we want to keep track of.
Now go save your script and run it.
You will get the results in which you view how many threads runs, latency, load times, response headers and etc
In the next part we will learn variables, properties and functions.