banner



How To Pass Data From One Api To Another

Introduction

Every bit a part of theFinish to End REST Assured Tutorial, in this postal service, nosotros will learn to pass data from 1 API to another API.

Information is fundamental in API testing and we may require to laissez passer the output of ane API equally an input to another API. For example:- We get a booking id from Create Booking API. If we demand to recollect, update, partial update, or delete booking and so we must need to pass the booking id to these APIs.

We will employ TestNG equally a testing framework so that we can easily share data amidst test methods.

I have already covered Sharing Data Among Test Methods In TestNG Using ITestContext. In this mail service, I will explain the same concept with respect to Residuum Assured.

Required Dependencies

I have used Rest Assured and TestNG of the below versions:-

Interface ITestContext

Every bit per TestNG Javadoc, ITestContext is an interface that defines a exam context that contains all the information for a given examination run. An instance of this context is passed to the test listeners so they can query information near their environment.

ITestContext is a powerful interface that provides many useful methods. In this post, we will run across two of import methods setAttribute​(java.lang.Cord name, java.lang.Object value)  and getAttribute​(java.lang.String name) provided past ITestContext interface.

setAttribute()

setAttribute(atttributeName, attributeValue) – Set a custom attribute. Information technology is similar to calculation an element in a Map equally primal-value pair. Kindly pay attending here that aspect value tin be of any type. This is the reason this method accepts Object type as a value.

getAttribute()

getAttribute(attributeName) – Go the value of given attribute name. Call back render type is an Object.

How to use ITestContext?

ITestContext interface extends IAttributes interface. Instead of going theoretically, let'southward learn it using examples. Information technology volition make more than sense to you.

ITestContext reference is created once and can be used with the @Test annotated method past just passing it as a parameter. Whatsoever information y'all would like to use in other tests you just need to shop them in Exam Context using setAttribute() method. To remember stored information apply getAttribute() method.

We volition utilise Restful – Booker APIs for demo purposes. I have already covered many examples of these APIs in my RestAssured series.

Example Program

Output

You tin can download/clone the in a higher place sample projection from here.

You lot tin can subscribe to my YouTube channelRetargetCommon to learn from video tutorials.

If you have any uncertainty, feel free to comment beneath.
If you lot similar my posts, delight like, comment, share and subscribe.
#ThanksForReading
#HappyLearning

Find all Selenium related posts here, all API manual and automation related posts here, and detect ofttimes asked Java Programs hither.

Many other topics you tin navigate through the menu.

Author: Amod Mahajan

A software Tester who is paid to approximate products developed past others. Currently getting paid in American Dollars. Writing technical posts and creating YouTube videos are my hobbies.

Source: http://makeseleniumeasy.com/2021/01/27/rest-assured-tutorial-64-how-to-pass-value-from-one-api-to-another-api-using-testng-itestcontext/

0 Response to "How To Pass Data From One Api To Another"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel