Thursday, June 6, 2024

API Testing Using Postman: Part 5

 Two types of scripts in postman:
  1. Pre-request script (It will run the script before execution)
  2. Test script (it will run the script after execution)
Order of execution:
 Pre-request --> Request --> Response--> Test script

Execute the pre-request script and test script in 3 levels.
  1. Collection level
  2. Folder level
  3. Request level
  • If we give scripts in pre-request and test scripts at all levels. The order will be executed in the following manner.
  • Collection -> Folder-> Request (until this pre-request) -> Request -> Response -> Collection -> Folder -> Test script.
Variables:
  • Variables are created to reduce the effort in updating data every time. In Postman, we are also creating variables to update data every time.
  • For example, some parts of the URL are common across all the requests ("https://localhost3000"). This can be stored in one variable and can be used anytime whenever we want.
  • If localhost number 3000 changes also, we can update the variable, it's a one-time update and can be updated everywhere.
Types of variables:
  1. Global - Accessible in Workspace
  2. Collection - Accessible within the collection.
  3. Environment - Accessible in all collections, but we need to switch to a particular environment.
  4. Local - Accessible only within the request (Specific to Request).

No comments:

Post a Comment