Data Driven API Testing Using Rest Assured

Data Driven API Testing Using Rest Assured

In this session, we would be looking into how we can perform the data-driven tests while doing API Testing using Rest assured.

As we all understand data-driven testing is an integral and important part while designing any testing framework as it helps us to segregate our test data from the code. 


So whenever any change happens in the data we don’t need to go and update that in code instead, we can update test data in our the source where we have kept it (Test Data can be kept either in excel or in some configuration or class files inside our project).

So In this session, we would be continuing doing some data driven test with One Sample API that we already have worked in our previous session.



As you have observed in my last blog we have done the hard coding of our Base URI and also every time when doing post requests we are taking the body from our code which is not good practice and should be avoided. Below is the code snapshot from my last blog.


In this session, we would be looking into two approaches of doing the Data-Driven Test while doing API Testing

ü  Using Properties or Configuration file
ü  Using Class File

Approach 1:

For Reading test data from Properties or configuration the file we can perform below steps




1)  Inside project main Folder under Configuration or any other Package of your choice create one text file with extension as .properties in this example I am creating one file named as Config.properties


2)  In these properties, the file declares the value in Key, value format of our Base URI.

3)  In project Base Class or in same test Class, declare one Properties variable and provide the path of .properties file along with below code snapshot.


4)  Now we are ready to use our Properties file inside test classes using below syntax.
pro.getProperty("BaseUrl");

Here, the getProperty method will take the Key of the property as a parameter and return the value of the matched key from the .properties file.


Approach 2:

Similarly for reading data from Another Class file we could follow the below steps:



1)  Inside project main Folder under Resources or any other Package of your choice create one class file let’s say TestResources.java


2)  In this Class create one static function and declare the body which we want to put in request and return that string.


3)  Finally Call this function inside our test class using
    classname.function name

The final Code for the API would look like below. If we observed carefully this code is much cleaner and easy to maintain than my last code.







SHARE THIS

Author:

My Name is Ankur Jain and I am currently working as Automation Test Architect.I am ISTQB Certified Test Manager,Certified UI Path RPA Developer as well as Certified Scrum Master with total 12 years of working experience with lot of big banking clients around the globe.I love to Design Automation Testing Frameworks with Selenium,Appium,Protractor,Cucumber,Rest-Assured, Katalon Studio and currently exploring lot in Dev-OPS as well. I am currently staying in Mumbai, Maharashtra. Please Connect with me through Contact Us page of this website.

Previous Post
Next Post
September 15, 2019 at 3:32 AM

Who approaches? Who claims it (don't make a presumption here))? By what means will it be conveyed back so you can move it to a contender's foundation?ExcelR Data Science Courses

Reply
avatar
February 18, 2020 at 2:10 PM

Such a very useful article. Very interesting to read this article.I would like to thank you for the efforts you had made for writing this awesome article.
360DigiTMG artificial intelligence course in hyderabad

Reply
avatar
May 6, 2020 at 5:59 PM

wonderful article. Very interesting to read this article.I would like to thank you for the efforts you had made for writing this awesome article. This article resolved my all queries.
Data Science Course

Reply
avatar
June 11, 2020 at 1:58 PM

This post is very simple to read and appreciate without leaving any details out. Great work!
Data Science Certification in Bangalore

Reply
avatar
June 12, 2020 at 10:37 PM

Admiring the time and effort you put into your blog and detailed information you offer!..
Data Science Course in Bangalore

Reply
avatar
June 12, 2020 at 10:37 PM

I would like to say that this blog really convinced me to do it! Thanks, very good post.
Data Science Training in Bangalore

Reply
avatar
June 16, 2020 at 3:38 PM

Very interesting to read this article.I would like to thank you for the efforts you had made for writing this awesome article. This article inspired me to read more. keep it up.
Correlation vs Covariance
Simple linear regression

Reply
avatar
June 27, 2020 at 2:07 PM

Hello, I have browsed most of your posts. This post is probably where I got the most useful information for my research. Thanks for posting, maybe we can see more on this. Are you aware of any other websites on this subject. free instagram likes instantly without password

Reply
avatar
July 3, 2020 at 8:06 PM

Such a very useful article. Very interesting to read this article. I would like to thank you for the efforts you had made for writing this awesome article.
Data Science Course in Pune
Data Science Training in Pune

Reply
avatar
July 4, 2020 at 4:30 PM

Awesome blog. I enjoyed reading your articles. This is truly a great read for me. I have bookmarked it and I am looking forward to reading new articles. Keep up the good work!
Data Science Institute in Bangalore

Reply
avatar
July 4, 2020 at 5:31 PM

Very interesting blog. Many blogs I see these days do not really provide anything that attracts others, but believe me the way you interact is literally awesome.You can also check my articles as well.

Data Science In Banglore With Placements
Data Science Course In Bangalore
Data Science Training In Bangalore
Best Data Science Courses In Bangalore
Data Science Institute In Bangalore

Thank you..

Reply
avatar
July 4, 2020 at 9:22 PM

I am really enjoying reading your well written articles. It looks like you spend a lot of effort and time on your blog. I have bookmarked it and I am looking forward to reading new articles. Keep up the good work.
Data Science Certification in Bangalore

Reply
avatar
July 5, 2020 at 6:53 PM

You completed a number of nice points there. I did a search on the issue and found nearly all people will have the same opinion with your blog.
Data Science Training in Bangalore

Reply
avatar
July 9, 2020 at 5:39 PM

This is a wonderful article, Given so much info in it, These type of articles keeps the users interest in the website, and keep on sharing more ... good luck. data science training in coimbatore

Reply
avatar
July 11, 2020 at 12:21 PM

Really nice and interesting post. I was looking for this kind of information and enjoyed reading this one. Keep posting. Thanks for sharing.

data science interview questions

Reply
avatar
July 28, 2020 at 3:05 PM

Excellent Blog! I would like to thank for the efforts you have made in writing this post. I am hoping the same best work from you in the future as well. I wanted to thank you for this websites! Thanks for sharing. Great websites!

data science interview questions

Reply
avatar
July 28, 2020 at 7:54 PM


This post is great. I reallly admire your post. Your post was awesome.
data science course in Hyderabad

Reply
avatar
July 30, 2020 at 1:11 AM

I feel a lot more people need to read this, very good info!.Learn best Data Science Course in Hyderabad

Reply
avatar
July 30, 2020 at 1:19 AM

Really nice and interesting post. I was looking for this kind of information and enjoyed reading this one. Keep posting. Thanks for sharing.Learn best Business Analytics Course in Hyderabad

Reply
avatar
July 30, 2020 at 1:29 AM

I feel really happy to have seen your post and look forward to so many more interesting post reading here. Thanks once more for all the details.Learn Best Data Science Training in Hyderabad

Reply
avatar
July 30, 2020 at 11:38 AM

Very interesting to read this article.I would like to thank you for the efforts you had made for writing this awesome article. This article inspired me to read more. keep it up.
Correlation vs Covariance
Simple linear regression
data science interview questions

Reply
avatar
August 4, 2020 at 8:49 AM

Big data is a term that describes the large volume of data – both structured and unstructured – that inundates a business on a day-to-day basis. big data projects for students But it’s not the amount of data that’s important. Project Center in Chennai It’s what organizations do with the data that matters. Big data can be analyzed for insights that lead to better decisions and strategic business moves.

Spring Framework has already made serious inroads as an integrated technology stack for building user-facing applications. Corporate TRaining Spring Framework the authors explore the idea of using Java in Big Data platforms.
Specifically, Spring Framework provides various tasks are geared around preparing data for further analysis and visualization. Spring Training in Chennai


The Angular Training covers a wide range of topics including Components, Angular Directives, Angular Services, Pipes, security fundamentals, Routing, and Angular programmability. The new Angular TRaining will lay the foundation you need to specialise in Single Page Application developer. Angular Training

Reply
avatar