Pages

Thursday, December 27, 2018

API performance testing using JMETER

 API performance testing using JMETER



In this article we are going to learn about How to use step by step JMETER for API Load and Performance testing . Basic information and details about JMETER and what is web service and API had been provided in our earlier topics.  JMETER is open source tool. Downloading JMETER is already covered in earlier topic. JMETER is free.


For question How to do API performance testing using JMETER? below are the steps.

Step 1.  Configure Test Plan in JMETER

For REST API performance testing we have to start with Test plan in JMETER. The test Plan is where the overall settings for a test are specified. Static variables can be defined for values that are repeated throughout a test, such as server names. For example the variable “environment” could be defined as www.example.com, and the rest of the test plan could refer to it as ${environment}. This simplifies changing the name later


Step2. Adding HTTP Header manager to JMETER
  1.     Right click on test plan >Add> Config element> http header manager
  2.     Click on Add button to add header 

There are multiple headers are available you can use any as per your requirement

Step3. Adding Thread group to JMETER
 Right click on Test Plan> Click Add> Click Threads>Thread group



You can see thread group is added in project.
A Thread Group defines a pool of users that will execute a particular test case against your server.
Number of Threads-Number of users to simulate
Ramp-up Period-How long JMeter should take to get a
Loop Count-Number of times to perform the test case.


Step4. Adding HTTP Requests
 1.Right click on thread group> Samplers> HTTP Request 


2. HTTP Request added to project. This sampler lets you send an HTTP/HTTPS request to a web server.
3. Use Protocol- HTTPS, Server name- Endpoint URL of API, Method , Enter REST request in BODY DATA tab and Save

Step 5-5. Adding Listener’s 

Most of the listeners perform several roles in addition to "listening" to the test results. They also provide means to view, save, and read saved test results. We are using two listeners  “Summary Report” and “View result Tree”. Right click on Thread group> Add> listeners 


 “Summary Report” and “View result tree” both listeners are added to project  

6. Running Test 

a.  Click on test plan and update 
  Number of Threads (5)
  Ramp-up Period(0)
  Loop Count(1) 
And click on run button  

b. Once you start execution you can see Number of users Test run, Time in upper right corner. Once execution done Green flag turn down to Grey 

7. Understanding  JMETER performance testing Reports 

A- How to understand JMETER Summary Report 


 Label - The name of the sample.  
 # Samples - The number of samples with the same label 
 Average - The average elapsed time of a set of results
  Min - The lowest elapsed time for the samples with the same label 
Max - The longest elapsed time for the samples with the same label 
Std. Dev. - the Standard Deviation of the sample elapsed time 
Error % - Percent of requests with errors 
Throughput - the Throughput is measured in requests per second/minute/hour. The time unit is chosen so that the displayed rate is at least 1.0. When the throughput is saved to a CSV file, it is expressed in requests/second, i.e. 30.0 requests/minute is saved as 0.5. 
Received KB/sec - The throughput measured in Kilobytes per second 
Sent KB/sec - The throughput measured in Kilobytes per second
  Avg. Bytes - average size of the sample response in bytes 

b.  Understanding JMTER View Result Tree Report –  
Sampler Result Tab-  Here you can see 5 HTTP Request in Green as we done Performance test with 5 users and all were  succeeded. If any one or more failed it will show in Read. Here you can  header data passed for each user


Request Tab- You can see here Request sent for each user

Response Data Tab- You can see here response received for each user 



Thursday, December 20, 2018

Understanding JMETER Listeners




Understanding Listeners in JEMTER  :-  Listener displays particulars of sampler requests and responses, and can display basic HTML and XML representations of the response. Other listeners deliver summary or aggregation information. We can use listeners can direct the data to a file for later use. Listeners can be added anywhere in the test, including directly under the test plan

Types of JMETER Listeners 

1.                Aggregate Graph
The Aggregate Graph listener is used to show the test results in both tabular form(reports) and graphs.
2.                Aggregate Report
The Aggregate Report listener is used to display and store test results in the form of reports.
3.                Assertion Results
The assertion results listener is used to display the assertion result for each erroneous sampler response. It is advised to not use this listener during performance test as it is very resource intensive. It should be used while debugging and functional testing only.
4.                Backend Listener
The backend listener is a special type of asynchronous listener used specifically with BackendListenerClient for its customization.
5.                BeanShell Listener
The beanshell listener is used to enable beanshell scripting in JMeter. For details on BeanShell Scipting check our tutorial Bean Shell Scripting in JMeter.
6.                BSF Listener
The beanshell listener is used to enable BSF scripting in JMeter.
7.                Comparison Assertion Visualizer
The Comparison Assertion Visualizer is used to provide the comparison between assertion result in an easy to compare UI.
8.                Generate Summary Results
The Generate Summary results listener is used to store and display detailed test results to log files.
9.                Graph Results
The Graph results listener is used to display each sampler resuest's response time graph in terms of average, median, deviation and throughput.
10.             JSR223 Listener
The JSR223 Listener is used to enable JSR223 scripting in JMeter.
11.             Mailer Visualizer
The Mailer Visualizer sampler is used to provide the functionality of sending customized mails in case of some specific error threshold.
12.             Monitor Results
This is a newly added listener in JMeter used to display and store server performance stats.
13.             Response Time Graph
The response time graph is used to provide the graphical representation of response time with time elapsed during the test run.
14.             Save Response to a file
The save response to a file listener is used to store the sampler response in a file. This listener is used while functional testing or debugging the test script.
15.             Simple Data Writer
The simple data writer listener is used to save the sampler response to a file after with different configurations to remove several unnecessary overheads.
16.             Summary Report
The summary report is used to store and display the test result in tabular form just like aggregate report listener but consumes less memory(as per Apache JMeter).
17.             View Results Tree
This listener is used to provide and store test results for each and every individual sampler.
18.             View Results in Table
The view results in table listener is used to display the sampler response header and response body.


Tuesday, December 11, 2018

JMETER -Understanding Thread Group



In this part of step by step JMETER tutorial we are going to learn about JMETER element “THREAD GROUP”

What is Thread Group in JMETER:-

Thread group is a place where we actually put number of users (Threads). It is starting point of JMETER test plan. This is first element of JMETER test plan. Each thread represent one user.  Using this Thread Group you can set number of users. Using thread group is basic step to start with JMETER load testing.

Now let’s understand How Element Thread group works .
If you put load of 50 users on your server by configuring 50 threads . Then all 50 user will simulate and will put load on server.




There are 3 controls we need to set for JMETER
  • Set the number of threads
  • Set the ramp-up period
  • Set the number of times to execute the test

  • How to set the number of threads
Here we need to set number of threads . If you put load of 50 users on your server by configuring 50 threads . Then all 50 user will simulate and will put load on server.
  • How to set the ramp-up period
The ramp-up period expresses JMeter how long to take to "ramp-up" to the full number of threads selected. If 10 threads are used, and the ramp-up period is 100 seconds, then JMeter will take 100 seconds to get all 10 threads up and running
  • How to set the number of times to execute the test (LOOP count):- how many times to run thread group  in loop. If you set value 2 then thread group will run twice.

Saturday, October 13, 2018

Creating Test Plan in JMETER




Creating Test Plan in JMETER

How to create test plan in JMETER for REST API performance testing?

For REST API performance testing we have to start with Test plan in JMETER. The test Plan is where the overall settings for a test are specified. Static variables can be defined for values that are repeated throughout a test, such as server names. For example the variable “environment” could be defined as www.example.com, and the rest of the test plan could refer to it as ${environment}. This simplifies changing the name later


Monday, August 13, 2018

HTML - Lists

HTML - Lists

HTML offers web authors three ways for specifying lists of information. All lists must contain one or more list elements. 

Lists may contain −

<ul> − An unordered list. This will list items using plain bullets.

<ol> − An ordered list. This will use different schemes of numbers to list your items.

<dl> − A definition list. This arranges your items in the same way as they are arranged in a dictionary.

HTML Unordered Lists

An unordered list is a collection of related items that have no special order or sequence. This list is created by using HTML <ul> tag. Each item in the list is marked with a bullet.

Example

<!DOCTYPE html>
<html>

   <head>
      <title>HTML Unordered List</title>
   </head>
   <body>
      <ul>
         <li>Beetroot</li>
         <li>Ginger</li>
         <li>Potato</li>
         <li>Radish</li>
      </ul>
   </body>
   
</html>
This will produce the following result −


The type Attribute

You can use type attribute for <ul> tag to specify the type of bullet you like. By default, it is a disc. Following are the possible options −

<ul type = "square">
<ul type = "disc">
<ul type = "circle">

Example

Following is an example where we used <ul type = "square">

<!DOCTYPE html>
<html>

   <head>
      <title>HTML Unordered List</title>
   </head>

   <body>
      <ul type = "square">
         <li>Beetroot</li>
         <li>Ginger</li>
         <li>Potato</li>
         <li>Radish</li>
      </ul>
   </body>

</html>
This will produce the following result −


Example

Following is an example where we used <ul type = "disc">

<!DOCTYPE html>
<html>

   <head>
      <title>HTML Unordered List</title>
   </head>
   <body>
      <ul type = "disc">
         <li>Beetroot</li>
         <li>Ginger</li>
         <li>Potato</li>
         <li>Radish</li>
      </ul>
   </body>

</html>
This will produce the following result −


Example

Following is an example where we used <ul type = "circle"> −

 <!DOCTYPE html>
<html>

   <head>
      <title>HTML Unordered List</title>
   </head>

   <body>
      <ul type = "circle">
         <li>Beetroot</li>
         <li>Ginger</li>
         <li>Potato</li>
         <li>Radish</li>
      </ul>
   </body>
</html>
This will produce the following result −


HTML Ordered Lists

If you are required to put your items in a numbered list instead of bulleted, then HTML ordered list will be used. This list is created by using <ol> tag. The numbering starts at one and is incremented by one for each successive ordered list element tagged with <li>.

Example

<!DOCTYPE html>
<html>

   <head>
      <title>HTML Ordered List</title>
   </head>

   <body>
      <ol>
         <li>Beetroot</li>
         <li>Ginger</li>
         <li>Potato</li>
         <li>Radish</li>
      </ol>
   </body>

</html>
This will produce the following result −


The type Attribute

You can use type attribute for <ol> tag to specify the type of numbering you like. By default, it is a number. Following are the possible options −

<ol type = "1"> - Default-Case Numerals.
<ol type = "I"> - Upper-Case Numerals.
<ol type = "i"> - Lower-Case Numerals.
<ol type = "A"> - Upper-Case Letters.
<ol type = "a"> - Lower-Case Letters.

Example

Following is an example where we used <ol type = "1">

 <!DOCTYPE html>
<html>

   <head>
      <title>HTML Ordered List</title>
   </head>

   <body>
      <ol type = "1">
         <li>Beetroot</li>
         <li>Ginger</li>
         <li>Potato</li>
         <li>Radish</li>
      </ol>
   </body>

</html>
This will produce the following result −

Example

Following is an example where we used <ol type = "I">

<!DOCTYPE html>
<html>

   <head>
      <title>HTML Ordered List</title>
   </head>
   <body>
      <ol type = "I">
         <li>Beetroot</li>
         <li>Ginger</li>
         <li>Potato</li>
         <li>Radish</li>
      </ol>
   </body>
</html>
This will produce the following result −


Example

Following is an example where we used <ol type = "i">

 <!DOCTYPE html>
<html>
   
   <head>
      <title>HTML Ordered List</title>
   </head>
   <body>
      <ol type = "i">
         <li>Beetroot</li>
         <li>Ginger</li>
         <li>Potato</li>
         <li>Radish</li>
      </ol>
   </body>
</html>
This will produce the following result −


Example

Following is an example where we used <ol type = "A" >

 <!DOCTYPE html>
<html>

   <head>
      <title>HTML Ordered List</title>
   </head>
   <body>
      <ol type = "A">
         <li>Beetroot</li>
         <li>Ginger</li>
         <li>Potato</li>
         <li>Radish</li>
      </ol>
   </body>
</html>
This will produce the following result −


Example

Following is an example where we used <ol type = "a">

 <!DOCTYPE html>
<html>
   
   <head>
      <title>HTML Ordered List</title>
   </head>
   <body>
      <ol type = "a">
         <li>Beetroot</li>
         <li>Ginger</li>
         <li>Potato</li>
         <li>Radish</li>
      </ol>
   </body>
</html>
This will produce the following result −


The start Attribute

You can use start attribute for <ol> tag to specify the starting point of numbering you need. Following are the possible options −

<ol type = "1" start = "4">    - Numerals starts with 4.
<ol type = "I" start = "4">    - Numerals starts with IV.
<ol type = "i" start = "4">    - Numerals starts with iv.
<ol type = "a" start = "4">    - Letters starts with d.
<ol type = "A" start = "4">    - Letters starts with D.

Example

Following is an example where we used <ol type = "i" start = "4" >

<!DOCTYPE html>
<html>

   <head>
      <title>HTML Ordered List</title>
   </head>
   <body>
      <ol type = "i" start = "4">
         <li>Beetroot</li>
         <li>Ginger</li>
         <li>Potato</li>
         <li>Radish</li>
      </ol>
   </body>
</html>
This will produce the following result −


HTML Definition Lists

HTML and XHTML supports a list style which is called definition lists where entries are listed like in a dictionary or encyclopedia. The definition list is the ideal way to present a glossary, list of terms, or other name/value list.

Definition List makes use of following three tags.

<dl> − Defines the start of the list
<dt> − A term
<dd> − Term definition
</dl> − Defines the end of the list

Example

<!DOCTYPE html>
<html>

   <head>
      <title>HTML Definition List</title>
   </head>
   <body>
      <dl>
         <dt><b>HTML</b></dt>
         <dd>This stands for Hyper Text Markup Language</dd>
         <dt><b>HTTP</b></dt>
         <dd>This stands for Hyper Text Transfer Protocol</dd>
      </dl>
   </body>
</html>
This will produce the following result −

Friday, August 10, 2018

HTML - Tables

HTML - Tables


The HTML tables allow web authors to arrange data like text, images, links, other tables, etc. into rows and columns of cells.

The HTML tables are created using the <table> tag in which the <tr> tag is used to create table rows and <td> tag is used to create data cells. The elements under <td> are regular and left aligned by default

Example

<!DOCTYPE html>
<html>

   <head>
      <title>HTML Tables</title>
   </head>
   <body>
      <table border = "1">
         <tr>
            <td>Row 1, Column 1</td>
            <td>Row 1, Column 2</td>
         </tr>
         
         <tr>
            <td>Row 2, Column 1</td>
            <td>Row 2, Column 2</td>
         </tr>
      </table>
      
   </body>
</html>
This will produce the following result −


Here, the border is an attribute of <table> tag and it is used to put a border across all the cells. If you do not need a border, then you can use border = "0".

Table Heading

Table heading can be defined using <th> tag. This tag will be put to replace <td> tag, which is used to represent actual data cell. Normally you will put your top row as table heading as shown below, otherwise you can use <th> element in any row. Headings, which are defined in <th> tag are centered and bold by default.

Example

<!DOCTYPE html>
<html>

   <head>
      <title>HTML Table Header</title>
   </head>
   <body>
      <table border = "1">
         <tr>
            <th>Name</th>
            <th>Salary</th>
         </tr>
         <tr>
            <td>Ramesh Raman</td>
            <td>5000</td>
         </tr>
         
         <tr>
            <td>Shabbir Hussein</td>
            <td>7000</td>
         </tr>
      </table>
   </body>
   
</html>

This will produce the following result −


Cellpadding and Cellspacing Attributes

There are two attributes called cellpadding and cellspacing which you will use to adjust the white space in your table cells. The cellspacing attribute defines space between table cells, while cellpadding represents the distance between cell borders and the content within a cell.

Example

<!DOCTYPE html>
<html>

   <head>
      <title>HTML Table Cellpadding</title>
   </head>
   <body>
      <table border = "1" cellpadding = "5" cellspacing = "5">
         <tr>
            <th>Name</th>
            <th>Salary</th>
         </tr>
         <tr>
            <td>Ramesh Raman</td>
            <td>5000</td>
         </tr>
         <tr>
            <td>Shabbir Hussein</td>
            <td>7000</td>
         </tr>
      </table>
   </body>
</html>
This will produce the following result −

Colspan and Rowspan Attributes

You will use colspan attribute if you want to merge two or more columns into a single column. Similar way you will use rowspan if you want to merge two or more rows.


Example

<!DOCTYPE html>
<html>

   <head>
      <title>HTML Table Colspan/Rowspan</title>
   </head>
   <body>
      <table border = "1">
         <tr>
            <th>Column 1</th>
            <th>Column 2</th>
            <th>Column 3</th>
         </tr>
         <tr>
            <td rowspan = "2">Row 1 Cell 1</td>
            <td>Row 1 Cell 2</td>
            <td>Row 1 Cell 3</td>
         </tr>
         <tr>
            <td>Row 2 Cell 2</td>
            <td>Row 2 Cell 3</td>
         </tr>
         <tr>
            <td colspan = "3">Row 3 Cell 1</td>
         </tr>
      </table>
   </body>
</html>
This will produce the following result −

Tables Backgrounds

You can set table background using one of the following two ways −

bgcolor attribute − You can set background color for whole table or just for one cell.

background attribute − You can set background image for whole table or just for one cell.

You can also set border color also using bordercolor attribute.

Note − The bgcolor, background, and bordercolor attributes deprecated in HTML5. Do not use these attributes.

Example

 <!DOCTYPE html>
<html>

   <head>
      <title>HTML Table Background</title>
   </head>
   <body>
      <table border = "1" bordercolor = "green" bgcolor = "yellow">
         <tr>
            <th>Column 1</th>
            <th>Column 2</th>
            <th>Column 3</th>
         </tr>
         <tr>
            <td rowspan = "2">Row 1 Cell 1</td>
            <td>Row 1 Cell 2</td>
            <td>Row 1 Cell 3</td>
         </tr>
         <tr>
            <td>Row 2 Cell 2</td>
            <td>Row 2 Cell 3</td>
         </tr>
         <tr>
            <td colspan = "3">Row 3 Cell 1</td>
         </tr>
      </table>
   </body>
</html>
This will produce the following result −


Here is an example of using background attribute. Here we will use an image available in /images directory.

<!DOCTYPE html>
<html>

   <head>
      <title>HTML Table Background</title>
   </head>
   <body>
      <table border = "1" bordercolor = "green" background = "/images/test.png">
         <tr>
            <th>Column 1</th>
            <th>Column 2</th>
            <th>Column 3</th>
         </tr>
         <tr>
            <td rowspan = "2">Row 1 Cell 1</td>
            <td>Row 1 Cell 2</td><td>Row 1 Cell 3</td>
         </tr>
         <tr>
            <td>Row 2 Cell 2</td>
            <td>Row 2 Cell 3</td>
         </tr>
         <tr>
            <td colspan = "3">Row 3 Cell 1</td>
         </tr>
      </table>
   </body>
</html>
This will produce the following result. Here background image did not apply to table's header.


Table Height and Width

You can set a table width and height using width and height attributes. You can specify table width or height in terms of pixels or in terms of percentage of available screen area.


Example

<!DOCTYPE html>
<html>

   <head>
      <title>HTML Table Width/Height</title>
   </head>
   <body>
      <table border = "1" width = "400" height = "150">
         <tr>
            <td>Row 1, Column 1</td>
            <td>Row 1, Column 2</td>
         </tr>
         
         <tr>
            <td>Row 2, Column 1</td>
            <td>Row 2, Column 2</td>
         </tr>
      </table>
   </body>
</html>
This will produce the following result −


Table Caption

The caption tag will serve as a title or explanation for the table and it shows up at the top of the table. This tag is deprecated in newer version of HTML/XHTML.

Example

 <!DOCTYPE html>
<html>

   <head>
      <title>HTML Table Caption</title>
   </head>
   <body>
      <table border = "1" width = "100%">
         <caption>This is the caption</caption>
         
         <tr>
            <td>row 1, column 1</td><td>row 1, columnn 2</td>
         </tr>
         
         <tr>
            <td>row 2, column 1</td><td>row 2, columnn 2</td>
         </tr>
      </table>
   </body>
</html>
This will produce the following result −


Table Header, Body, and Footer

Tables can be divided into three portions − a header, a body, and a foot
The head and foot are rather similar to headers and footers in a word-processed document that remain the same for every page, while the body is the main content holder of the table.

The three elements for separating the head, body, and foot of a table are −


<thead> − to create a separate table header.

<tbody> − to indicate the main body of the table.

<tfoot> − to create a separate table footer.

A table may contain several <tbody> elements to indicate different pages or groups of data. But it is notable that <thead> and <tfoot> tags should appear before <tbody>

Example

<!DOCTYPE html>
<html>

   <head>
      <title>HTML Table</title>
   </head>
   <body>
      <table border = "1" width = "100%">
         <thead>
            <tr>
               <td colspan = "4">This is the head of the table</td>
            </tr>
         </thead>
         
         <tfoot>
            <tr>
               <td colspan = "4">This is the foot of the table</td>
            </tr>
         </tfoot>
         
         <tbody>
            <tr>
               <td>Cell 1</td>
               <td>Cell 2</td>
               <td>Cell 3</td>
               <td>Cell 4</td>
            </tr>
         </tbody>
         
      </table>
   </body>
</html>
This will produce the following result −