API Testing using Postman scripts

What is a test in Postman?

  • Pre-request Script: pre-request scripts used to execute before a request runs
  • Tests: allow you to ensure that your API is working as expected. Tests will execute after the response is received, so when you Send a request, Postman will run your test script when the response data returned from the API.
  • Global
  • Collection
  • Environment
  • Data
  • Local
  • Global variable: allow you to access data between collections, requests, test scripts, and environments. Global variables are available throughout a workspace.
  • Collection Variable: are available throughout the requests in a collection and are independent of environments.
  • Environment variables: allow you to tailor your processing to different environments.Only one environment can be active at a time
  • Local variables:are temporary, and only accessible in your request scripts
  1. $guid: generate uuid dynamically
  2. $randomAlphaNumeric: random alpha-numeric character
  3. $randomInt: random integer between 1 and 1000
  4. $randomIP: random IPv4 address
  5. $randomFirstName: random first name
  6. $randomLastName: random last name
  7. $randomPhoneNumber: random 10-digit phone number
  8. $randomCity: random city name
  9. $randomCompanyName : random company name
  10. $randomEmail: random email address
  • Setting headers:
  • If your request has any headers. You can take headers value from variables and can declare headers in the pre request section at collection,folder or request level.
  • Sending requests from scripts

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store