banner



How To Pass Data Using Put To Rest Service In Java

Introduction

Every bit a part of theStop to End REST Assured Tutorial, in this mail service, nosotros will learn to pass data from one API to another API.

Information is key in API testing and we may require to pass the output of one API as an input to another API. For example:- We go a booking id from Create Booking API. If nosotros need to retrieve, update, partial update, or delete booking then we must demand to laissez passer the booking id to these APIs.

We will use TestNG as a testing framework so that nosotros can easily share information among test methods.

I accept already covered Sharing Data Amidst Test Methods In TestNG Using ITestContext. In this postal service, I will explicate the aforementioned concept with respect to Residue Assured.

Required Dependencies

I have used Remainder Bodacious and TestNG of the below versions:-

Interface ITestContext

As per TestNG Javadoc, ITestContext is an interface that defines a test context that contains all the information for a given test run. An instance of this context is passed to the test listeners and then they tin can query information about their surroundings.

ITestContext is a powerful interface that provides many useful methods. In this mail service, we will see two important methods setAttribute​(java.lang.Cord name, java.lang.Object value)  and getAttribute​(java.lang.String name) provided by ITestContext interface.

setAttribute()

setAttribute(atttributeName, attributeValue) – Ready a custom aspect. Information technology is similar to calculation an element in a Map every bit key-value pair. Kindly pay attention here that attribute value can be of any type. This is the reason this method accepts Object type as a value.

getAttribute()

getAttribute(attributeName) – Get the value of given attribute name. Remember render type is an Object.

How to use ITestContext?

ITestContext interface extends IAttributes interface. Instead of going theoretically, permit's learn information technology using examples. It volition brand more sense to y'all.

ITestContext reference is created one time and can be used with the @Exam annotated method by only passing it as a parameter. Whatsoever data you would like to apply in other tests you simply need to store them in Test Context using setAttribute() method. To recollect stored information employ getAttribute() method.

Nosotros will use Restful – Booker APIs for demo purposes. I have already covered many examples of these APIs in my RestAssured serial.

Instance Program

Output

You can download/clone the above sample project from hither.

You can subscribe to my YouTube channelRetargetCommon to larn from video tutorials.

If you accept any doubt, experience free to comment below.
If yous like my posts, please similar, comment, share and subscribe.
#ThanksForReading
#HappyLearning

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

Many other topics you can navigate through the menu.

Author: Amod Mahajan

My name is Amod Mahajan and I am an IT employee with 6+ years of feel in Software testing and staying in Bengaluru. My expanse of interest is Automation testing. I started from basics and went through so many selenium tutorials. Thanks to Mukesh Otwani every bit his tutorials are piece of cake and cover basics to advance. I accept habit of exploring concepts by deep diving. I used to brand notes. I thought of sharing my knowledge through posts and at present I am here. #KeepLearning #ShareLearning

How To Pass Data Using Put To Rest Service In Java,

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

Posted by: buellthisced.blogspot.com

0 Response to "How To Pass Data Using Put To Rest Service In Java"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel