How to Convert Your Postman API Tests to JMeter for Scaling
Many test engineers use Postman for API testing automation. They discover endpoints, make requests, create test data, run regression testing, implement continuous integration of API testing by using Newman and much more. However, Postman has certain testing limitations. Developers, DevOps and QA engineers who want to gain more load testing abilities can convert their Postman tests to JMeter. This blog post will explain when it is recommended to convert Postman to JMeter, and a step by step explanation of how to do it.
Postman API Testing Limitations
Postman tests don’t scale. If you have many requests in your collection, Postman/Newman will be executing them with 1 thread (user) and sequentially, instead of with multiple threads and in parallel.
Performance Testing Capabilities
Postman is not suitable for API performance testing due to scalability limitations. Performance tests require running tests for multiple threads (users) at the same time, to check that your system doesn’t break under heavy loads. Learn more here.
When to Convert Postman Tests to JMeter Tests
You may want to convert your existing Postman tests to JMeter to get the benefits of:
- Multithreaded execution
- Obtaining performance metrics for your API
- Getting advanced reporting and correlating increasing load with the increasing response time, number of errors, etc.
- Finding the bottlenecks and slowest API endpoints
How to Convert Postman API Tests to JMeter Tests
Here are the steps to convert your existing Postman tests into JMeter:
Step 1 - Prepare JMeter for Recording
JMeter comes with an HTTP(S) Test Script Recorder that acts as a proxy for the browser (or any other application that uses the HTTP protocol and supports proxy). Therefore, you can use it for intercepting requests generated by the browser. In our case, you can use it to intercept Postman, and convert the requests to HTTP Request samplers.
JMeter configuration is fairly simple—especially if you use the JMeter Templates Feature:
1. Go to the JMeter main menu and choose File -> Templates -> Recording and click “Create”.
2. Select HTTP(S) Test Script Recorder and click “Start”.
Step 2 - Prepare Postman for Recording
1. First, import the JMeter certificate into Postman. When you launch JMeter’s HTTP(S) Test Script Recorder, JMeter generates a self-signed certificate that allows JMeter to decrypt HTTPS requests. The file is called ApacheJMeterTemporaryRootCA.crt and it will begin generating under the “bin” folder of your JMeter installation.
2. Open the Postman settings and to to “Certificates” tab
3. Toggle On for “CA certificates” and locate ApacheJMeterTemporaryRootCA.crt
That’s it, now Postman will use JMeter’s certificate and JMeter will be able to decrypt captured requests
Configure Postman to Use JMeter as the Proxy
Now you need to “tell” Postman to send requests via JMeter’s HTTP(S) Test Script Recorder.
4. Go to Postman’s settings and open the “Proxy” tab.
5. Under Proxy configurations for sending requests tick “Add a custom proxy configuration” box.
6. Select both the “HTTP” and “HTTPS” protocols.
7. Use “localhost” as the proxy server (if you have JMeter running on the different host—use that host IP address or DNS hostname instead).
8. Use “8888” as the proxy port.
Step 3 - Record Your Tests
Congratulations! Postman and JMeter are finally connected. When you start your request or collection, JMeter will capture it and generate a HTTP Request sampler per request. If there are any HTTP Headers present JMeter will add a HTTP Header Manager to add the headers to the request.
Here is a small simple demo of how it should work:
Tips, Tricks and Limitations When Converting Postman to JMeter
Newman Command-line Recording
Windows operating system proxy settings are respected if you want to record your Newman tests on Windows. Therefore, it’s sufficient to perform the setup in Internet Explorer or Chrome browsers. This will set the system-wide proxy which will be used by Newman.
For Linux/Unix/MacOS the proxy can be supplied via HTTP_PROXY environment variable like:
HTTP_PROXY=http://localhost:8888 && newman -c your_collection.json
BlazeMeter Proxy Recorder
Instead of local JMeter proxy you can use the cloud-based BlazeMeter Proxy Recorder which:
- Simplifies certificate creation, especially when it comes to recording mobile applications traffic.
- Has feature of automated correlation of dynamic parameters. See the How to Cut Your JMeter Scripting Time by 80% article for more details.
Remember that this approach is only suitable for recording requests only. Any scripts that you have defined under the “Pre-req.” or “Tests” tabs in Postman will not be considered. So, if you have test data preparation or assertion logic you will need to replicate it using JSR223 Test Elements and Groovy language, like I’ve described in the Scripting JMeter Assertions in Groovy - A Tutorial article.