HTTP Protocol

Recording and playback of script:
JMeter has HTTP Proxy Server to listen to requests being sent from web browser to the server.
Ex for web application it automatically creates HTTP Request samplers for each action that has been performed on the application.


Steps to record the HTTP application using JMeter in windows environment
Step-1: Open JMeter and Add Thread Group under Test Plan
Right click on test plan -->Add --> Threads (User’s) -->Thread Group


Step-2: Add HTTP Request Defaults under the Thread Group
Right click on Thread Group --> Add -->Config Element -->HTTP Request Defaults

Provide application Host name and port number in respective fields.

Step-3: Add HTTP Proxy Server under WorkBench
Right click on WorkBench --> Add -->Non-Test Element --> HTTP Proxy Server

 

The default port is 8080. If the app server is running on the same machine as JMeter and it also uses 8080, then should have to pick an unused port in JMeter HTTP Proxy Server.

Step-4:
Since JMeter will act as a proxy sever after clicking on start button in HTTP Proxy Server, need to keep browser Proxy Server as localhost.

Note: The port number in browser ‘proxy sever’ should be same as that in JMeter HTTP Proxy Server under workbench



Step-5:
JMeter has a provision to Include/Exclude specific requests/patterns. Capturing of static HTML files, GIFs, CSS and JS files are not required. Below is the format that is used in Include/Exclude pattern..*\.htm
.*\.jpg
.*\.png
.*\.gif
.*\.css
.*\.js




In 2.8 version, "Add From Clipboard' option is available. By using this option all the exclude patterns can be added at once.

Click on start button to start JMeter HTTP Proxy Server
provide the application url in browser and browse the application according to the designed scenario.
click on Stop button after the completion of browsing the scenario and Save the script.

Step-6:
Add Listener to the Thread group to view the execution results.
The listener ‘View Results Tree’ will be helpful in debugging the script.

Right click on Thread Group --> Add --> Listener --> View Results Tree





Add the listener 'Aggregate Graph' to view the response times


Run the test and check the results


Parameterization
What is Parameterization and why it is required?

Parameterization is process of generalizing user input, so as to use it for multiple executions. When a test plan needs to run/execute for more than one user at the same time, parameterization concept is used. It is a method of generalizing an action.

Ex: Suppose, we have to do load test for a multiple categories in filpkart site, for that we record the related scenario. Now to do effective load test, we can’t just playback the script for say 100 users. We should simulate 100 users that access for 100 different categories. Here we need parameterization, wherein we can have a CSV file that contains 100 different items. Now instead of the static category/ item that we had recorded in our script we can include the different items from the CSV file dynamically.

Implementation of parameterization in JMeter
Add CSV Data Set to Thread Group
Right click on Thread Group --> Add --> Config Element --> CSV Data Set Config.










Create the txt file or csv file and save it in the same location of script. Add the values in the file.

In our example, the file name is ‘categories.txt’ and the values are books, computers and cameras.












As shown in above screen shot, provide the 'Filename:' filed value as categories.txt
And 'Variable Names (comma-delimited):' field value as categories

In the script, check for the categories and replace the variable name.
In our example, books is the category where the variable should be placed.




















Replace the variables as shown in above format.
In Thread group, keep the loop count as 3 and run the test.


 




After running the test, check the results in view results tree.
For the first user, it has picked the value as books









For the second user, it has picked the value as computers
















 











For the Third user, it has picked the value as cameras









No comments:

Post a Comment