Showing posts with label API Testing. Show all posts
Showing posts with label API Testing. Show all posts

Monday, August 5, 2019

How to Retrieve Response Data and store it in variables?

How to Retrieve Response Data and store it in variables?

While working with Postman, sometimes we come across some situations where we need to use the Response data of say Request 1 as an input to Request 2 and so on. This process of reusing the data in other requests is called as Chaining.

To get started with Chaining. first thing to know is how to store the re-usable response data in variables.

Have a look at the screenshot below:

In the above screenshot, I have used a dummy API request for testing purpose. Here while hitting "/posts" we will get all the posts data as a response for the request we have made.

Now, suppose we have an another API where we need to pass a particular posts "id" as an input to get the details of the same. Let's see how to achieve this.



Here, we have written some tests in "Test Scripts" tab. Let's see what these lines of code is doing:

pm.environment.clear() - This clears all the environment variables of the specific environment say we are using "QA" environment, so this line of code will clear all the variables from the "QA" environment.

var response = JSON.parse(responseBody) - Here, we are declaring a variable name "response" and we're storing the response of the API in this variable.

pm.environment.set("id", response[0].id) - This line of code is setting an environment variable with name i.e variable key as "id" and as the response is in the form of array, we're getting the post id from the "0th" index and storing in the id variable here.

Thursday, August 1, 2019

API Testing via Postman

API Testing via Postman

Introduction

In my previous post, we have seen some few things to know before starting API testing. It's recommended to go though my previous post before proceeding with this article. Here is the link for your quick reference. https://bit.ly/2KjFqYN

Postman is a popular API Development and testing tool. It is available for Windows, Mac OS , Linux. Postman can be downloaded as a chrome plugin (which is deprecated now) hence its recommended to switch to the Native Postman App. You can download the native app from Postman Website.


Initial Steps
  • Download latest version of Postman native app and Launch the application.
  • Once you Launch the application, you'll see a window having an option to login / signup.



  • Or if you are thinking to skip this signup step, then at the bottom of the page you'll see an option "Skip signing in and take me straight to the app", by choosing this option you can continue using the app without creating an account with Postman.
  • But, it's good to create an account / sign in initially so that all your work progress can be synced to your account and you'll not loose anything.
  • Once you sign in you'll taken straight to the application. 

  • Here you'll see many options and you can de-select the checkbox at the bottom left corner (shown in the image above) so that this window will not appear again when you launch the Postman app.

Making our First Request

Once you close the pop-up you'll see a screen similar to a one you see below.


In the above image, there are some areas marked with numbers. The area which is marked as "1." there we can give a "Name to the request". "2." is where we need to enter the "Request URL" and "3." is the "Send" button which will help to build the request.

For testing purpose, we have used https://httpbin.org/ to make request.



Here we have made a GET request and after clicking on Send the request has been built and we got the response back from the server i.e the user-agnet in this particular case.

In next article we'll learn about more HTTP requests and related information.

Wednesday, July 17, 2019

Starting API Testing? - Here are the few things to know before you start!

What is an API?

API stands for Application Programming Interface. It's an interface responsible for communication / data transfer between two different software applications.

There are mainly two types of Web Services:

  • REST (Representational State Transfer)
  • SOAP (Simple Object Access Protocol)

REST stands for Representational State Transfer, which provides an ability of exchanging information between the the applications. These web services provide a predefined set of stateless operations and allow requesting applications to access and manipulate the data.

SOAP stands for Simple Object Access Protocol, which allows exchange of meaningful information between the applications using XML. It helps in exchanging structured information.

HTTP Methods

HTTP stands for Hyper Text Transfer Protocol is an application protocol for distributed and collaborative information systems.

HTTP defines some set of methods to indicate the expected action to be performed for a given resource. Each of them implement a different logic, but some common characteristics are shared by group of them. eg; a request can be idempotent or non-idempotent.

GET 
GET method is used when we need to retrieve the data. For simple understanding, it's like a Select command in SQL.This request doesn't result in modification of the data. If the request is successful, the status code of 200(OK) is received along the data in a particular JSON or XML format. This method is idempotent, i.e no matter how many times you make the request, there won't be any change in the data.

POST
POST method is used when we need to make manipulation of the data. Mostly, it is used to create a resource. When this request is made, a new resource gets created and if it's a successful requests a status code of 201(CREATED) is received. This method is non-idempotent, i.e this may result in duplicates or errors if called more than once.

PUT
PUT method is used when we need to make manipulation of the data. Mostly, it is used to update a existing resource. It maybe used to create a resource is request is made from client side. When this request is made, a new resource gets created and if it's a successful requests a status code of 201(CREATED) is received. This method is idempotent, i.e no matter how many times you make the request, there won't be any change in the data.

DELETE
- DELETE method is used to delete a resource. On a successful request, a status code of 200(OK) is received. This method is also idempotent as if a resource is deleted once it cannot affect it no matter how many times the request is made.

HTTP Response Codes

HTTP response codes fall under following categories:

1xx - Response code series starts with '1' are Informational codes.
2xx - Response code series starts with '2' are Success codes
3xx - Response code series starts with '3' are Redirection codes
4xx - Response code series starts with '4' are Client side error codes
5xx - Response code series starts with '5' are Server side error codes


Featured Post

API Automation using Newman - Part II

HTML Report via Newman In previous post we have seen how to setup Newman and execute the collections via Newman in command line. Ne...