Search GimmeJob

Type at least 2 characters. Enter also searches by meaning.
GimmeJob
Sign in
Testing tools: hands-on guides · Chapter 02 / 09

Testing Tools

Postman

Postman is a desktop and web API client. You build HTTP requests in a form, group them into collections, switch environments with variables, write JavaScript tests, and run the whole set from the Collection Runner or a CI pipeline. Recent versions also speak WebSocket, gRPC, GraphQL and MQTT. This chapter follows the current Postman UI (v12), where the sidebar has Items and new tabs open with the Add (+) button.

Key factDetails
InstallDesktop app for Windows, macOS and Linux from postman.com, or the web app with the Postman Desktop Agent
PlansA free plan exists. Collaboration features and usage limits depend on the plan, so check the current pricing page
Best forExploratory API testing, chained requests, contract checks, sharing ready-made requests with a team
Command linePostman CLI (recommended by Postman) or Newman
Request → save to a collection → move URLs and secrets into environment variables → add authorization at collection level → add post-response tests → run the collection (Runner / Postman CLI / Newman) → read the report → fix or file a bug

Sending a request: method, URL, params, headers and body

  1. Click Add (+) next to the open tabs and choose an HTTP request.
  2. Pick a method from the dropdown (GET, POST, PUT, PATCH, DELETE...) and enter the URL, for example postman-echo.com/get.
  3. Open Params and add query parameters as key/value rows. Postman keeps the URL in sync, so ?page=2&size=20 appears automatically.
  4. Open Headers to add headers such as Accept: application/json. Click hidden to see the headers Postman adds by itself (User-Agent, Postman-Token, Content-Length...).
  5. For POST/PUT/PATCH, open Body and choose a type: raw → JSON for APIs, form-data for file uploads, x-www-form-urlencoded for classic forms.
  6. Click Send. The response pane shows the status code, time and size, plus the Body (Pretty / Raw / Preview), Cookies, Headers and Test Results tabs.
Postman request builder and response pane
Official Postman documentation screenshot: the request builder with a Postman Echo response.
QA tip: Hover over the response time to see the breakdown into DNS lookup, TCP handshake, SSL handshake, waiting for the first byte and download. That breakdown is good evidence for "the API is slow" reports.

Collections, environments and variables

A collection is a folder tree of saved requests. An environment is a named set of variables, such as local, stage and prod, that you switch with one click.

  1. Save a request with Ctrl+S / Cmd+S → New Collection, give it a name and click Save.
  2. Create an environment: click Add (+) in the sidebar → Environments, or use the environment selector at the top right of the workbench.
  3. Add variables such as baseUrl, userEmail and apiKey. Click Secure next to the name for anything sensitive.
  4. Replace hard-coded values with variables in double curly braces: {{baseUrl}}/users/{{userId}}. Variables work in the URL, params, headers and body.
  5. Make the environment active: pick it in the selector at the top right, or click Set active next to it in the Environments list. Hover over {{baseUrl}} to see which value will be used.
Selecting the active environment in Postman
Official Postman documentation screenshot: the Environments list with the Set active action.

Each variable has a local value and an optional shared value. The local value is what Postman uses to send requests. It isn't synced to the Postman cloud and teammates don't see it. The shared value syncs to the workspace, so never put real tokens or passwords there.

If the same name exists in several scopes, the narrowest one wins. Environment variables override collection and global variables, and data-file and local variables override environment values.

Caveat: Name environments so that production is impossible to miss, and give production a red color. A collection run against the wrong environment is a classic way to create test data in production.

Authorization: Bearer, Basic, API key, OAuth 2.0 and inheritance

  1. Open the collection (click its name) → Authorization tab.
  2. Choose a type: Bearer Token, Basic Auth, API Key (header or query parameter), OAuth 2.0 and others.
  3. Use variables rather than literal values, for example token {{accessToken}}.
  4. In each request's Authorization tab, leave Inherit auth from parent. Every request then uses the collection settings, and you change the token in one place.
  5. For OAuth 2.0, fill in the grant type, auth URL, token URL, client ID and scopes, then click Get New Access Token. Postman stores the token, and you can refresh it when it expires.

For negative tests, duplicate a request and set its Authorization to No Auth (expect 401), or use an expired or low-privilege token (expect 401 or 403).

Scripts: pre-request setup and post-response tests

Each request, folder and collection has a Scripts tab with two editors: Pre-request (runs before sending) and Post-response (runs after the response arrives). Scripts are JavaScript using the pm object.

  1. Open a request → Scripts → Post-response.
  2. Click Snippets at the lower right of the editor and choose, for example, Status code: Code is 200.
  3. Add your own checks with pm.test and pm.expect. The examples below cover the most common ones.
  4. Click Send and open Test Results in the response pane. Use Filter Results to show Passed, Skipped or Failed.
  5. Open Console from the footer to see console.log() output and the raw request and response for each call.
pm.test("Status is 201", () => {
    pm.response.to.have.status(201);
});

pm.test("Response time under 800 ms", () => {
    pm.expect(pm.response.responseTime).to.be.below(800);
});

const body = pm.response.json();

pm.test("Created user has an id and the right email", () => {
    pm.expect(body.id).to.be.a("number");
    pm.expect(body.email).to.eql(pm.environment.get("userEmail"));
});

// Save a value for the next request in the chain
pm.environment.set("userId", body.id);

A Pre-request script prepares data, for example a unique email for every run:

pm.environment.set("userEmail", `qa+${Date.now()}@example.test`);
QA tip: Keep tests about the contract: status, required fields, types and business rules. Comparing the full body to a stored copy breaks on every harmless change, such as a new field or a different order.

Collection Runner, Postman CLI and Newman

Collection Runner (inside the app):

  1. Click Items in the sidebar → Collections, select a collection or folder, and click Run.
  2. Under Run type, choose Functional, then Local.
  3. Choose the environment at the upper right.
  4. Set Iterations. Under Iteration data, pick a Datafile (CSV or JSON) to run the same requests with different input rows. Each column becomes a {{variable}}.
  5. In Settings, add a delay between requests and decide whether to Stop run if an error occurs.
  6. Drag requests to change the order, or untick the ones to skip, then click Start run.
  7. Read the results: passed and failed tests per request, an Errors tab for runtime errors, and Console log for script output. In the desktop app, use View more actions → Export run results.
Collection Runner results in Postman
Official Postman documentation screenshot: Collection Runner results.

In CI, Postman recommends the Postman CLI. Install it with npm install -g postman-cli, and use Configure CI/CD in the Runner to generate the exact command for your workspace. Postman has announced that Newman won't receive further updates or fixes. Many pipelines still use it, though, and it runs exported collection files with no account at all:

npm install -g newman
newman run my-collection.json -e stage.postman_environment.json \
  -d users.csv -n 3 --bail -r cli,junit

--bail stops at the first failed test and makes Newman exit with code 1, so the CI job fails. -r junit writes a JUnit XML report that most CI servers can display.

WebSocket, gRPC, GraphQL and MQTT requests

The Add (+) menu offers request types beyond HTTP:

  • WebSocket: enter a wss:// URL, click Connect, write a message in Message and click Send. Incoming and outgoing frames appear in a timeline. This is useful for chat, notifications and live dashboards.
  • gRPC: enter the server address, load the service definition (server reflection or an imported .proto file), pick a method, edit the message and click Invoke.
  • GraphQL: Postman fetches the schema, so you can build the query with autocomplete and set variables in a separate pane.
  • MQTT: the steps below.

MQTT in Postman:

  1. Click Add and select MQTT.
  2. Enter the broker address, for example the public test broker broker.hivemq.com, and click Connect. In the web app this needs the Postman Desktop Agent.
  3. Open Topics, enter a topic such as gimmejob/qa-lab/#, and turn on Subscribe.
  4. Open Message, enter a topic such as gimmejob/qa-lab/sensor1 and a payload such as {"temp": 21.5}, then click Send. Because you're subscribed, the message appears twice: once outgoing and once incoming.
Connecting to an MQTT broker in Postman
Official Postman documentation screenshot: connecting an MQTT request to a broker.
Caveat: Public brokers are visible to everyone. Use a unique topic prefix and never publish real data. The MQTT chapter of this path covers QoS, retained messages and Last Will in depth.

Sharing, code snippets and Git-friendly alternatives

  • Import: paste a cURL command, an OpenAPI file or a HAR-derived request and Postman builds the request for you. This is the fastest way to turn DevTools' Copy as cURL into a saved request.
  • Code (</> icon in the right sidebar): generates the same request as cURL, Python requests, JavaScript fetch and other languages. It's a quick start for an automated test.
  • Export: collections export as JSON (Collection v2.1) and environments as separate JSON files. Remove secrets before you commit or send them.
  • Bruno is a free, open-source alternative that stores each request as a plain-text file in your repository. Request changes can then be reviewed in pull requests next to the code.

Cheat sheet

TaskHow
New requestAdd (+) → HTTP
Save to a collectionCtrl+S / Cmd+S
Use a variable{{baseUrl}}
Switch environmentSelector at the top right
One auth for all requestsCollection → Authorization, requests → Inherit auth from parent
Assert statuspm.response.to.have.status(200)
Save a valuepm.environment.set("token", value)
Debug scriptsFooter → Console
Data-driven runRunner → Iteration data → CSV/JSON
CI runPostman CLI or newman run collection.json -e env.json --bail
From browser to PostmanDevTools Copy as cURL → Postman Import
Hands-on lab: a chained, data-driven collection against Postman Echo

postman-echo.com returns whatever you send it, so you can practise without any backend.

  1. Create an environment named echo with the variable baseUrl = https://postman-echo.com and make it active.
  2. Create a collection Echo lab. Add request 1 – Login (fake): POST {{baseUrl}}/post, Body → raw → JSON, with the login body shown after this list.
  3. In its Scripts → Post-response, add the first script after this list. It saves the token for the next request.
  4. Add request 2 – Use token: GET {{baseUrl}}/headers. On the collection's Authorization tab choose Bearer Token with token {{token}}, and leave the request on Inherit auth from parent.
  5. In request 2's Post-response script, add the second script after this list.
  6. Add request 3 – Server error: GET {{baseUrl}}/status/500, with a test that expects status 500.
  7. Create users.csv with a header row user,token and two data rows: anna,token-anna and oleh,token-oleh. In the login body, use {{user}} and {{token}} instead of fixed values.
  8. Run the collection: Run → Functional → Local → Iteration data = users.csv → Start run. Both iterations must pass.
  9. Export the collection and the environment, then run them from a terminal with the command at the end of this lab.
{ "user": "qa", "token": "abc123" }
pm.test("status 200", () => pm.response.to.have.status(200));
pm.environment.set("token", pm.response.json().json.token);
pm.test("token was sent as Bearer", () => {
  const sent = pm.response.json().headers.authorization;
  pm.expect(sent).to.eql(`Bearer ${pm.environment.get("token")}`);
});
newman run "Echo lab.postman_collection.json" -e echo.postman_environment.json -d users.csv

Official Postman quick start · Collection runs

Summary

  • Build a request in the form, save it to a collection, and move every URL, user and secret into environment variables.
  • Set authorization once on the collection, and keep post-response tests focused on status, required fields and business rules.
  • Chain requests by saving values with pm.environment.set, and use the Collection Runner with a data file for data-driven checks.
  • Run collections in CI with the Postman CLI or Newman. Remember that Postman can also test WebSocket, gRPC, GraphQL and MQTT APIs.

Source registry

Verified 22 Nov 2026
Postman quick start

Sending a first request, saving to a collection and adding a status-code test

Postman · verified
Source ↗
Postman: Manage environments

Creating environments, local and shared values, Secure variables, scope precedence and {{variable}} syntax

Postman · verified
Source ↗
Postman: Write post-response scripts to test API response data

Scripts > Post-response, snippets, pm.test and pm.expect examples, Test Results filtering

Postman · verified
Source ↗
Postman: Run collections in the Collection Runner

Functional local runs, iterations, data files, run order, results and Postman CLI hand-off

Postman · verified
Source ↗
Postman: Run collections using Newman CLI

Newman installation, newman run syntax, --bail exit codes and the Postman CLI recommendation

Postman · verified
Source ↗
Postman: Create your first MQTT request

Connecting to a broker, subscribing to topics and publishing messages from Postman

Postman · verified
Source ↗
Bruno documentation

File-based, Git-friendly API collections as an alternative to cloud workspaces

Bruno · verified
Source ↗
MDN WebSockets API

WebSocket connection and message semantics behind WebSocket requests

Mozilla · verified
Source ↗