How to convert Postman API tests to JMeter for scaling

Many test engineers use Postman for API test automation. They discover endpoints, make requests, create test data, run regression tests, implement continuous integration for API testing using Newman, etc. However, Postman has certain testing limitations. Developers, DevOps and QA engineers who want more load testing capabilities can convert their Postman tests to JMeter. This blog post will explain when it is recommended to convert Postman to JMeter and provide step-by-step instructions on how to achieve it.

Postman API Testing Limitations

Scalability

Postman tests don't scale. If you have a lot of requests in your collection, Postman/Newman will use 1 thread (user) and execute those requests sequentially instead of using multiple threads to execute concurrently.

Performance testing capabilities

Postman is not suitable for API performance testing due to scalability limitations. Performance testing requires running tests against multiple threads (users) simultaneously to ensure the system does not interrupt under heavy load.

When to convert Postman tests to JMeter tests

You may wish to convert existing Postman tests to JMeter to gain the following benefits:

  • Multi-threaded execution
  • Get API performance metrics
  • Get advanced reporting and correlate increasing loads with response times, number of errors, and more.
  • Find bottlenecks and slowest API endpoints

How to convert Postman API tests to JMeter tests

Here are the steps to convert existing Postman tests to JMeter:

Step 1 - Prepare JMeter for recording

JMeter comes with an HTTP(S) test script recorder, which acts as a proxy for the browser (or any other application that uses the HTTP protocol and supports proxies). Therefore, you can use it to intercept requests generated by the browser. In our case, you can use it to intercept Postman and convert the request into an HTTP Request sampler.

The configuration of JMeter is very simple - especially when using the JMeter template feature:

1. Go to JMeter main menu and select "File" -> "Template" -> "Record" and click "Create".

2. Select HTTP(S) Test Script Recorder and click Start.

3. Provide your API host so JMeter will place it under HTTP Request Defaults .

 

Step 2 - Prepare Postman for Recording

1. First, import the JMeter certificate into Postman. When you start 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, which will start generating under the "bin" folder of your JMeter installation.

2. Open Postman settings and go to the Certificates tab

3. Switch to "CA Certificate" and find
ApacheJMeterTemporaryRootCA.crt

That's it, now Postman will use JMeter's certificate and JMeter will be able to decrypt the captured request

Configure Postman to use JMeter as proxy

 

Now you need to "tell" Postman to send the request via JMeter's HTTP(S) test script recorder.

4. Go to Postman’s settings and open the “Agent” tab.

5. Under the proxy configuration used to send requests, check the "Add custom proxy configuration" box.

6. Select the "HTTP" and "HTTPS" protocols.

7. Use "localhost" as proxy server (if you have JMeter running on a different host - use that host's IP address or DNS hostname instead).

8. Use “8888” as proxy port.

Step 3 - Document your tests

congratulations! Postman and JMeter are finally connected. When you start a request or collection, JMeter will capture it and generate an HTTP request sampler for each request. If any HTTP headers are present, JMeter will add an HTTP header manager to add the headers to the request.

Here's a small example of how it works:

 

Tips, tricks and limitations when converting Postman to JMeter

Command line logging

If you want to record Newman tests on Windows, follow the Windows operating system proxy settings. Therefore, it is enough to perform the settings in Internet Explorer or Chrome browser. This will set up the system level proxy that Newman will use.

For Linux/Unix/MacOS, the proxy can be provided via the HTTP_PROXY environment variable, for example:

HTTP_PROXY = http:// localhost:8888 && newman -c your_collection.jso

BlazeMeter Agent Logger

Instead of a local JMeter agent, you can use the cloud-based BlazeMeter agent logger , which :

  • Simplify certificate creation, especially when logging mobile application traffic.
  • It has the function of automatic association of dynamic parameters.

limitation

Keep in mind that this approach only works with logging-only requests . All scripts you define under "Prerequisites". Or the "test" tag in Postman will not be considered. So if you have test data preparation or declaration logic, you need to replicate it using JSR223 test elements and the Groovy language.

 

Thank you to everyone who reads my article carefully. There is always a courtesy. Although it is not a very valuable thing, if you can use it, you can take it directly:

These materials should be the most comprehensive and complete preparation warehouse for [software testing] friends. This warehouse has also accompanied tens of thousands of test engineers through the most difficult journey. I hope it can also help you! Anyone in need Partners can click on the small card below to receive it  

Guess you like

Origin blog.csdn.net/okcross0/article/details/132811782