How To Use JMeter Elements? - Loginworks Softwares Pvt. Ltd.
Home Quality Assurance How To Use JMeter Elements?
How To Use JMeter Elements?
Somethings that we may be concerned about when developing the website are: What will happen to the web server(s) in such severe load conditions when multiple users are going to access the system simultaneously?
Of course!! An application may get hanged.
Fortunately one does not need to get panicked with this situation as there is a software which can help us to deal with these issues and that is JMeter!
JMeter is the tool to measure a website's performance. Basically, this tool is developed for performance testing of web applications but in fact, it can do much more than that. It has a very complex architecture that provides support for several inbuilt elements and allows extending the functionality of JMeter through plugins. It has many elements like Samplers, Processors, Listeners etc. In simple terms, different types of Elements represent the different features provided by JMeter. Each Element is designed for a specific purpose.
If you want to check performance, you need a test plan.It narrates a series of test steps, which JMeter will execute and run. Test Plan is the root element of JMeter as shown in the above figure.Test Plan is also the biggest component in JMeter architecture and is at the top of the hierarchy.
There are one or many elements in a complete Test Plan such as Thread Group, Samplers, Listeners, Timers etc. Also, there is one point to be noted here: A Test Plan always has at least one Thread Group.
Thread Group is the most basic element starting point of any Test Plan. It is commonly referred as a collection of Threads. It controls all the threads that JMeter uses to execute the test cases. The controls for a thread group allow you to Set the number of threads for each group.
Each thread illustrates one user using the application under test. Above all, each Thread replicates one real user request to the server. For example, if you set the number of threads as 100; JMeter will create and simulate 100 user requests to the server under test.
Let's consider following scenario. During a promotional campaign, 100 real users connect concurrently to the server and use your web application. Each user will create a working session for that web application.
Number of Threads in Thread Group describes the replicate number of real users connected to the web server.
Set the duration(ramp-up period) within which all threads have to be run.
All controllers and samplers can only be added to a Thread Group and the other elements, like Listeners (which we cover later in this topic), can be added to a Test Plan or Thread Group. When they are added to a Test Plan in JMeter, they are associated with all the Thread Groups in the Test Plan. When controllers and samplers are added to a Thread Group, they apply only to that Thread Group.
JMeter has two types of Controllers: Samplers and Logical Controllers. Both the controllers drive the processing of the test.
In the Samplers section, we will discuss how JMeter creates a request to the server. But there is another need i.e. If we want to control those requests based on a logic such as setting the schedule to send that request, determine which request to be sent… etc. what should we do?
JMeter provides you with the element to do it. It is the Logic Controller.
A very interesting question you must have like how JMeter creates a request to the server or how does a Thread Group know which type of requests (HTTP, FTP etc.) it needs to make?
We will discuss these request on our next blog!!!
Earlier in the Samplers section, we discussed how JMeter creates a request to the server. The question is – If we want to control those requests based on a logic such as setting the schedule to send that request, determine which request to be sent and the order of processing Samplers/Requests in a Thread. … etc. what should you do?
JMeter provides you with the element to do it. It is the Logic Controller. Also Logic Controllers will decide "When & How" to send a request to a web server. Logic Controllers can change the order of requests coming from their child elements.
There are following common Logic Controllers. You can use appropriate Controller based on your specific requirement.
We will discuss Logic Controllers in detail on our next blog on.
The processor is used to modify the Samplers in their scope and customise the Samplers functionality. There are two types of processors in JMeter, PreProcessor and Post Processor.
Pre-processor tends to execute few actions before making Sampler Request. It will execute just prior to that sampler element running, if a Pre-Processor is attached to a Sampler element. A Pre-Processor is mostly used to alter the settings of a Sample Request just before it runs, or to update variables that aren't extracted from response text.
Post-processor tends to execute few actions after making Sampler Request. It will execute just after that sampler element runs, if a Post-Processor is attached to a Sampler element. A Post-Processor is mostly used to process the response data, often to extract values from it.
Config Elements in JMeter allow the user to change the request they create.A configuration element works closely with a Sampler. However it does not send requests, it can add to or alter requests.
A configuration element is accessible from only inside the tree branch where you place the element. For example, the Cookie Manager will only be accessible to HTTP Request Controllers you place inside the Simple Logic Controller, if you place an HTTP Cookie Manager inside a Simple Logic Controller.
An assertion in JMeter is used to validate response to the request, that you have sent to the server. Using an assertion, you can essentially "test" that your application is returning the results you expect it to. Assertions are statements that verify the test results as either positive or negative. Assertions in JMeter can be applied to many elements such as Test Plan, Thread Group or Samplers.
You can add an assertion to any Sampler. Let's take an example, In an HTTP Request, you can add an assertion that checks for the text, "</HTML>". JMeter is then obliged to check that the text is present in the HTTP response. This request will however be marked as fail, if JMeter is unable to find the text.
To view assertion results, add an Assertion Listener to the Thread Group. Failed Assertions will also be displayed in the Tree View and Table Listeners, and will count towards the error percentage for example in the Aggregate and Summary reports.
So far, we have seen how Samplers are used to create and send a request to the server to complete a performance test. Processors can be used to modify the request or the response. After creating and sending the request to the server, JMeter receives the results returned from the server. ….Listeners help users to access the server response and analyze the test results.
Graph result listeners display the server response times on a Graph.
View Result Tree show results of the user request in basic HTML format.
Table Result display summary of test results in table format.
Log display summary of the test results in the text file.
By default, a JMeter thread executes samplers in sequence without pausing. In that case, JMeter could overwhelm your test server by making too many requests in a short amount of times. Let imagine that you send thousands request to a web server under test in a few seconds. What will happen??
Therefore, you need to create a time delay between each request. JMeter offers elements called the Timer elements that you can use in such situations. The purpose of Timer elements is to pause a JMeter Thread representing a virtual user, for a definite amount of time. If you want to add more than one timer to a Thread Group, JMeter catch the sum of the timers and pauses for that amount of time before executing the samplers to which the timers apply. Timers can be added as children of samplers or controllers in order to restrict the samplers to which they are applied.
Constant Timer: Constant timer delays each user request for the same amount of time.
Uniform Random Timer: Uniform random timer delays each user request for a random amount of time.
Gaussian Random Timer: Gaussian random timer delays each user request for a random amount of time.
BeanShell Timer: The BeanShell Timer can be used to produce a delay time between each user request.
BSF Timer: In order to produce a delay between each user request with the help of BSF scripting language, BSF Timer can be used.
As a result, we can conclude that JMeter processes Samplers and Logic Controllers in the sequence that they appear in the Test Plan. Pre Processors, Post Processors, Assertions, and Timers are only processed if they are associated with a Sampler. Thus we have learned about all components or Elements of Jmeter.
Previous articleHow To Use UIAutomatorViewer To Inspect Elements For Mobile Automation?
Next articleManagement Roles And Responsibilities: What And How?
I have 3+ years of experience in Software Testing. I am working as Quality Analyst with Loginworks Softwares Pvt Ltd. Passionate to improve Software Quality.
How to develop Hybrid Mobile App using Cordova?