Knowledgebase

Load Testing with Postman


Background

Postman is one of the best-in-market tools for functional testing of APIs. Postman makes it easy for you to develop, document, and test your APIs. But what about when you want to test those APIs beyond single requests. That is where the Load Impact Postman converter can help.

The Postman to Load Impact converter allows you to utilize your Postman collections as load tests on the Load Impact platform. Specifically, you can convert them to either a Lua(Load Impact 3.0) based or JavaScript(Load Impact 4.0) based script for use with the Load Impact platform. You can then execute these scripts within the context of a load test, where you decide how many virtual users, length of test, and ramping profile.

Note: this article is about Load Impact 3.0. If you are looking for Load Impact 4.0, click here

How to use the converter

Note: Please be sure to sign up for a free Load Impact account!

1 - Install the Command Line Tool.

Load Impact provides CLI tools to convert your Postman tests to both versions of our platform:

2 - As a Postman user, you organize your API tests into collections of requests. First, you have to export your Postman collections.

Download Postman collection

3 - Use the command line to convert the Postman collection: postman-to-loadimpact path/my-collection.json -o path/my-collection.lua postman-to-k6 path/my-collection.json -o path/k6-script.js

4 - Only LUA tests/scripts: Copy the content of the command output into a new or existing user scenario in Load Impact.

5 - Based on your script, you may need to do some additional scripting for it to validate. Here are common cases:

5.1 - Assign Lua variable values. The transformer will convert variables as:

1
2
3
4
5
    
    `{{url}}/repos/{{username}}/{{repository}}/contributors`
    ..url.."/repos/"..username.."/"..repository.."/contributors
    
    

At the top of the script, we have auto-generated variables. You must assign values to these. If these are dynamic, you may wish to use a Data Store

1
2
3
4
      local url = YOUR_VALUE
      local username = YOUR_VALUE
      local repository = YOUR_VALUE
  

5.2 - Replicate the behaviour defined in your Postman pre-request and response test.

This code will be inserted as a comment before and after the Lua request.

1
2
3
4
5
      --[[
      tests["Body matches string"] = responseBody.has("API endpoint authorized");
      tests["Status code is 200"] = responseCode.code === 200;
      --]]
  

You could easily replace the code to simulate this behaviour:

LUA tests using the Load script API

1
2
3
4
5
6
7
8
9
10
11
      if response.status_code ~= 200 then
        log.error("Status code is 200")
         -- or
        result.custom_metric("Status code is 200", 1)
      end
      if not string.find(response.body, "API endpoint authorized") then
        log.error("Body does not match")
        -- or
        result.custom_metric("Body does not match", 1)
      end
  

k6 tests using the k6 API.

1
2
3
4
      check(res, {
        "status was 200": (r) => r.status == 200
      });
  

6 - Validate your script and run your test!

See also: