Ads

JMeter Notes and interview Questions

Performance Testing:

  • Performance Testing is a process of testing to ensure that software application performs well under the particular load condition.

  • Also a kind of server testing.what happens if 1000 users accessing the application

  •  

What is JMeter?

  • Answer: JMeter is an open-source, Java-based tool used for performance testing, primarily web applications. It simulates a heavy load on servers, networks, or objects to test their strength and analyze overall performance under different load types.

What types of tests can JMeter perform?

  • Answer: JMeter can perform load testing, stress testing, functional testing, regression testing, and distributed testing. It is widely used for performance testing of web applications, databases, web services (SOAP/REST), FTP servers, and more.

Explain the role of a Thread Group in JMeter.

  • Answer: A Thread Group represents a group of virtual users who will execute a particular test plan. It defines the number of users, the ramp-up period (how long it takes to start all the threads), and the loop count (how many times to execute the test). Each thread simulates a single user request to the server.

. What are samplers in JMeter?

  • Answer: Samplers in JMeter are used to send requests to the server and wait for a response. They simulate the user's activity on the server. Some common types of samplers include HTTP Request, FTP Request, JDBC Request, SOAP/XML-RPC Request, and JMS Request.

. How does JMeter handle dynamic values in requests?

  • Answer: JMeter handles dynamic values using Regular Expression Extractor or JSON Extractor post-processors. These extract dynamic data (like session IDs, tokens) from the server responses and store them in variables, which can then be used in subsequent requests.

What is the purpose of the "Controller" elements in JMeter?

  • Answer: Controllers in JMeter determine the order of processing of samplers in a thread. There are two main types of controllers: Logic Controllers (e.g., If Controller, Loop Controller, Transaction Controller) which control the flow of the test and Test Fragment Controller used to reuse test fragments in multiple places within the test plan.

What are listeners in JMeter, and why are they important?

  • Answer: Listeners are used to view, save, and analyze the results of performance tests in JMeter. They can show results in different formats such as tables, trees, graphs, or logs. Some commonly used listeners include View Results Tree, Graph Results, and Summary Report.

Explain the difference between a "Throughput" and "Response Time" in JMeter.

  • Answer:

    • Throughput refers to the number of requests processed by the server in a given time period. It's typically measured in requests per second or transactions per second.

    • Response Time is the time taken by the server to respond to a request. It's the duration from the moment a request is sent until the complete response is received.

How can you parameterize a JMeter script?

  • Answer: Parameterization in JMeter is done using CSV Data Set Config. This allows you to run your test with multiple sets of data. You can read data from a CSV file and substitute values in the requests with the variables from the CSV.

What is a "Test Plan" in JMeter?

  • Answer: A Test Plan in JMeter is a container for all elements that make up a test. It includes thread groups, controllers, samplers, listeners, timers, and other configuration elements. It defines how the test should run.

What is a Correlation in JMeter? How is it done?

  • Answer: Correlation in JMeter refers to the process of capturing dynamic values from the server response and using them in subsequent requests. This is typically done using the Regular Expression Extractor or JSON Extractor to extract values like session IDs or tokens, which are then reused in the test.

How do you perform Distributed Testing using JMeter?

  • Answer: Distributed Testing in JMeter involves using multiple machines to perform load testing. This is done by setting up one machine as the Master and others as Slaves. The Master machine sends the test plan to all the Slave machines, which then execute the plan and send the results back to the Master.

How can you reduce resource usage in JMeter during a test?

  • Answer: To reduce resource usage in JMeter, you can:

    • Run tests in non-GUI mode using the command line.

    • Use less intensive listeners like Simple Data Writer instead of View Results Tree.

    • Increase the heap size in the JMeter properties file if needed.

    • Use CSV Data Set Config for parameterization instead of hard-coding data.

What is the difference between a "Test Fragment" and a "Module Controller"?

  • Answer:

    • A Test Fragment is a special type of controller in JMeter used to define a part of a test plan that can be reused across different parts of the test plan.

    • A Module Controller allows you to define reusable modules (test fragments) and include them in your test plan. This helps in reusing parts of the test plan across different thread groups.

  • Answer: The HTTP Cookie Manager in JMeter automatically handles cookies for web applications. It stores and sends cookies along with HTTP requests, mimicking the behavior of a real browser. This is important for maintaining session state across multiple requests.

 

Test Plan:

Actual Execution will be done here.It consists of all actions,components.

Right Click,Add-->

  1. Thread Group---->it contains number of virtual users,loop count,ramp up period

  2. Test fragment--->is a special type of controller used to define particular part of a plan

  3. Config Element--->used to configure multiple values.http header cookie,header,cache manager

  4. timer--->we can time between two requests constant

  5. Pre processor--->pre requisite

  6. Post Processor--->json extractor,regular expression extractor

  7. Listener--->kind of reporting..View Results tree,Aggregate Report,

  8. Assertions--->Response assertion,json assertion,duration assertion,size assertion

  9. Non test Elements--->http script recorder

 

Alternate way to generate .jmx file:

  1. Http record play back

    1. Start--->record everything--->Stop

      1. it gives all html,http requests everything

      2. Remove unwanted requests and keep only http requests

      3. Mandentory: Firefox proxy has to be set to 127.0.0.1 port 8888 and upload certificate from bin folder

  2. BlazeMeter

    1. this is actually a extension used to record and attach in jmeter

    2. start -->record everything-->stop-->Export as .jmx file-->in jmeter,open-->this will automatically attaches the config elements such as http header manager,cookie manager,cache manager,user defined variables,authorization manager

 

Thread Group:

All actions should be placed under thread groups

1.Number of threads--->no of virtual users ex:100 users

2.Ramp up period--->how long users have to load.ex:5 seconds…so 100/5=20 users will be loaded per second

3.Loop count-->how many times that thread group should run

  • 4.Additionally,we can mention duration and start up delay

    • Durarion---120 seconds,execution only run till 120 seconds completed

    • Start up delay-->5 seconds,execution will start after 5 seconds

Action to be taken a sampler error:

 

Listeners:

Listeners used to generate reports for analyse the result

View Result tree:

shows request wise response data,request data everything

latency,response code,response message,load time,connect time

green marked pass,red marked failed

Aggregate Report:

shows all terminolgies such as Samples,average,median,90%line,95% line,99% line,min,maximum.error%

ThroughPut,Received,sent

Samples--->User count

Average-->average response time

median--->kind of centre point

Min-->min response time

Max-->max response time

90%line--->90% of the users got this much response time

95%line--->95% of the users got this much response time

99% line-->99% of the users got this much response time

Error%--->error percentage,failed users/totalusers*100

thoroughput-->no of users handled by the server per second

received/sent-->size

 

Response time vs Thoroughput:

Response time is the time taken by the server to respond.duration between request sent untill full response received.

Throughput: capability of the server to handle the request per second.

 

Graph result:

Understanding Deviation in JMeter:

  • Standard Deviation is a measure of the amount of variation or dispersion in a set of values. It indicates how spread out the response times are from the mean (average) response time.

  • If the deviation is low, it means that the response times are close to the mean, indicating consistent performance.

  • If the deviation is high, it means that the response times vary significantly, indicating inconsistent performance and possibly issues that need investigation

 

External Thread Groups:

Concurrent Thread Groups:

Parameters:

Target concurrency,Ramp up time,Ramp up steps,Hold target date

  • Target concurrency: no of users

  • Ramp up time:within specified time all users should be onboarded

  • Ramp up steps :with how many steps that users has to be onboarded

  • Hold Target Rate time--->how much time users/tests should be continue

 

 

Ultimate thread Group:

similar to concurrency thread group,but in this we can set some initial delay and shutdown time

 

Cookie Manager:

Used to store the cookies. cookies in the sense it contains accesstoken and some important terminologies.

Jmeter is not a browser,so it wont store any cookies automatically,manually we have to configure http cokkie manager so that cookies will be passed in each request to avoid continuity.

Assertions:

Response Assertion:

Field to Test:

Text Response,Response code,Response message,Response headers,Request headers,

Pattern MAtching rules:

contains,matches,equals,

 

 

Custom Failure Message:

in case failing we can give custom messages

 

 

Apply to:

Main response or sub sample response anything we can set

 

Types of Assertions:

Size assertion:Size of response can be validated

Duration assertion: duration also can be verified

Controller:

Module wise segregate the api’s under controllers.for ex: Transation controller named as Login and Login related API’s placed here.similary for Flight Booking,confirmation,payment modules maintained as Transasction controller.

Now if client asks howmuch time taken for flight confirmation we can simply give the aggregate reprot for their information

 

Types of controllers:

Simple controller:

Simple but not like transaction controller..EAch request appears in aggregate report instead of module wise

MOdule Controller:

For exL:if we have to run another flow,we have to create login flow again..to avoid that we can simply refer that login module here.

 

InterLEave controller:

  • The Interleave Controller alternates between each of its child elements sequentially for every iteration of the thread.

  • During each iteration of the thread, only one child element is executed. On the next iteration, the next child element is executed, and so on.

  • Once all child elements have been executed, the controller will start again from the first child element.

Random controller:

Similar to interleave controller but it picks the child element randomly whereas Interleave controller picks the child element in sequential order.(during iteration)

Random Order Controller:

Picks any one child element(not all child element) during iteration

Runtime controller:

Particular request under run time controller runs continues till set time.

If controller:

only if condition satisfied then only apis under that controller will execute.

Loop controller:

that particular api will run specified number of times.

while controller:

untill condition false,it keep on looping….

Timers Usage:

Gap between threads(users..Scenario: in 60 seconds 50 users clicking application ok.but in 1 sec 50 users clicking is invalid.so such kind of scenario we can utilise the timers.

Constant timer:

 

Gaussian timer:

Deviation and constant delay can be given.

Constant thoroughPut timer:

can give target 200 .so based on this target server will load…

Regular Expression Extractor:

Post Processor-->Regular Expression Extractor

(.+?) if we have multiple $1$ it will pick first value.

Enter<em>(.+?)</em> for the username and for the password <em>(.+?)</em>

username_g1--user name

username_g2--password

we can refer this by ${username_g1} and ${username_g2} for password

we can use those ${username_g1} and ${username_g2}

Debug Sampler:

if we extract any value from regular expression extractor we can see those values here in view result tree

Sampler:

http Request--->Normal http request

Data Driven:

Thread group-->config element-->CSV DAta set config-->Select file

variable names comma separated-username,password

Recycle on EOF-end of file-->if we have 7 set of data and we gave 10 threads again thread will start taking first value..to avoid give it as false.

 

Bean shell Scripting:

Pre processors:

Bean shell pre processor used to set or modify the variable through script if needed.

String usernameBro=vars.get("username"); String newUsername; if(usernameBro.contains("required")){ newUsername=usernameBro+"EditedBro"; vars.put("username",newUsername); }

Post Processors:

vars ctx prop log prev

vars===>used to refer variables

ctx==>used to retrieve thread related functions

props--->used to set global variable to use across different thread groups

prev--->used to retrieve previous request responses

log--->used to log messages

String threadNumber=ctx.getThreadNum().toString(); if(vars.get("username").contains("ayyanPattasu")){ String newUser=vars.get("username"); vars.put("username",newUser+threadNumber); } if(prev.getResponsecode().toString().equals(200)){ log.info("Test PAssed Bro"); } if(prev.getResponseMessage().equals("OK")){ props.put("Result","Pass"); }

 

Run Jmeter through CMD:

jmeter -n -t runner.jmx -l c:result.jtl

it generates jtl report that can be viewed in xl file.

 

Jmeter Distributed Format:

Main machine will act as a master under that we can create more slave machines…this is useful when we want to run 5000 users at a time.it may affect the system performance and ram performance..to overcome this issue we are running jmeter in distributted system..

Comments

Popular posts from this blog

Rest Assured Api Automation

Appium Notes

Jenkins Notes