0% found this document useful (0 votes)
6 views3 pages

Postman_Scripting_Basics

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views3 pages

Postman_Scripting_Basics

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Postman Scripting Basics: Methods, Functions, and Variables

1. pm.test:

- Used to define a test that can be run on a request. It takes a test name and a function that runs

the test.

2. pm.response:

- Returns the response object for the request. Used to check the response's status, body,

headers, etc.

3. pm.environment:

- Allows accessing and modifying environment variables. Useful for storing values like

authentication tokens or base URLs.

4. pm.globals:

- Allows accessing and modifying global variables. These variables are shared across all requests

in a collection.

5. pm.variables:

- Returns the variable store that includes environment, global, and data variables. Allows access

to all variable types in Postman.

6. pm.request:

- Provides access to the request object for the current request. Useful for checking request

headers, body, and method before sending.


7. pm.collectionVariables:

- Provides access to collection-level variables. These are used across all requests within a specific

collection.

8. pm.expect:

- Assertion library used to write tests. It allows checking if the actual value matches the expected

value (e.g., status code, response body).

9. pm.sendRequest:

- Used to send another HTTP request from within the script. This is useful for making secondary

requests or API calls during tests.

10. pm.iterationData:

- Accesses the data file used in collection runner (when running with data). This is useful for

data-driven testing.

Postman Variables:

- **Environment Variables**: Variables specific to an environment (e.g., API base URL,

authentication token). Set through the Environment tab.

- **Global Variables**: Variables that are accessible throughout the entire Postman workspace. Set

through the Globals tab.

- **Collection Variables**: Variables specific to a Postman collection. Set via the collection settings.

- **Data Variables**: Variables supplied through the collection runner or data files (CSV, JSON).

- **Local Variables**: Variables scoped only to a specific request during runtime.

Common Functions in Postman Scripting:

- **pm.environment.set(name, value)**: Sets the value of an environment variable.


- **pm.globals.set(name, value)**: Sets the value of a global variable.

- **pm.request.headers**: Accesses the headers of the current request.

- **pm.response.json()**: Parses the response body as JSON and returns the parsed object.

- **pm.response.text()**: Returns the response body as raw text.

- **pm.response.status**: Returns the status code of the response.

You might also like