One more "Simple REST API" tutorial in jMeter



  • First of all we need to add an HTTP Request Sampler inside a Thread group (Test Plan -> Thread Group -> Sampler->HTTP Request)Rest API Load Testing in JMeter

  • Next we need to enter the Server Name or IP of the API and its port(if required) in the web server section.
    The HTTP Request Section will be required to be filled as-
    Server Name or IP - Name of the server (e.g. jsonplaceholder.typicode.com) Implementation - Select HttpClient4 or Java
    Protocol[http] - Depending on type of protocol, select HTTP or HTTPS (e.g. the dummy API is build over http protocol so we'll be using http here)
    Method - Depending on the type of method, the API was build over, select Get, Put, Post, Delete etc (in our demo we will be working on Post method)
    Path - Application path after the API_URL (e.g. for API_URL http://jsonplaceholder.typicode.com/posts' the Path will be 'posts'
    Parameters/Post Body - Add Request of the API body here (request body of the API in "Post body" section (refer to screenshot below for detail, or we can also give requests parameters on by one in Parameters section)
    Rest API Load Testing in JMeter Artoftesting.com

  • User also need to add HTTP Header Manager as child to the HTTP Request sampler(for the current example this is not required, even will not work) with the content-type header
    Click on Add button on HTTP Header Manager and add "Content-Type" under Name and "application/json" under Value.Rest API JMeter

  • [Optional]Next we can add different assertions to the test plan in order to mark the test case as pass or fail based on the response fetched. E.g. the above dummy API returns the "title:foo" in its response. So, in order to test the API we can add a "Response Assertion" to the "HTTP Request"(HTTP Request->ADD->Assertion->Response Assertion) and add the pattern "title: 'foo'" in the Pattern to Test section of Response Assertion. Refer to screenshot for reference.Rest API Functional Testing

  • At last we can add different listeners like 'View Result Tree' to conclude. On running the JMeter script (Ctrl+r), we will see the response in for the API in the response data section of "View Result Tree".Rest API JMeter View Result Tree


In this way we can do the functional testing of the Rest APIs and increase the "Number of Thread" and "Loop Count" in the Thread Group for load testing it.

Comments

Popular posts from this blog

Robot Framework vs Cucumber

Performance Testing of RESTful APIs Using JMeter

Verification displayed number of rows inside table by Robot Framework