Use Postman collections to create Gatling load tests
Learn how to export Postman collections and use them as Gatling scenarios.
Prerequisites
- A Gatling Enterprise account sign up for a free trial here
- A Postman collection
Step 1: Export your Postman Collection
In your Postman workspace navigate to the collections menu and press the ellipsis button. At the bottom of the menu select the export option. Export your collection as a v2.1. This downloads a JSON file to your machine.
Step 2: Setup a Gatling JavaScript Project
If you don’t already have a Gatling JavaScript Project, head to the open-source downloads page to download it today.
Unzip the Gating JavaScript project and open it in your favorite IDE. The SDK has JavaScript and TypeScript folders. You can use either, but we will focus on JavaScript for the rest of this post.
Add your Postman collection to the javascript/resources
folder in the Gatling JavaScript project
Open the javascript/src
folder and create a file named postman.gatling.js
.
In the newly created file add the following JavaScript code:
import { simulation, constantUsersPerSec } from "@gatling.io/core";
import { http } from "@gatling.io/http";
import { postman } from "@gatling.io/postman";
export default simulation((setUp) => {
const httpProtocol = http;
const collection = postman
.fromResource("yourCollectionName.postman_collection.json");
const scn = collection.scenario("My Scenario", { pauses: 1 });
setUp(
scn.injectOpen(
constantUsersPerSec(1).during(60)
).protocols(httpProtocol)
);
});
- Change your
CollectionName
on line 9 to match the filename for your imported Postman collection. - Run the installation command to install all of the packages and dependencies:
npm install --save "@gatling.io/postman"
Step 3: Run your test on Gatling Enterprise
Remove the open-source test limits by running your test on Gatling Enterprise with a free trial account. To do so:
- Package your test by running the command
npx gatling enterprise-package
in your terminal. The packaged simulation is saved in thetarget
folder. - Log in to your Gatling Enterprise account.
- Click on Simulations in the left-side menu.
- Click on Create a simulation and follow the prompts to upload your package and create your simulation.
- Start your simulation and see the live results!