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).

API Testing Using Postman: Part 4

 Here we are validating 5 types of response in the output.
  1. Status code
  2. Headers
  3. Cookies
  4. Response time
  5. Response body
  • To test the above validations we have something called "Assertions" in Postman. Assertion is nothing but a validation point. To add this validation we have one library in Postman called "pm".In this, we have so many functions available. By adding some parameters to these functions we can validate the above responses.
Testing Headers:
  • We can check static values present in the header.
  • We are checking whether the text is present in the header as well as the text assigned to the header.
Testing Cookies:
  • Every time, the cookies we get are not constant. So we are using two types of assertions. One is to check whether that cookie is present and another is text present for that cookie.
Testing Response time:
  • We are checking whether the API is running in the expected time. we don't know the exact time every time, So we are giving min or max time to validate the time.
Testing Response body:
  • Sometimes the response in the body is not static values, it will be dynamic sometimes. So, we are validating only the static values or content in the response body.
validating the Response body in 3 categories.
  1. Validating the type of values.
  2. Validating the values assigned.
  3. Validating JSON Schema.

Monday, June 3, 2024

API Testing Using Postman: Part 3

HTTP vs HTTPS:
  • We have 2 types of URLs. One is HTTP and the other is HTTPS.
  1. HTTP(Hypertext transfer protocol) will give the data to the client without any security(without password encryption).
  2. HTTPS(Hyper Text transfer protocol secure) will give the data to the client with some security (password encryption).

  • URL is divided into 3 parts:
  1. URL: Uniform Resource Locator
  2. URI: Uniform Resource Identifier
  3. URN: Uniform Resource Name


Feature & Resource:
  • The feature is the term which is used in manual Testing to test some functionality. Resource is the term used in API Automation Testing referring to some functionality.
Payload: payload is the body HTTP Request and Response message.
Request payload: In the Request payload, we send the request in the request body using HTTP/HTTPS Request.
Response payload: In the response payload we will get the response in the format of HTTP Response which contains the status code, Response payload and string message.


Thursday, May 23, 2024

API Testing Using Postman: Part 2

  •  API helps to communicate between two different applications and also which are coded in 2 different languages.
  • For example, Google developed maps that contain open-source APIs. Maps are not only used by Google but also by different applications such as whatsapp, FB, snap etc.

  • API vs Webservice: API is a request which will be developed offline without using of public server and Webservice is also an API but it is deployed in the server and made available for the public.
  • All Webservices are API but all APIs are not Webservices.
  • An API is called a Webservice when an API is deployed in a public server and makes it available for everyone.
Two Types of API:
  1. Simple Object Access Protocol(SOAP). (XML format)
  2. REST(Representational State Transfer). (JSON, XML, etc.)
  • SOAP is a very old tool and it is difficult to understand the request and response sometimes.
  • Currently, we are using REST services. we have 4 major commands to request or to get the response.
  1. GET - used to get the requested info from the Database.
  2. POST - used to create a new item in DB.
  3. PUT - used to update the existing item in DB.
  4. DELETE - used to delete existing items from DB.


Friday, May 17, 2024

API Testing Using Postman: Part 1

Client and Server: The client is a computer or local machine which is from the user's end and the server is a place where the data is stored.



Client and server are divided into 3 categories.
  • 1-Tier -  It has only 1 client and 1 server.
  • 2-Tier -  It has multiple clients but contains only one server.
  • 3-Tier -  It will have 3 layers.
           Client(Presentation layer)[multiple clients]
           Business logic(Application layer)[multiple API's]
           Server(Data layer)[Multiple servers]



API - Application Programming Interface.
  •  Application - It works for a Web Application. It is called an Application Layer.
  • Programming - we will send API requests through code which are written in programming languages(Eg: java, python etc.).
  • Interface - It will act as an interface or communication barrier between client and server.


Uses of API Testing:
  • Generally, we test the UI using selenium and we check whether every functionality is working or not. But, when it comes to API Testing we send a request to the server based on the request it will give the response. In the response itself, we can check whether all the functionality is working or not. 80% of the Testing is completed within less time if you know API Testing and 20% will be testing the UI elements, colour buttons etc.
  • No need for UI Testing by 100%.If we perform API Testing.
  • We can perform API Testing once the backend code and the APIs are ready. A gap will occur between the presentation and Application layer(it will take time to create UI). In that time, we can test our application using API's. 
  • API Testing is simple and easy to learn compared to Selenium web application Testing.