Category Archives: Testing

Getting Started with JMeter

This is a guide for someone who is trying to run JMeter for the very first time. So let’s dive into doing the stuff straight away by following the below steps

  1. First thing we need to do is to download JRT (java runtime environment), if we don’t have it installed already
  2. After installing JRT we need to download the Apache JMeter. I downloaded the .zip file under the binaries. if you can’t find it on the page click here. Please check on the Apache JMeter website there may be a newer version available.
  3. After unzipping the folder go to the bin folder and double click on jmeter.bat file which is highlighted in pic belowcapture
  4. This will start a console application, wait for few seconds and you will see a GUI for the JMeter.JMeter.PNG
  5. Now first thing we need to do is to create a Thread Group under the Test plan. So right click on Test Plan and go to Add -> Thread (Users) -> Thread Group. On this screen we can configure how many times this thread will run and few other things.
  6. Now right click on Thread Group in the tree and go to Add -> Sampler -> HTTP Request. On this pane we can configure the options related to http request.
    1. In the basic tab enter the server name of IP this can be a URL to your API Call
    2. Select implementation, in my case I selected HttpClient4
    3. Enter protocol, in my case I entered https
    4. Select method type i.e GET or POST or as per your api call
    5. In the path use the api function which is being called i.e the text appended after the main server address
    6. In the Body Data enter your json format data if your api call expecting that, otherwise do the needful as per your API implementation
  7. If your api call need some info to be appended in the header than right click on HTTP Request and go to Add -> Config Element -> HTTP Header Manager. Enter the data in key value pair. you can add data like  key = Content-Type, value=applicaiton/json
  8. If you want to validate the response of the API call, you can add Response Assertion by right clicking of HTTP Request and go to Add -> Assertions -> Response Assertion. The sample test is to be check the http response codes in this screen.
  9. If you want to extract the value from http response and use it and another http request. you can add the JSON Extractor or Regular Expression Extractor by right clicking HTTP Request and go to Add -> Post Processors -> JSON Extractor. The key fields in this page would be variable name (where your value will be stored to use in another http request), JSON path expression and match numbers. The format for JSON path expression is shown below. If you want to find only one match than Match Numbers should have 1 against it.json extractor.PNG
  10. Now in the end if someone wants to load sample data from csv for http requests then we need to add CSV data set config. Right click on Test Group and click on Add -> Config Element -> CSV Data Set Config. Key fields in this screen are
    1. Filename (Enter a full file path)
    2. Variable Names which will be use in http requests
    3. Delimiter usedcsv.PNG
    4. to use these variable in http request we need to change our http requests to be like this one. See how we changed the http request as per the variable names declared above.
  11. In the end click on RUN to see the test results in View Results Tree