Postman_Scripting_Basics
Postman_Scripting_Basics
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
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
6. pm.request:
- Provides access to the request object for the current request. Useful for checking request
- 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
9. pm.sendRequest:
- Used to send another HTTP request from within the script. This is useful for making secondary
10. pm.iterationData:
- Accesses the data file used in collection runner (when running with data). This is useful for
data-driven testing.
Postman Variables:
- **Global Variables**: Variables that are accessible throughout the entire Postman workspace. Set
- **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).
- **pm.response.json()**: Parses the response body as JSON and returns the parsed object.