1. Tell few benefits of JMeter over other performance tools or why did you select JMeter for performance testing?
- JMeter is open source software, easy to install on any desktop with windows, mac or Linux OS.
- It’s useful in testing the performance of both static and dynamic resources like files, Servlets, Perl scripts, Java Objects, Data Bases, Queries, FTP Servers and more
- JMeter can also perform various other types of testing like Functional, Regression, and Unit testing.
- It has the most user-friendly interface or can be easily used in a command-line interface
- It enables test recording for native applications and browsers
- JMeter can easily extract data from any data formats like HTML, JSON, XML or text-based formats into its system.
- It’s very easy to integrate the JMeter script with any build tool like Jenkins and with cloud.
- Like all the other open-source tools, JMeter has a highly active community on the web.
2. What all protocols supported by JMeter?
Following are some of the protocols supported by JMeter.
- Web Protocol: To test the web applications, it supports both HTTP and HTTPS protocols.
- Web Services: To test web services applications, it supports both SOAP and REST.
- FTP: File Transfer Protocol provides the support for testing the FTP servers and applications.
- Database via JDBC: used for testing the database applications.
- LDAP: Lightweight Directory Access Protocol
- Message-oriented middleware (MOM) via JMS
- Mail: used for testing of mail servers such as SMTP(S), POP3(S) and IMAP(S)
- Mongo DB (NoSQL): it is recently supported protocol by JMeter.
- Native commands or shell scripts
3. What is the execution order of Test Elements in Test Plan of JMeter?
Following is the order of execution of the Test Plan elements.
- Configuration elements
4. How do you ensure re-usability in your JMeter scripts?
- Using config elements like “CSV Data Set Config” and “User Defined Variables” for supporting greater data reuse.
- Modularizing the shared tasks and invoking them via a “Module Controller”.
- Creating own Bean Shell functions and reusing them.
5. What kind of Assertion you have used in JMeter?
Assertion helps to verify that the server under test returns the expected results. Some commonly used Assertion in JMeter are as follows.
- Response Assertion: It facilitates the user by comparing the server response against a string pattern to check that the result is as expected.
- Size Assertion: It is to test that each response coming from server holds the expected number of bytes.
- Duration Assertion: You may need to test the response from the server reaches in user-defined time. If it takes longer than the defined time, server response fails.
- XML Assertion: It verifies that the response coming from the server holds the data in a correct XML format.
- HTML Assertion: It is helpful for checking the syntax of the response data.
6. What is Spike testing and how can we perform it in JMeter? What is a Rendezvous Point?
Sometime you may have scenarios where all of sudden website traffic increases drastically during festivals/offer season (black Friday sale). This Sudden increase in the number of users at a certain point of application and then monitoring its behavior at that interval is Spike testing.
The Rendezvous point in JMeter is used to perform spike testing Spike testing can be performed using Synchronizing Timer. This timer keeps on blocking the threads until a particular number of threads get reserved. It then releases them at once thus creating large instantaneous load.
7. How did you use JMeter Pre and Post processor in your project?
Pre-processor executes some action before making a Sampler Request i.e. they get executed before a sampler is executed.
Example: adding “Sample Timeout” preprocessor with an HTTP Request so that this request would run for only defined amount of time. Below are some of the Pre-Processor used in JMeter:
- Bean Shell Pre-Processor
- HTML Link Parser
- HTTP URL Re-Writing
- JDBC Preprocessor
- Sample Timeout
- User Parameters
Post-processor executes some action after making a Sampler Request i.e. Post-Processors are actions that are performed after your sampler has been executed.
- Regular Expression Extractor
- CSS/JQuery Extractor
- XPath Extractor
- BeanShell Post Processor
- JSR223 Post Processor
- JDBC Post Processor
- JSON Path Post Processor
- Boundary Extractor
8. How do you extract specific attribute from response and parse it to another request, what is correlation? What is regular expression extractor?
Correlation is the most important aspect of scripting in JMeter. It includes fetching dynamic data from preceding requests/calls and passing them to the subsequent requests as parameters.
Example - we can extract the values of session variables from the response of the request with login details and then pass those values to the subsequent requests (thus handling the sessions).
Regular Expression Extractor is used to find out the dynamic value returned by the server like the session ID, order number etc. Such dynamic values are then passed in the next requests.
9. What are various listeners you used in your project?
Listeners are the elements that enable you to view the results of Samplers in the form of tables, graphs, trees or simple text in some log files. It provides visual access to the data gathered by JMeter for the test cases executed for the Sampler component of JMeter.
Some of the important JMeter Listeners used widely are...
- Aggregate Report
- View Result Tree
- View Result in Table
- Summary Report
10. How do you parameterized your test, how to handle Headers, cookie, default configuration in JMeter?
By using Configuration Element. A Config element allows you to create/configure default values and variables to be used by Samplers. It will get executed at the beginning of the scope before any Samplers present in the same range.
Following are the key features of Configuration Element.
- CSV Data Set Config: It supports reading line by line from a file and splitting the line into variables.
- HTTP Authorization Manager: You can specify one or more user logins for web pages that are restricted using server authentication.
- HTTP Cookie Manager: The Cookie Manager element has two functions:
- It stores and sends cookies just like a web browser.
- Second, you can manually add a cookie to the Cookie Manager. However, if you do this, the cookie will be shared by all JMeter threads.
- HTTP Request Defaults: It lets you set default values to be used by your HTTP Request controllers.
- HTTP Header Manager: It enables you to add or override the HTTP request headers.
11. Did you use JMeter controllers?
Yes, JMeter provides two types of Controllers.
1. Samplers Controllers: It enables JMeter to post specific types of requests to a server. For example, you can add an HTTP Request sampler if you need to perform a POST, GET, or DELETE operation on an HTTP service.
2. Logical Controllers: It lets you control the order of processing of Samplers in a Thread. Logic Controllers can change the order of request coming from any of their child elements. Some examples are ForEach Controller, While Controller, Loop Controller, IF Controller, Run Time Controller, Interleave Controller, Throughput Controller, and Run Once Controller.
12. What is latency in JMeter?
In simple words, Latency is network delay (time taken by network while transferring data).In JMeter latency is time between, when request is sent to server till first byte of response reaches the client/JMeter. If response time is very low enough then you won’t get precise measure of latency.
13. What was your approach/performance strategy, what all activities you performed during performance testing?
- Performance Test Requirements Gathering & Analysis
- Testing Tool Selection
- Performance Tests Planning
- Test Script Implementation
- Performance Test Execution
- Test Result Analysis and finding the performance bottlenecks.
14. What is ramp up period, throughput in JMeter? Difference between thread and samples?
In JMeter ramp-up period defines the time period within which the all the specified users get in running state i.e. the time frame (in seconds) for all requests to start.
- 100 threads and 100 seconds ramp-up: each second JMeter will start 1 Thread until all threads are started by the time the 100 seconds are up.
- 100 threads and 50 seconds ramp-up: each second 2 Threads are started.
- 100 threads and 200 seconds ramp-up: every .5 seconds, 1 Thread is started.
The number of requests that are completed per unit time is called the throughput. The time is calculated from the start of the first sample to the end of the last sample. This includes any intervals between samples, as it is supposed to represent the load on the server.
The formula is: Throughput = (number of requests) / (total time)
Threads and Samples are totally different. Threads represent the number of virtual users. Samples represent the number of total requests made by users. So suppose if you have a test plan with 5 requests. If you run it with 1 user: you will have 1 thread and 5 samples.
Samples = (Number of Threads (users) * Loop Count)
15. How response time and average response time is being calculated in JMeter?
Response time is the time difference between submissions of a request until the response begins to be received. The difference between response time and throughput is; throughput time is calculated from the start of the first sample to the end of the last sample whereas response time is calculated between submissions of a request until the response begins to be received
Total Avg Response time = ((s1*t1) + (s2*t2)...)/s
s1 = No of times transaction 1 was executed
t1 = Avg response time for transaction 1
s2 = No of times transaction 2 was executed
t2 = Avg response time for transaction 2
s = Total no of samples (s1+s2...)
16. How do you handle session and cookies during execution?
Sessions and cookies are managed in JMeter by using config elements such as HTTP Cookie Manager which provides an option to save the cookie. There is also an option to clear the cookies in every iteration and also allows to add user-defined cookies.
HTTP Cache manager helps to cache the images and .css file. It can also be cleared after each iteration as per the requirement in the load tests and also limits the number of elements which can be stored in the cache.
In JMeter you can specify how you want to manipulate with threads/users…
- Same user on each iteration checkbox: If this check box is checked, then the session/cookie will be same throughout the execution.
- Same user on each iteration checkbox: If this check box is unchecked, then you should get a new session/cookie every time but its not straight forward to execute this scenario, you have to perform below steps to do this...
17. What is the Maximum number of users/threads you can test in JMeter?
There is no limit on Thread execution in JMeter. Since it’s a java based tool, it uses java thread capabilities. Maximum number of users depends of your OS, free RAM and connection. I prefer fare to start maximum 300 users per machine. If you want to increase the number of users than use distributed testing.
How to increase JMeter users capacity and utilize system better way?
- Increase available memory (right click on jmter.bat and open with editor)
- Run JMeter via sh script, e.g.: /jmeter/5.1.1/libexec/bin/jmeter.sh -n -t testfile.jmx -l results.jtl -j log.txt
- Add very less/no listeners.
- Run JMeter in non-GUI mode.
18. How to run selenium Junit test cases into JMeter?
- Import the necessary jars inside JMeter/lib folder i.e. Selenium web driver jar, Junit4 Jar, Jar file which contains the automation selenium code
- In eclipse make sure that you create a Junit class, not just the class and add Junit annotations to this
- Your Junit test class should have either empty constructor or constructor taking a single string as an argument. Other options are not supported
19. What challenges you faced during distributed testing and how did you solve them?
The main problem that occurs is the connectivity issue from various slaves machine, I followed below steps to resolve them.
- The firewalls on the systems are turned off
- All the planned master and Slaves are in the same subnet
- Same version of JMeter on all the systems
- Try pinging form master to slave and vice versa
- Make sure to add the master and slave IPs to jmeter.properties
- Start the JMeter engine on Master.
- Start the Slave(s) using jmeter-server.bat
20. How you measure/record the performance of mobile application?
Recording of mobile application traffic is not much different from what we do to record scripts for web applications.
- Android proxy configuration: Go to Settings > Wi-Fi option (the shared Wi-Fi network should be same for both Mobile and PC where JMeter is installed).
- Long tap the network which you are connected and click the 'Modify Network' option.
- Check the 'Advanced options' checkbox.
- This will open advanced settings from which we can modify proxy manually. For this, set 'Proxy'option to 'Manual'.
- Now, set 'Proxy hostname' as your PC IP address and 'Proxy port' to 8080 as we have set up in JMeter Proxy server.
- Click 'Save', now you can start running the application on your mobile device and its requests will be recorded in JMeter.
21. What are the errors you encountered during running JMeter testing and how did you solve them?
- Error 1: Error:jmeter.threads.JMeterThread: Test failed! java.lang.OutOfMemoryError: Java heap space
- Solution: Need to increase heap memory. There is a line in jmeter.bat or jmeter.sh script wJVM_ARGS="-Xms512m -Xmx512m". Increase heap memory from here.
- Error 2: Error: java.net.SocketException: Connection reset
- Solution: Change "Implementation" of all your HTTP Request samplers to HttpClient4. The easiest way of doing it is using HTTP Request Defaults configuration element.
- Error 3: Error : Connection refused to host : : java.net.ConnectionException : Connection Refused
- Solution:Need to check the connection to host. Need to check the port number. Need to check the proxy settings
- Error 4: Error: Non HTTP response message: The target server failed to respond
- Solution: Try Disable Keep Alive.Check Network Bandwidth (network cards, interfaces and switches), Monitor your environment and Timeout or retries
- Error 5: Error : java.lang.String">java.net.BindException: Address already in use: connect in jmeter
- Solution: Try to change the port. Run your JMeter client on a separate machine than the tomcat. Also try to increase the ramp up time, if possible.
- Error 6: Error : ‘error: jmeterjava.io.ioexception exceeded the maximum number of redirects XXX’
- Solution: Add the cache manager and cookie manager in your script
22. What is the Timer in JMeter?
Timers add a delay between the flows of the script. They are used for halting the test execution of a thread for a certain predefined time. These timers are used for simulating the real user think time. The popular types of timers available in JMeter are:
- Constant Timer – This element delays each request in a Thread Group for the same amount of time.
- Gaussian Timer – This element is used to delay each user request for a random period of time.
- Synchronizing Timer – This element is used to release number of threads at given point.
- Uniform Random Timer – This element is used to delay each request for a random period of time.
23. What is the command to generate an HTML report at the end of the test?
jmeter -n -t <script name along with full path> -l <log file name (and path)> -e -o <path where HTML report will be stored>
- -n specifies that JMeter will run in the non-GUI mode
-t instructs that this is a test script file
-l instructs that log should be created at this location
24. What is BeanShell scripting and JSR223 elements?
BeanShell scripting is used to write the custom code in the JMeter script. if there are any complex scenario then BeanShell scripting is used. It is a lightweight Java scripting to perform some additional task.
25. What does “Contains” and “Matches” indicate in the Regular Expression?
In the regular expression, Contains indicates that the regular expression matched at least some part of the target. While Matches means the regular expression matched the whole target. So, ‘alphabet’ is “matched” by ‘al.*t.’
26. How to validate OAuth secured application using JMeter?
OAuth 2.0 Flow : This is a generic flow irrespective of the Authorization Grant Type that we need to pass while sending Authorization Grant request to get the access token.
In an OAuth 2.0 secured API, we need to first call the token URL to get the access token, and then we use that access token to call the main API.
Below are the detailed steps of implementing the OAuth API calls in JMeter itself and how the generated access token will be used to call the main API.
1. Create HTTP Request corresponding to the API that is responsible to generate the OAuth Token
a) Add a HTTP Request element: Thread Group -> Add -> Sampler -> HTTP Request
b) The above HTTP Request is to call the token API to get the access token. We are using the client credentials grant type in this example. Below are the details of all the required parameters like client-id, client-secret, grant_type, and scope that we need to pass as parameters.