Postman

Use your Postman collections in Gatling load tests

Postman is a collaborative platform for testing and documenting APIs. Check the Postman official documentation for more details.

License and limitations

The Gatling Postman component is distributed under the Gatling Enterprise Component License.

Gatling Postman can be used with both the Open Source and Enterprise versions of Gatling.

Its usage is unlimited when running on Gatling Enterprise. When used with Gatling Open Source, usage is limited to:

  • 5 users maximum
  • 5 minute duration tests

Limits after which the test will stop.

Scope of Postman support

Postman support is only available for the JavaScript/TypeScript DSL for Gatling; it is not available in Java, Kotlin, or Scala. If you are interested in a JVM implementation, submit a request on the public roadmap.

The Gatling Postman component currently supports most features needed to import a Postman collection and run simple requests defined therein. However, it does not yet support:

  • Integrating with Postman Cloud: collections and environments must be exported to JSON files.
  • Running pre-request or post-response scripts.
  • Modifying variable values during execution or injecting them from data files.
  • Dynamic variables.
  • Request authorizations (e.g. Basic Auth, Bearer Token, etc.) and settings (e.g. disable follow redirects, etc.).

For requests which include file uploads, we currently support loading them from the project’s resources folder as if they were in Postman’s working directory. In other words: in Postman, select files from your working directory; then copy those files to your Gatling project’s resources folder.

Installation

Getting started with the demo project

A demo project is available with JavaScript and TypeScript test examples:

Adding the Gatling Postman dependency

You can also add Gatling Postman to an existing Gatling project written in JavaScript or TypeScript. In that case:

  1. Add the Gatling Postman dependency:

    npm install --save "@gatling.io/postman"
    
  2. Copy your exported Postman files (collection, and optionally environment and global variables) to the resources folder.

For more details on how to create a JavaScript or TypeScript project, check the dedicated tutorial.

DSL overview

The Gatling Postman support works as an extension for Gatling’s HTTP protocol; it generates requests or scenarios which are compatible with Gatling’s HTTP protocol. Here is an example of a Gatling simulation using a request imported from a Postman Collection. Like all Gatling simulations, it should be defined in a file ending in .gatling.js (JavaScript) or .gatling.ts (TypeScript):

import { simulation, scenario, atOnceUsers } from "@gatling.io/core"; // 1
import { http } from "@gatling.io/http"; // 1
import { postman } from "@gatling.io/postman";

export default simulation((setUp) => { // 2
  const httpProtocol = http; // 3

  const collection = postman
    .fromResource("My Collection.postman_collection.json");

  const scn = scenario("My scenario").exec( // 4
    // Manually defined HTTP request (not using Postman):
    http("My HTTP request").get("http://example.com"),
    // HTTP request generated from the Postman collection: 
    collection.request("My Postman request"),
  );

  setUp(scn.injectOpen(atOnceUsers(1))).protocols(httpProtocol); // 5
});
  1. The Gatling core and HTTP imports are used for all functionalities not specific to Postman.
  2. As for all JavaScript tests, define a simulation function.
  3. Gatling Postman uses the standard Gatling HTTP protocol.
  4. It is possible to perform Postman requests inside an existing Gatling test.
  5. Don’t forget to set up an injection profile.

DSL reference

Import Postman

Add the following import statement in your simulation file:

import { postman } from "@gatling.io/postman";

Import collections

You can import a collection file, exported from Postman, from the project resources (by default, from the resources folder):

const collection = postman.fromResource("My Collection.postman_collection.json");

You can inject a Postman environment:

// Import environment from exported JSON file:
collection.environment("My Environment.postman_environment.json");
// Import environment from a JavaScript object:
collection.environment({ "key 1": "value 1" });

You can also inject global variables:

// Import global variables from exported JSON file:
collection.globals("My Globals.postman_globals.json");
// Import global variables from a JavaScript object:
collection.globals({ "key 1": "value 1" });

Variables used in your Postman collection will be substituted with values from the collection, environment, and global variables, according to Postman’s variable scopes. Note that this currently only happens when requests are generated; Postman variable values cannot yet be modified during the Gatling simulation execution.

Create Gatling requests and scenarios

If the Postman collection is organized with folders, you can navigate with the folder function:

collection.folder("My Folder");
// Refers to the request "My Request" inside the folder "My Folder":
collection.folder("My Folder").request("My Request");

You can generate individual Gatling HTTP requests from Postman requests:

collectionOrFolder.request("My Request");
// Override the request name shown in Gatling reports:
collectionOrFolder.request("My Request", "Overridden Request Name");

You can generate an entire Gatling scenario, which will execute all requests defined in the current Postman folder (or collection root) one after the other:

collectionOrFolder.scenario("My Scenario");
// Add pauses between requests (duration in seconds):
collectionOrFolder.scenario("My Scenario", { pauses: 1 });
// Add pauses between requests (specify time unit):
collectionOrFolder.scenario("My Scenario", { pauses: { amount: 1, unit: "seconds" }});
// By default, only requests defined directly at the current level are included.
// Use the `recursive` option if you want to include all requests defined in
// sub-folders (at any depth):
collectionOrFolder.scenario("My Scenario", { recursive: true });

By default, only requests defined directly at the current level are included. Use the recursive option if you want to include all requests defined in sub-folders (at any depth).

Edit this page on GitHub