Session 1: API Testing | RestAssured | Introduction | E… — Transcript

Introduction to Rest Assured for automating REST API testing, covering setup, prerequisites, and basic HTTP methods.

Key Takeaways

  • Rest Assured is a specialized API/library designed exclusively for REST API automation.
  • Setting up Rest Assured requires Java, Eclipse, TestNG, and Maven, with modern Eclipse simplifying Java installation.
  • TestNG enhances test management and execution features for Rest Assured tests.
  • Rest Assured supports BDD style test writing natively without extra Cucumber setup.
  • Basic HTTP methods like GET, POST, DELETE, and PUT are fundamental operations automated using Rest Assured.

Summary

  • Introduction to Rest Assured as an API/library for automating REST API testing.
  • Explanation of Rest Assured supporting only REST APIs and not other API types.
  • Prerequisites include Java, Eclipse IDE, TestNG framework, and Maven integration.
  • Java is bundled with modern Eclipse versions, simplifying setup.
  • TestNG is used for test suite management, parameterization, and running multiple tests.
  • Maven comes integrated with Eclipse for dependency management, including Rest Assured jars.
  • Rest Assured supports BDD style test writing without needing additional Cucumber plugins.
  • Instructions on downloading and installing Java and Eclipse.
  • Basic HTTP methods covered include GET, POST, DELETE, and PUT requests.
  • Overview of importing necessary packages and structuring tests with given-when-then syntax.

Full Transcript — Download SRT & Markdown

00:02
Speaker A
Right, so from today, we are going to start Rest Assured. Using Rest Assured, we can automate REST APIs. So today, we will see an introduction, what is Rest Assured, and how to install the setup, like what are the prerequisites required. Then we will see the basic operations, how we can send GET requests, POST requests, DELETE, and PUT requests. Okay, some basic request types we will see.
00:23
Speaker A
we can send get a request post request delete and put request okay some basic request type we will see so what is rest threshold so rest assured itself is an API through which we will able to automate rest apis okay so this is the definition so restoration is an API registration is also an
00:45
Speaker A
So what is Rest Assured? Rest Assured itself is an API through which we will be able to automate REST APIs. Okay, so this is the definition. So Rest Assured is an API. Registration is also an API, and Rest Assured will provide a certain number of methods. So when you call those methods, it will perform some actions or perform some requests. So Rest Assured is an API through which we can automate REST APIs. Okay, so through which we can automate REST APIs only. REST APIs will be supported; other types of APIs will not be supported. It is designed only for REST APIs.
01:07
Speaker A
rest apis only rest apis will be supported other type of APs will not be supported is it designed only for rest apis so rest ratio is an API through which we can automate rest API so to use it uh what are the prerequisites so basically the rest assured uh is kind of a API
01:29
Speaker A
So Rest Assured is an API through which we can automate REST APIs. So to use it, what are the prerequisites? So basically, Rest Assured is kind of an API, or it can be said it is a library. Okay, we can also call it a library API or you can say library, just like Selenium WebDriver. So how we work with Selenium WebDriver, we just download some jar files and then attach them to the Eclipse project, and then we get additional classes and methods, right? Similarly, Rest Assured is also an API or a library, and we have to download those jar files and then attach them to your project so that we will get some additional classes and methods from Rest Assured. By using those methods and classes, we will be able to automate REST APIs, and we will be able to send different types of requests. We will be able to validate the responses. So all these things are possible using Rest Assured.
01:41
Speaker A
Webdriver so we'll just download some jar files and then we will attach them to the eclipse project and then we will get additional classes and methods right similarly rest issue is also an API or a library and we have to download those jar files and then we have to attach them to your
01:59
Speaker A
So Rest Assured is an API or library through which we can automate REST APIs. Okay, that's a definition. Now, what are the prerequisites which we need to have to work with Rest Assured? Prerequisites, what are the basic installations which we need to have?
02:16
Speaker A
possible using rest API so rest assured is an API or Library through which we can automate rest apis okay that's a definition now what are the prerequisites which which we need to have to work with the rest assured prerequisites what are the basic installations which we need to have
02:37
Speaker A
So the prerequisite to work with Rest Assured, the first thing is you need to have Java and Eclipse or other than Eclipse, any editor is fine. So basically, most of the times, we use Java and Eclipse combination. So you need to have Java and Eclipse. Again, Java is optional because when you install Eclipse, by default Java will come with Eclipse. Okay, nowadays Java is also bundled with Eclipse, so even if you have not installed Java, you don't need to worry. So that will automatically come with Eclipse, and those guys support at least Java 9 plus. Okay, so Java 9 plus, yeah, they are basically supporting, and 8 is also fine, but raising the Rest Assured versions, they suggest Java 9 plus, whatever it is. And Eclipse is an IDE where we can write our scripts. Okay, short scripts.
02:49
Speaker A
and Eclipse combination so you need to have Java and Eclipse again Java is optional because when you install Eclipse by default Java will come with Eclipse okay nowadays Java is also bundled with Eclipse so even if you are not installed Java you don't need to worry so that will automatically
03:06
Speaker A
Okay, previously, Java we had to first install as a prerequisite to install Eclipse, but nowadays Eclipse will automatically come with Java, so you don't need to bother about Java. So later, if you want to run new test cases in command prompt or Jenkins, then we need external Java, not in Eclipse. We need external Java. Okay, that time we can install Java. But even if you already have Java in your system, no problem, you can continue with that. And Eclipse is also required, which is basically an editor. Okay, so this is the first requisite: Java and Eclipse.
03:31
Speaker A
our scripts okay short Scripts okay and previously Java we have to first install as a prerequisite to install like list but nowadays Eclipse will automatically comes with Java so you don't need to bother about Java so later if you want to run new test cases in command prompt or Jenkins so then
03:49
Speaker A
And the second thing is, once you have installed Eclipse, inside Eclipse we need to install one more add-on, that is testing. So TestNG framework we are going to use because from TestNG we will get a good number of features, right? So we are going to use those features from TestNG, just personally maintaining the test suite, maintaining the test cases, and data provider parameterization, running multiple suites, multiple tests. So these are very important features we will get from TestNG, so we are also going to use TestNG.
04:07
Speaker A
and the second thing is so once you have installed eclipse in inside the eclipse we need to install uh one more add-on that is testing so test engine framework we are going to use because from test engine we will get a good number of features right so we are going to use those features
04:26
Speaker A
So these are the prerequisites, and along with that, Maven. So Maven will even come along with Eclipse, so Maven we do not need to install separately. So that plugin will come along with Eclipse. So that is another thing, Maven, okay, which will come automatically with Eclipse. But as a destiny, we have to install separately. Okay, so Cucumber is a different type of framework, so we do not need to have Cucumber, not required here. Rest Assured by default supports Cucumber style of writing the test cases, but for that, we don't need to add any additional Cucumber plugins, not required. Okay, by default, Rest Assured supports BDD style of writing the test cases. Okay, fine.
04:43
Speaker A
so these are the prerequisites and along with that Maven so Maven will have even come along with uh comes along with the eclipse so Maven we no need to install separately so that plugin will along with the comes along with the eclipse so that is another thing maven
05:02
Speaker A
So these are the three prerequisites which we need to have before starting Rest Assured: Java, Eclipse, TestNG should be there, and TestNG we have to install after getting Eclipse, and then Maven. Okay, so Maven will come along with Eclipse. Okay, so once you have this, then we can start working with Rest Assured. Again, we have to download Rest Assured jar files, or else if you are using Maven, we can just add the dependencies of Rest Assured so that we will get additional classes and methods. Okay, so these are the prerequisites which we need to have.
05:22
Speaker A
for that we don't need to add any additional cucumber plugins not required okay by default restoration support bdd support bdd style of writing the test cases okay fine so these are the three prerequisites which we need to have before starting restoration so Java Eclipse
05:41
Speaker A
So first, let us see how we can get this. So if anyone has not installed Java and Eclipse, I will share a small document here, and this contains how to download Java and how to install Eclipse. Everything I have noted down here with the screenshots. I can share this document, and go through it and just try to install it. Java is optional for now. You can directly install Eclipse, no problem. You can install Java later also.
06:00
Speaker A
or else uh if you are using Maven so we can just add the dependencies of test ratio so that we will get additional classes and methods okay so these are the prerequisites which we need to have so first let us see how we can get this so if if anyone is not installed Java and Eclipse so I
06:19
Speaker A
So how to install Eclipse? Simple, we can directly go to their official website. Just go to Eclipse, just search for Eclipse download, and go to this location. This is their official website, okay, and you can directly download this. There is an installer for Mac also, and if you want to download for Mac, you can say Eclipse download for Mac, so it will directly go there and you can download from Mac also.
06:35
Speaker A
Eclipse no problem you can install Java later also so how to install a clip simple we can directly go to their official website just go to eclipse just search for Eclipse download and go to this location this is our their official website okay and you can directly
06:57
Speaker A
So this is for Eclipse IDE for Java developers, and you can see this is for Windows. For Mac version is also available. There will be some DMG file, you can just download for that. This is for Linux, and this is for Mac OS. You can just look here, this is for Mac OS 32-bit and 64-bit. Try to download 64-bit because nowadays there is no 32-bit. All are 64-bit installers. So you can just download this and you can try to install it. This simple installer, we can just click on the executable file and say next, next, next. You can see this.
07:20
Speaker A
for Mac version is also available there will be some DMG file uh you can just download for that this is for Linux and this is for Mac OS you can just look at here this is for Mac OS
07:35
Speaker A
Okay, so once you download it, we will get a small executable file or DMG file, so you can just double-click and it will proceed further. So here we have to select Eclipse IDE for Java developers in the welcome window, and then it will show you the location where exactly it will install, which version of Java it will come along with Eclipse. It will show you some options, and then click on install. Then installation will start, and it will take some time. Once installation is successful, okay, it will show you the location of your Eclipse, and click on the launch button. So then automatically, first time when you launch your Eclipse, it will ask you for the workspace.
07:53
Speaker A
so we'll get small executable fire or dng file so you can just double click and it will proceed further so here we have to select Eclipse ID for Java developer in the welcome window and then it will show you the location where exactly it will install which version of java
08:10
Speaker A
So workspace in the sense, whatever the task or whatever the job you have done inside Eclipse, everything will be saved in one location. That is called workspace. So workspace is a storage data where it will store everything. So whatever we do in Eclipse, everything will be stored in that particular workspace. So first time when you're launching your Eclipse, it will ask you the workspace, and you can just create one folder wherever you want to store your files and browse that folder, then launch it. So then your Eclipse will be launched.
08:28
Speaker A
first time when you launch your Eclipse it will ask you for the workspace so workspace in the sense whatever the task or whatever the job you have done inside the eclipse everything will be saved in one location that is called workspace so workspace is a storage data where uh which will
08:44
Speaker A
store everything so whatever we do in Eclipse everything will be stored in that particular workspace so first time when you're launching your work Eclipse it will ask you the workspace and you can just create one folder wherever you want to store your files and browse that folder
08:58
Speaker A
then launch it so then your Eclipse will be launched launched and first time you will get the welcome screen so let me show you my eclipse so I already installed my Eclipse Let's Go and show me so here this is my Eclipse icon you will get so click on it and this will start our eclipse
09:26
Speaker A
and this is the first prerequisite so first we have installed Eclipse so first time when you open the eclipse you will get welcome screen you can just once you close the welcome screen then you will see the package Explorer like this so you don't see anything by default you can see
09:40
Speaker A
some options here package Explorer and some bottom window you can see some icons and my nose you can see so the first thing is here we have to create a new project okay whenever you start working on something you have to first create a new project in the eclipse so if
09:57
Speaker A
you create a normal Java project so you have to download rest assured jar files externally then you have to add them to your project manually how to add so many dependencies are there not only one or two dependencies at least we have to download five to six types of dependencies
10:13
Speaker A
okay so uh we need to again getting download in the jar file from the different places is very difficult thing so instead of doing normal creating normal Java project we will create a maven project so what is an advantage of Maven project so when you create a maven project we can
10:32
Speaker A
just add the dependencies which will automatically download required HR files or libraries the second Advantage is suppose tomorrow if there is any versions were changed so we can easily change those versions We can easily update your project with the latest versions and the bomb.xml just
10:48
Speaker A
we need to change the version number and that will automatically remove the old jar files or old dependencies and it will update with the latest dependencies so that is another usage of maple project so whenever you are working on Java projects not only this rest Ratio or not only
11:05
Speaker A
cylinder wherever or whenever you are working on some Java related projects we will always create a maven project okay so this is your eclipse and uh here we have to create a maven project so that I will do later there's a first take visit and second thing is in test engine we have to install
11:24
Speaker A
okay so this is another important item we have to install so to test NG if you want to install what we can say is just go to window here so go to help menu and here you can see Eclipse Marketplace so
11:37
Speaker A
go to Eclipse Marketplace and whatever additional add-ons or plugins we required for Eclipse we will able to get from the eclipse Marketplace so here just go take less Marketplace and here search for testing G and click on go button so it will show you the test engine for Eclipse so just you need
12:00
Speaker A
to click on the install button here so you already I already installed this so I'm not getting that button so in case if you are in doing this first time you will get this button like this install button so once you click on this install button so then you will able to it will automatically start
12:17
Speaker A
your test NG and installation will be completed it will take few seconds and after completion of installation then it will ask you to restart your Eclipse so you have to restart it okay so this is test engine plugin it is very simple to install you can just go through the steps and
12:35
Speaker A
then Maven anyway it will come along with the eclipse so these are the prerequisites which we need to have before starting with the rest assured okay so how to create and save projects in the particular workspace you need to just hold on for some time I'll show you so eclipse is ready and
12:54
Speaker A
test NG and then we will create an event project anyway so because Maven will come along with the eclipse so we have to create a maven project so once you have these prerequisites then we will start working with the project okay so as soon as you open the eclipse first time okay
13:14
Speaker A
now you won't see any projects or nothing here okay so we have to create a new Maven project so now I have an eclipse so now the first thing is we need to create a new project so whenever you
13:29
Speaker A
want to create a new project always try to put it a maven project but not a Java project okay so create you can see more options here create Java project create a project multiple options you can see and instead of doing this you can directly go to a file new and here you
13:46
Speaker A
can select project option and don't take the Java project just take the normal project okay so even if you have created Java project no problem because later we can convert that into Maple project but instead of doing all that indirectly we can directly create a mavon project
14:06
Speaker A
so in this video it will show you different options which are available in eclipse and you can just select the maven here expand and see this Maven project so you can select this option and then say click on the next button
14:21
Speaker A
and once you click on the next button which will ask you where exactly it will show you basically location default workspace location I'm selected this because whatever workspace we have open okay so before that uh I already switched to my workspace here let me close this for now
14:39
Speaker A
so first time it will ask you workspace right so you can see rest issue training this is a workspace which already created suppose if you want to switch to another workspace or suppose you created some folders in some other place you want to switch then you can just go to file and
14:53
Speaker A
here you can see one option called switch to workspace and here click on other and you can just browse wherever your workspace is created you can just browse it so this is a workspace name I have created inside this folder so I'm just browsing that workspace so that all your
15:10
Speaker A
tasks will be stored in the say or saved in that particular workspace okay so it can also switch between multiple workspaces but always maintain one one workspace per one project okay even in one workspace we can store multiple projects multiple projects also we can create in
15:27
Speaker A
one workspace that is also fine okay let me just create a maven project so go to file new uh select a project and then here we have to select the main one and select a maven project and say click on the next okay so in this screen so it will show you
15:47
Speaker A
different type of default templates project templates we don't need all those things we will create our own template so simply select the first checkbox create a simple project okay if you don't select what happens here it will show you uh some templates here so by default
16:06
Speaker A
some template will be displayed here like this you can see there are different templates so we'll be there for different type of projects so instead of you predify using predefined templates we will create our own templates so we know just select this check box and it will
16:21
Speaker A
not show you those templates it will just keep the archetype selection then click on the next button right so here we have to provide some information so here uh all other fields are optional but at least group ID and artifact ID we have to specify
16:38
Speaker A
so group ID is basically representing your project name and artifact ID is representing the package name the root package name which is created inside the project so we can use same name so here I'm specifying my packet uh my project name is rest assured
17:02
Speaker A
okay rest assured grinding okay my workspace name is also same I have given so press test show writing this is my project name and I'm also giving the artifact name same and the rest of the fields are optionally which will automatically create you can simply say finish
17:23
Speaker A
so once you've done it then it is created new Maven project inside your eclipse this is a maven project which is created if I just expand this you can see some default packages which are created SRC main Java SRC main resources SRC test Java SRC test resources these are the
17:44
Speaker A
predefined packages which are created and uh JRE Java also I'll attached this project so by default and this is the form.xml which is a most important thing where we will specify all the dependencies means what whatever the jar files we required and what are all other external dependencies
18:04
Speaker A
we required to the to use this project we can specify all those dependencies in the spawn.xml and this will automatically download required jar files for our project and which is very very useful so let me just close other unwanted windows in the bottom of the window
18:23
Speaker A
inside window it will show you some outlines one so I can just close them so this is the first Maven project which we have created so once you've created your Maven project let me maximize it okay so this is a maven project just you can create and if you want to increase the font and everything
18:46
Speaker A
you can still do it you can just go to window preferences and go to General section appearance colors and fonts and here we will able to increase the font I can just first increase the font of your editor go to basic and this is my text font currently small size 10 is there so let
19:10
Speaker A
me just write increase to 20. okay and this is the one and uh also we can increase this package editor font this seems very small all right so for that we can just again go to basic okay text editor blog selection font is there right so you can
19:31
Speaker A
just increase this you can just make it as if 12. okay it is still not increased let me just go to preferences saying this is the one View and editor folders tree and table font views edit yes okay so now it is good uh extender so it is got increased
20:02
Speaker A
so I'll show you one more time go to window preferences and here you can see General and appearance in the appearance section go to colors and fonts so this is a one so you can just select the basic option in the basic option you can see here the
20:18
Speaker A
two options this is for text font in the editor we will type the script right that is a font and the above one is what uh not this one so text editor block not this one so we need to go to another one
20:31
Speaker A
here View and editor folders if you want to increase the size of this package Explorer tree then you can just go to view and editor folders and here select this click on edit and here we can increase let me just put 11 that is fine okay so this is how we can just increase the
20:52
Speaker A
size so this is default uh Maven project okay So currently we have a three packages SRC main Java SRC main resources so test Java SRC test resources package is nothing but what it is just a folder so normally we create a folders right inside the folders We will have some files similarly
21:14
Speaker A
in Java whatever classes we will create everything will be part of your packages okay so SRC main Java resources and this attached to Java test resources we have a four different packages so especially test SRC main Java is used for development code okay so if
21:33
Speaker A
you want to develop something so we will write that code inside the SRC main Java and for development while developing some code you need some resources like properties file or Excel sheet or any other configuration files are required we can keep inside the SRC main resources
21:48
Speaker A
so these two are for only for development purpose okay for development we can use these two packages and uh once the development is done we have to test that right test the code for that we use SRC test Java for testing code and while testing if you need any external files like configuration
22:08
Speaker A
files and so on then we will keep inside the SRC test resources right so this is a file we can store different configuration files in the start the SRC test resources and SRS tested Java is for testing all the test cases we will include inside the SRC test chart so by default these four
22:27
Speaker A
packages are provided by Maven project okay so now so far we have seen eclipse is ready and test engine is also ready and how we will know whether testing is successfully installed or not so once you install uh test NG from the marketplace so I already shown you so just go to Marketplace
22:49
Speaker A
okay and once you install testng from here then you will see one new Option just go to window preferences and here you can see a test engine here see if you see this option means you already have a testing
23:05
Speaker A
okay but if you have a maven project this is also optional okay you can just add dependency in the pound rate XML test strange dependency we will add in that case we don't need to use this plugin okay
23:18
Speaker A
right so this is a prerequisite first we need to have eclipse and then test NG and then Maven so which is automate comes with the eclipse so we already created a maven project so now the next thing is we need to add some dependencies to the maven project okay dependencies
23:39
Speaker A
so if I just open the form.xml and this file will automatically get when you create a maven project so this is our palm.xml so in the form.xml we have to add certain number of dependencies and uh then it will automatically download required dependencies for our project then
24:00
Speaker A
we can start writing our report so what are the dependencies which we required for rest assured so we can refer them in the rest issue of their official documentation so go to Google and just search for rest assured okay rest assured so it will navigate to official website rest assured
24:23
Speaker A
so this is uh their official webpage and we just go to docs here they will give you official documentation a very detailed documentation they have provided so click on getting started so here they will show you what are all dependencies we required
24:43
Speaker A
so Maven or Gradle users we are Maven users currently so rest assured if you want to use we have to add certain dependencies like rest ratio dependency and then Json path also required this is another dependency required and XML path and dependency is required and then Json schema
25:02
Speaker A
validator dependencies required so these are the dependencies and other dependencies are given for development purpose so especially when you're walking with the spring and everything so but then we need it otherwise not required so they have mentioned what are all dependencies we require
25:19
Speaker A
especially in Java so they will suggest a Java 9 actually even Java 8 also they are not suggesting they are basically suggesting the Java 9 here okay so these are the required dependencies which we have to uh keyboard and once you imported all the dependencies then we will discuss about the static
25:42
Speaker A
packages okay static import so let's go to format XML let's add one by one all the dependencies and apart from this we need some other dependencies also to maintain the framework and everything so I will try to add those dependencies also okay so how to add dependencies go to permanent
25:59
Speaker A
XML and here we need to add one tag called dependencies dependencies This is the opening tag and this is the closing time opening tag and the closing title so this spelling mistake okay dependencies opening tag and this is the closing black dependencies so
26:21
Speaker A
inside the dependencies we have to keep all the dependencies inside the dependencies which we have to add all the dependencies so what are all the dependencies which we have to add so we already referred the document so the same dependencies we have to add I will list out here so later you
26:40
Speaker A
guys anyway I'll share the form.xml you can just directly copy paste somewhere but actually if you don't have permanent XML so how we can get these dependency I will show you so I will write all the dependencies here one by one and accordingly we can just specify them so the first dependency is
27:00
Speaker A
IO dot rest ratio this is a first dependency and the second dependence is Json path okay so IO is a package name actually so restoration dependency and video Json path dependency the second one and then we have Json dependency
27:23
Speaker A
Json is one of another dependency and G sun is also one more dependency Json is different Json is different okay both are different and uh then we have something called and again this Json is available in two different uh packages okay so I'll show you that so Json is
27:44
Speaker A
one dependency Json uh for that for the Json we have to add two dependencies especially for Json we have to add two dependencies okay I'll show you what are those dependents later so then we need to have test engine dependency that is another dependency and then we have something
28:05
Speaker A
called Script Java apis okay this is another dependency I'll tell you what is the use of it scribe script Java hyphen API so this dependency used for generating a random test data so while testing the apis right so we will send the request body right so in the request body sometimes we
28:27
Speaker A
need to pass a random data dynamically or we can say some fake data we have to generate so for that this API will be useful this is third party API and which we can use in uh in other
28:37
Speaker A
Technologies also normal Java projects everywhere we can use to generate the fake date kind of data and then we have to add one more Json schema validator Json schema validator so this is another dependency which we required to validate Json schema okay and similarly
29:03
Speaker A
XML schema validator is also available so we need to add that also XML schema validator schema validator okay so these are the required dependencies which we need to have in the form.xml so that we will get required jar files for our project okay so
29:28
Speaker A
now let me add all the dependencies here so from where we will able to get these dependencies so to get these dependencies we will refer mvn Repository mvnrepository.com so if you just go to this website you can find all the dependencies here suppose I
29:47
Speaker A
want to download rest issue dependency so you can just search for rest assured so now it will show you the rest issued here you can click on it and just then copy this dependencies and then go back to your form.xml and copy it here that's it so this is how we can
30:06
Speaker A
just download the dependencies one after another this is our rest ratio dependency okay so this comes from this particular default package and similarly we will able to download all other dependencies so I already downloaded all the dependencies in the power.xml I will shade the
30:26
Speaker A
format XML you can just copy paste directly and suppose tomorrow if there is any version changes happen then you can just change the version number in the pound.xml that will automatically remove your old jar files and then it will download latest jar files it is very simple to upgrade
30:44
Speaker A
your project also if it is a maven project okay all right so similarly let me just add other required dependencies of our project go to form.xml just added all other dependencies okay so this is how we can just add other dependencies
31:07
Speaker A
okay now save the file so once you save it will start downloading some error is showing let me show you what is an error so 400xml end tag name okay so this is ending tag name missing any tag name here yeah I think spelling mistake yeah dependencies
31:31
Speaker A
here and here dependencies in just a second okay this is the closing tag okay and we need to have a opening tag so before specifying all the dependencies here we have to write a opening tab this is the opening tag okay
32:02
Speaker A
now save the file so once you save the file so then it will download all required dependencies and you can see those dependencies under May 1 dependencies type you can see here this is a new entry which is created so these are all the different dependencies
32:20
Speaker A
we just downloaded through pawn.xml file okay now we can just look at this so this is very very useful right if I create a normal Java project everything we have to do manually so we have to add all the jar files manually and we have to again if tomorrow if you want to upgrade
32:39
Speaker A
your project again you have to remove all jars and again we have to add a new jars a lot of manual tasks will be there so to avoid that simply create a maven project okay so log4j for now it is not required if you want to add any logs then it is required otherwise no need
32:55
Speaker A
okay so if required we will add them later in the project but here we don't need okay because uh we are just trying to learn some concept from the first we will learn some concept from the rest issue okay and at the end of the course I will show you the framework that time I will use
33:13
Speaker A
block for J dependency also okay people also do small uh one small project on rest assured okay and that time I will show you all other other type of dependencies so first we will learn all the concepts okay how we can send different type of requests so whatever Concepts we have learned
33:30
Speaker A
in the postman tool right same Concepts will be there in here also but uh here we do everything through automation script we have to write our own script everything will be there okay we'll verify the body request body response body chaining status code everything will be there everything
33:48
Speaker A
is repeated here but we will do everything through automation code okay that is the only difference in the postman we have done manually But Here We Do everything is automated okay once you learn all the concept then I will show you the complete framework development how to develop the framework
34:04
Speaker A
and uh then how we can generate the report we will see so many other things okay so first let us focus on Concepts first and first let us learn all the concepts then we will proceed further okay all right so now we have done created a new project and then we have updated form.xml
34:26
Speaker A
and everything is ready so these These are the prerequisites you have to ready with these things okay now we are ready to create rest Azure project we already created so we are ready to write our automation Scripts okay so far everything is clear everyone please confirm the chat window can you
34:46
Speaker A
guys do it yourself I will share the document for Eclipse installation testing installation just go through the document step by step and just try to install it if you already worked on Webdriver selenium earlier so you may have all the setup ready so you don't need to do
35:04
Speaker A
any additional setup just directly create your Maven project and if you're completely new and if you are doing this first time then you have to install Eclipse test NG and then do the setup okay so now we are ready with the setup and configuration now let's see how we can create
35:24
Speaker A
uh rest issued request okay so rest assured uh basically have different type of requests right http requester so let's see how we can automate the basic HTTP request so the first thing is we have to create get request and we have post request and we have
35:49
Speaker A
then put request right so we have then put request and then we have a delete request so these are the four main requests we do in the HTTP request so let us see how we can create a automation
36:03
Speaker A
test with this requester so as a first step very basic so I'm just taking request and response API so which we already used earlier in the postman tool and same uh AP I am taking to understand the basic step later we will try it with a different type of eps so from this I am taking
36:22
Speaker A
four different type of requests one is single user creating the single user this is getting the user and create this is a one another API I'm taking which will create a new user and then uh update for updating users so we can use either put request or you can use patch request either
36:42
Speaker A
this one put request or you can use patch request both are almost same and then for delete request I am taking this so this will delete the user so creating user and getting the user information and update the user and delete the user so these are the four requests I am going to automate through
37:01
Speaker A
rest APK okay so for that let's go to Eclipse now and so rest of the packages we don't need SRC test Java right inside this we are going to create everything so if you want to delete them you can still delete those two we don't need these two packages we can directly delete them
37:21
Speaker A
and don't delete SRC test resources which we require in future only delete SRC main Java SRC main resources you can just right click and then delete them okay so now under SRC test Java we are going to create all the scripts so inside this I am creating a new package again so today I'll say
37:44
Speaker A
day one plus they showed day one so every day I'll create a new folders so in the day one let me just create a new class and whenever you want to create a new test case we have to create a new class okay
37:59
Speaker A
so in this I'm going to create a new class name I say HTTP requests okay HTTP request so this is the name of the class I have given and we are going to write the test cases in the test engine style
38:16
Speaker A
okay not in the Java style so we don't need to take any main method so click on finish directly so which will create a new class so this new class is representing a new test case okay new test case
38:30
Speaker A
all right so now let us try to create a new test case so whenever you create a rest issue test cases so by default which will follow bdd style Behavior development Behavior driven development approach Okay so how we will write the test cases so here we have to understand few important things
38:53
Speaker A
so we have something called Gerkin language okay so we have something called Gerkin so this is a particular language and which contains some number of keywords some keywords will be used and these keywords especially we used in the bdd approach like given when then and so like that
39:14
Speaker A
so there are different keywords are available in the git gherkin so restaurant should by default support this so you don't need to add any special type of dependencies like cucumber all those things we don't need that so by default test rest assured will support bdd style of writing
39:30
Speaker A
test cases so we are going to write all the tests using bdd Style okay yeah sorry spelling message okay by by default which will support bdd style of writing test cases so uh we don't need to add any additional dependencies to support this so let me just try to show you few keywords
39:54
Speaker A
how we will use them uh at the time of writing the test cases so before writing the test case okay so here we use certain number of keywords I said right so first thing is given and these are all basically methods not a keywords basically methods okay given
40:14
Speaker A
and then we have something called when and then we have something called that so these are the main three things which we are going to use given when and then okay so first listen guys so don't compare with any other videos please come please listen from the beginning so once I have completed
40:33
Speaker A
this topic then I'll take the questions then I will answer that okay first listen completely so uh rest issue is provided a certain number of keywords like given when and then so just remember only these three methods case only three methods okay I'll tell you when we have to use given when
40:55
Speaker A
we have to use when when we have to use them it's very very simple if you try to understand it's very easy also it's not that much complicated it's very very simple I'll tell you so these are the
41:05
Speaker A
only three methods we will use while writing the residual test phases only three methods but uh what is the difference between given when and then so what is the different type of content we will include inside the given bank so you can consider these three or the three different
41:21
Speaker A
sections in your automation test case so can automation test case you can divide into three sections you can say given section Ben and then so you can consider them as three different sections okay so in the given section okay let me put the comment here so in the given session what type of
41:41
Speaker A
code we can include whenever you are sending a APA requester so you already seen in the postman also whenever you are sending a pay request there are some prerequisites are required can anyone tell me what are the prerequisites before sending any API request what are the things we required sometimes
42:03
Speaker A
we have to specify the what kind of content we are sending okay and we can specify authentication we can add query parameters path parameters we can set some writers cookies so these information also we can pass along with the requester right when you're sending some post request especially
42:20
Speaker A
we will send all these things right so these things we have to keep inside the given section insert the given section what is the what are the content we have to keep content type content type cookies authentication parameters headers information Etc so all these things comes under
42:40
Speaker A
given section okay so in the given section we have to keep these information now in the when section what we have to do so in the when section we have to specify the request type like get request post
42:54
Speaker A
request put a request delete request so all the request URLs we will keep inside the when section and the third section then all validations we have to do under then section validations what are the validations status code response headers cookies response body all these things we will
43:15
Speaker A
validate right once you get a response so all those things we have to keep inside of the then section it's very simple to understand the entire test case is divided into three parts one is prerequisites second part is a request third part is a validation so all prerequisites we
43:33
Speaker A
have to keep inside the given all requests we have to keep inside the when all the validations we have to keep inside the then if you understand this structure we can easily write our test cases it's very very simple and we can easily write our test cases okay now so based on this let us try to
43:53
Speaker A
create a test cases so given when then actually these are the methods which are available in rest assured and in the given section we specify content type cookies authentication parameters headers everything we can keep inside the given section all the requests should be part of when
44:10
Speaker A
section all the validation should be part of then section okay it's very simple and straightforward so we don't use end here and is not required just given then given when and then so sometimes we use end also that will be part of then section again if you have multiple validation points yes I want
44:30
Speaker A
to verify status code Response Code then you can use end okay and also will be there which is also part of them then it will part so I will show you that also once we validate multiple things then
44:43
Speaker A
we can use end keyword all right so this is the structure of creating the tests in rest assured okay so you have to remember this is very very fundamental now based on that let us try to create a rest issue test basis so now first test so I'm going to write a test cases in the test NG
45:03
Speaker A
style you have to remember this so the first test is what I'm going to create a new user okay here okay so before getting let me just exude the single user get request so when you send this request you will get some response here you can say this is a response so let us try to automate
45:24
Speaker A
this getting the single user so for that I am going to write a one test NG test so void get user okay wide get user and this is my test method so in the test NG every method should be defined
45:47
Speaker A
with the test annotation so then only testing you will consider that method as a test method then it will able to execute so I hope everybody know about Java and testing so as I said beginning itself these are the prerequisites so you have to know some basics of java and testing G okay
46:03
Speaker A
so now in the test range you have created a new class right so inside this I have created one test method so get user is a test method get user is a test method now inside this I am going
46:17
Speaker A
to create a test cases so what are the different sections we discussed here given when then right so let me just write them first given when and then okay so to identify these keywords especially we have to import some packages okay to identify these keywords we have to import special packages
46:41
Speaker A
and what are the packages which we have to import there are mainly three packages which we have to import they are called Static packages okay so static packages we have to import why I'm calling a static packages they are not normal packages because whenever you put the cursor here it will
47:00
Speaker A
show you the package names right so immediately we say import that will automatically import the package there's a normal way will happen whenever you some new classes or external classes but in these cases it will not happen like this it will not show you required packages in this list
47:16
Speaker A
so they are called Static packages we have to find out and we have to add them manually so what are those static packages in every test case we have to add those three static packages so what are those three static packages they have supported so go to rest Asia document here and in
47:36
Speaker A
this they have provided something called Static Imports so these three packages which we have to import in every test case copy them and then place it over here and use import keyword import so these packages by default it will not show you in the pop-up so we have to do it manually
47:59
Speaker A
important so these are three other special type of packages come some rest assured and if you add this then only the keywords will be identified so now end with the semicolons and then save it okay so these are the three static packages which you have to import
48:19
Speaker A
so now if you come here these are the three cables given when and then so whenever you start these methods given when then so actually the given is one method which includes when this includes that this is a combined method structure so for the first method you don't need to give any dot
48:38
Speaker A
from the second method you have to give something called Dot because these methods we are accessing from given so whichever method sometimes given is also optional if you don't have any prerequisites if you don't have these things you just ignore the given you can just remove the given section
48:54
Speaker A
directly you can write when and then okay suppose if you write a given section if you write a given section then you no need to write the dot for this only when and then section you need to start with the DOT suppose sometimes we don't have any prerequisite I directly want to send
49:12
Speaker A
a request then you can just remove the given section and you can remove the dot for the Venom so whichever method will start first for that method we don't need to specify the data so only then section is having dot suppose you have a prerequisites then I can specify
49:29
Speaker A
the given and then for given method you need to you no need to have a DOT from the second method you need to specify the DOT so this is a structure we will normally follow and whichever the first method you are using for that method dot is not required it can be given or it can
49:47
Speaker A
be when or can then whatever if that is a first parameter first section you know need to specify the data from the second onwards we have to specify the dot okay now in the get user request what are all prerequisite which we need have so if you want to send a request go back here again
50:09
Speaker A
so when you send a request I want to send a single user request so how to send the request what is the URL we have to copy this main URL okay and then copy this request and this will basically display the users which are there in the second page so this
50:27
Speaker A
is a complete URL this URL will use to get the users list get users on this particular page so on this two means from the second page it will get all the users and this is the get request
50:43
Speaker A
okay so the next one is what post request or create user so for that what we have to use so here we have a post request so this is a one and this is a URL again slash and uh what is end point so this is the end point slash AP slash users
51:07
Speaker A
endpoint and for this we should also send body right so this is a body request so this is our post request so this is the URL and this is the body we have to send okay and then put a put or patch so we can just select the put request so for put request also it is the same URL
51:28
Speaker A
put request means what update user for update user again it is the same your same URL get user's URL AP uses API slash user Slash 2 and here we have to send the body updated body same body but we have to change something here this is the update request and for delete request
51:55
Speaker A
this is a delete request again same URL delete user this is the URL and this is the endpoint so here the two is a user ID so when you pass user ID the response will be two zero four
52:13
Speaker A
so that also we have to validate this is a URL and here we have to pass the user ID user ID then obviously 204 is the status quo so these are the four type of requester get users post user update
52:32
Speaker A
user and delete user so let us try to create different type of tests on this particular request okay so now go back to the eclipse and now in the given session what we have to specify in the given
52:47
Speaker A
content type cookies authentication parameters all those things but currently get requests don't have these things you can simply ignore given section you can just add given here that's it you don't need to write anything in this so directly go to when section in the when section what you
53:06
Speaker A
can specify only request a type okay so how to specify the request to type in the when session which request you want to send get request so I say dot get this is the method dot get them okay dot get and here in the double quotations we have to specify the request type so for get
53:27
Speaker A
users this is the URL copy here and then specify and don't put any semicolons here because these methods are interrelated there will not be random so when section we send a request dot get and specify the complete URL of your API it is done so what's the next step then come to the then
53:49
Speaker A
section so what are what are all things we have to validate here so once you send this get request and we have to validate the Response Code which is 200 and also we can verify the body section okay
54:02
Speaker A
we can also verify the body section so first let's see how we can verify the status code so in the then section you can simply say dot status code this is a method dot status code and here we can
54:17
Speaker A
specify which status code we are expecting let's say 200 MX per T this is one validation point next line what is another validation point I want to check something in the body section so in the body section let's say I'm requesting second page of data so here in the data also you
54:35
Speaker A
can see here ID is 2 here it is giving single user single user right I'm requesting single user I've set two here so the user ID is 2 here the two user ID is two so this I can validate the ID is two or
54:49
Speaker A
not I can validate so how we can validate this so we can validate right how we can validate this we can validate by passing the Json path so we have a concept of Json path right that we have to specify
55:05
Speaker A
okay so let's see how we can do this so for that let me just capture this response okay so for now let us take the simple response later I will include Json path and everything so for that what I can do instead of taking single user take the list of users take this
55:23
Speaker A
particular request okay so this is the URL I'm sending list users not get users list users or you can say get the users because we are getting the all users information so here this is a URL which we have to send okay this one this is a URL
55:56
Speaker A
and not a single user so we are getting the multiple user request first of all copied here okay this is the end point foreign ers and then specify the enter request URL so this is a get user request and which will return
56:17
Speaker A
multiple users which are available in the page number two so if you just send this you'll get some response here a big response you will get different users you will get and now we need to check whichever ID we have passed here whichever page number we have passed in the response also
56:33
Speaker A
the page same page number should be there okay that's my validation fact so how we can specify this this page is directly available in the Json so how to get this value of the page in the rest assured so we have a different syntax so status code we already validated the next thing is what
56:51
Speaker A
from the body we have to validate something so for that we have a method called dot body dot body and here what is a field page right page so it is uh directly available so we don't need to
57:07
Speaker A
write the a bigger Json path right but if you want to handle this email address first name last name then we have to write a complete Json path but this is a first field and it is directly available
57:18
Speaker A
so you can directly take page so go back here and say page and uh what is the value of the page we are expecting we are expecting two so comma here we have a method called equal two this is again
57:32
Speaker A
now rest issued assertion so I can say two this is a value we are expecting so this is the one validation point and this is another validation point and after that if you want to display the entire response in the console window if you want to see the response then you can add one
57:51
Speaker A
more method called it is not a validation point it is just for displaying the response in the console window I can simply say log dot all log dot all so this will display the entire response in the console window and now this is the end last step so this here we have to specify semicolon okay so
58:14
Speaker A
this is the entire structure of writing the test so given section currently not having anything because get request don't have any prerequisites so we can just leave empty and in the when section we have sent get request and in the then section we have done the validation now if I just look at
58:31
Speaker A
here there are few things which are still not recognized you can see given is not recognized and equal to is also not recognized means what we have to import some additional packages rest assured we have imported hybrid or restoration and Iota restoration.matcher.restration matches
58:50
Speaker A
also we have imported and HR and prestidot matches also imported but still it is not identifying the not identify them so let me just check why it is not identified and we put star star means what which will import all the classes which are available in
59:09
Speaker A
those import packages so one more important thing here especially static packages we have imported yes static packages we have imported right so they are not like normal packages so we have to add one more thing called static keyword so where we have to add after this import we have to add something
59:30
Speaker A
called Static okay in every package before the package we have to add something called Static because these are the special packages not normal packages so then only these keywords will be identified given when then and everything will be identified okay now save it
59:51
Speaker A
and everything is got saved okay so everything is good so we have imported required packages and uh whatever structure we discussed before same structure same thing we followed given when then and make sure except the first method rest of all methods should start with the data
60:11
Speaker A
actually the whole thing we can write within single line that is also possible but as a beginner we need to understand few things here the sections what are the things we need to keep so I just divided them into multiple Parts but later I will show you how we can write everything in one
60:26
Speaker A
single line because these methods are interrelated okay so this is a get user tester so when you run this method which will get all the users and which will validate something and also response will be printed in the console window okay so one more thing if you don't have anything in the given
60:49
Speaker A
section you can directly remove that also no problem even if your remote no issues at all but the first method is what now when so we should remove the dot for this this is also fine if you don't have anything in the given section you can directly remove that method or even if we keep an
61:07
Speaker A
empty method no problem at all so later while sending the post request we will add something in the given section so the time I'll show you for now let me just continue have given method and when you say given method again from the second method onwards we have to say dot
61:24
Speaker A
okay so this is how we can just write a test for get requested okay get request so here these are rest issued assertions so actually these equal to comes from uh this one register should match this is the imported package right so from rest assured matches this will come into picture
61:45
Speaker A
it will not use any other separate framework by default this will come from West issued matches okay right so let's try to execute this and see how it's going to work so to run this we can use run as a test10g so test NG import package also we have import I can just go
62:04
Speaker A
to palm.xml and test changes also we have address somewhere here you can see this dependency we have added and if you are not either the dependency then at least we have to add the test engine library to the project so like this you can just right click on the project properties
62:20
Speaker A
and go to Java build path and here we have to add test NG Library so not here under libraries currently Java and Maven dependencies are there if you want to add test any Library just click on ADD library and select test NG and check next and then finish and this is not required if
62:39
Speaker A
you add the dependency in the form.xml this is not required okay so I just try to remove this fine so everything is done so com.xml we have updated with required dependencies and also we have created one request first request let us try to execute it right click run as test NG test
63:01
Speaker A
and it will ask you every time so I can just select this marks and say ok so now it is trying to execute yes so now it is executed and one is got passed now you can see the response here because we have
63:22
Speaker A
said log dot all right so this is printed the entire response in the console window also and just go to console window and you can just look at here these are the details we got a response so this is called status code and these are all Header information and this is the actual
63:41
Speaker A
response we got this is actual response so in that response we have a page number two which is also validated so that is got passed and Status Quo is 200 is also got passed both are got passed right so this is how we can just automate and you can see one more output here get
63:59
Speaker A
users here also it is get passed so this is how we can simply write a small test for get request okay so similarly let us try to automate other type of request post request update user and delete user so post user means we have to create a new user so let me create one more test
64:22
Speaker A
so I'll say void create user create user so I can give priority so if you have a multiple test methods if you want to execute in proper orders you can give the priority right so I can just get users I'll give Priority One
64:41
Speaker A
for add equal to 1. So currently I don't want to execute this I can just comment this so later we will execute all the requested one shot for now we will create one by one and execute one by one once
64:53
Speaker A
everything is successful then we will execute all the requests in one shot so now the create user and whenever you create any new method we have to specify with that test annotation and now let us create so again three sections you should not forget this this is the thumb rule
65:11
Speaker A
first one is what given given second one is what when third one is what then so first write entire structure then we will write a statements inside every session now given so when I create a user we are sending some data right we need some data request body is required because we are posting
65:33
Speaker A
the user posting user is nothing but we are creating the user creating the user means we have to pass the user information like name and job you have to pass so this is a prerequisite so to send the post request so this is a prerequisite so now we need to send this request along with this data
65:50
Speaker A
right so this is a prerequisite and what is the content type here what is the content type content type what kind of content we are sending here what kind of content we are sending Json format right so there's a Content okay remember these two are important whenever you are sending
66:07
Speaker A
the post request what what is the data you are sending and what type of data you are sending so these two are very very important right so now let us create post user or create user request so I
66:20
Speaker A
have created another tester so before using given when and then we have to prepare some test data so tested data we have to prepare So currently I have only name and a job only two fields so what I will do is in Java we have something called hash map collection Java we have a hash
66:41
Speaker A
map collection so by using hash map I will generate this data or I will store this data in the hash map and then I will convert that hash map into Json format and then I will pass the Json
66:53
Speaker A
format as part of your post request but again to generate this body we have a different methods are available okay different ways we can generate the post request body so in the next session I will discuss in detail how many request how many ways we can generate the body of post request again
67:14
Speaker A
that is a big concept which we have different ways different approaches which we have But Here let us use small approach very simple straightforward which is Hash map actually we don't prefer this one in the real projects because if I use hash map we have to hard code the data right so normally we
67:32
Speaker A
don't suggest to hard code the data so we don't use hashmap but currently we have only two inputs to pass as part of the request so just let us try to use hash map but tomorrow's session I will show
67:44
Speaker A
you the actual way of generating the data post request different approaches I will show you so for now I'm just using hash mapper okay before given section let us create something called hash map object I say hash map hm equal to new hash map and what kind of data we can store in the hash map
68:07
Speaker A
and what kind of data it will support data should be in the key and value pair key and value base right and even here also in which format you have to send the data key and value pair name is a key
68:19
Speaker A
this is the data this is a job is a key this is a data so key and a value pair the data we have to pass so in hash map we can maintain data in the key and value pair right so let's import this hash
68:32
Speaker A
map from java.util now we need to add some data to this hash map let us add some data let's say uh hm hash map Dot put is a method to add the data right so here name is my field
68:47
Speaker A
the first field is name and here I'm adding some value this is my first field now hm dot put hm Dot put and what's the next field job job we have to send a job and here you can pass
69:06
Speaker A
something called planar so this is my job so I have put two details or two values in my hash map now my hash map contains two different uh requests so this is one input this is another input so two
69:18
Speaker A
values I have in my hash map so two values I have in my ash map so now we need to pass this hm hm is representing what data only hm is representing what data or you can just rename it data so data
69:35
Speaker A
is what now hm type so now data do output and here data.put so now my hash map contains the data so this particular data object we have to send along with the post request this particular data object we have to send along with the post request okay so now we have generated the data by using hashmap
69:58
Speaker A
now let's go to given section so what are the prerequisite do we need to pass along with the post request prerequisite we have to specify content type what kind of content we are sending second thing is what we have to specify the body also there are two things which are part of the
70:17
Speaker A
given session now go to given section in the given we have to specify something called content type what kind of content we are passing so for that we have a method called dot content type content type content type is what application application slash Json this is my content type and what else body
70:39
Speaker A
also we have to center right dot body dot body and now we already created the data inside this right same thing we have to pass it here body is in data so now this data will go along with the requester
70:55
Speaker A
now given section is done now come to the when section in one section what we will do we will send the request so what type of request we have to send post request so dot poster post and here we specify the post request URL so what is a post request URL this is a post request URL
71:16
Speaker A
go back and specify so post request URL we have Center done so now come to the then section so what are the things we have to validate in the then section now we can validate status code right we can validate other things right so here let's validate the status quo dot status
71:36
Speaker A
code and what is the status code I'm expecting 201 whenever you create something normally two zero one is the status quo and if you have doubt here you can check so here I'm sending create a user post request and here you can see 201 is the response code okay so now I specify the
71:56
Speaker A
status quo now I want to put the entire response in my console window so how we can log entire response in my console window I can simply say dot or before that suppose uh ID is dynamically generated here if you just look at here in this request whenever you send this request
72:15
Speaker A
ID will be generated see here ID is 949 when you send one more time the ID is 100 and one more time the ID is different so we cannot expect what IDT is going to generate we don't know exactly
72:29
Speaker A
so we can't put any validation point or ID value but we can use this ID value in the next requester suppose if you want to update the user if you want to delete the user that time we can use this ID
72:44
Speaker A
once you capture this ID we can reuse it but we cannot validate the exact value in the ID because this ID is dynamically generating fine so now what we will do is status code we have validated and what after that I just want to print the response how to print the response by using
73:02
Speaker A
log dot or log dot R now here I'm ending the statement so every statement should not put semicolon okay the last statement only we have to put the semicolon so this is the entire test for creating the user creating the user so we have first created the data by using hashmap
73:23
Speaker A
and in the given section we specify the content type and body and along with the body we are sending the data this data we are sending and this is my post request and once send the post request we are validating the status code and then we are printing the response in our console window
73:39
Speaker A
this is our test okay still we need to add something here first of all let me just execute this and see whether it's working or not so now my first test is already commented so it will not execute now the second one will be executed now run as testing the test
74:02
Speaker A
okay so now it is got failed now we'll see why it is getting failed here so don't know how to encode yeah this is the data error so don't know how to encode the name right on the job as a byte streamer
74:18
Speaker A
as a bite steam it is giving some error so let us see whether the data is correctly given or not okay so let's try to check the data once again so name this is the hash map hash map equal to new hash map is fine data
74:39
Speaker A
put it's a name and this is my name job double quotations and semicolon okay this is fine and at the time of sending the body we are sending the body okay so yeah sorry guys this is the content type validation wrong okay application
74:55
Speaker A
slash Json it is not a DOT actually application slash Json okay yeah save it then execute okay so now my request is successfully done so if you just go to console you will also see the response here this is the response which is generated
75:22
Speaker A
and what is an ID which is generated 4 4 is my ID generator okay so now if you want to update this recorder okay if you want to update this record this ID is required for us okay this ID based
75:37
Speaker A
on the ID we will able to update name or job so for the next method next test we require this ID you can just look at here if you want to update put request update here we have to pass ID 2 is
75:53
Speaker A
my ID and this is the data we have to pass then it will go and update the data so what we have to do now we have to capture the ID from the response what we get so when execute this method we got
76:08
Speaker A
some response but we are just printing the response we are not uh getting any data from the response we are just printing the response so now from thus response we have to capture the ID you have to capture the ID and that ID we have to use in the next request for updating and deletion
76:28
Speaker A
so how to return the ID how to capture the ID from this method so to capture the ID from this method ID is used for ID is used in other request also in the update user get request also update user
76:42
Speaker A
and delete user in both the requests we need ID so I will create one Global variable here ID integer ID I just created one Global variable because I can use this side I can access this variable in every method okay now instead of printing this instead of checking the status
77:01
Speaker A
code instead of printing this I will just send the response back I will get the ID from the response so how to capture ID from the response where we have to capture ID from the response just try to remove this then section okay I can just remove this comment this then section
77:23
Speaker A
right so here we can what we can do is directly as soon as you send a post request this will give you some response on that response we are doing these validations so now what I want to do is once you send this post request I don't want to do any validations here but I want to
77:42
Speaker A
capture the response in a variable so I put semicolon here I end up the statement here so as soon as you send the post request okay this will send from some response okay that response how we can send back the response dot the response in the form of Json Json format so here we have
78:04
Speaker A
to use one additional method in the when section what is the traditional method dot Json path okay dot Json path from the Json path we have to get int okay get integer method get in so which data we want to capture from the response ID value we have to capture the ID whichever ID is generated
78:28
Speaker A
the ID we have to capture so that I can specify here ID and then semicolon keep semicolon here so what exactly happened here is whenever you send a post request it will return some response on top of response we are getting the Json path get in of ID
78:50
Speaker A
okay by using Json path I am getting the value of the particular field what is that field ID which is a number so I am using get in if it is string then you have to use get string guessing a method you have to use depends on the data suppose here I have a name job ID so
79:09
Speaker A
for name and job you have to use get the string here for ID is a number so ID is a number so for that we have to use in there okay so we have to get this ID and where we have to store this
79:22
Speaker A
ID this will return some value so before given section before given section we have to create a variable so ID equal to ID equal to so this is how we can specify that so enter into we already specified right in ID we already specified so just say only ID so now
79:45
Speaker A
given we specify the content type and body we are sending along with the request and we are sending the post request and from the response by using Json path we are getting the particular field ID and returning the value here now what is this ID contains ID contains a
80:04
Speaker A
ID which is captured from the response which is captured from the response so this ID I will use it another request for updating the request so let me create one more request let me make priority equal to one so now let me create one more method
80:26
Speaker A
so not only one property we can capture other properties also okay so I will show you that I will show you that options we have a chaining concept right so that time I will explain how we can get the multiple uh multiple fields from the response because we
80:42
Speaker A
need to also violate the entire response so from the response we have to violate all the fields so we have a separate part for that how to validate the Json response how to violate the XML response we will see them in the separate sessions okay this is not for validations we are just trying
81:00
Speaker A
to understand how to send a request that's it only focus only that particular part so forget about uh validation forget about Json path we will discuss in detail one by one in the coming sessions okay so for now just focus mainly on the request type how to send get requests how to send post request
81:21
Speaker A
how does input request and delete request so now we have created a user and this ID whatever idea I have written in here this I'm going to use in another test so let me create one more test void
81:33
Speaker A
update user and this is my another test and give priority three so here are given two and here I will give one one two okay and three so update user how to update the user almost it is same just copy the same but slightly change update means what we
82:01
Speaker A
have to just update the body right again we have to prepare the data data so previously the name and job is updated like this now this time I'm just changing the data so here I can simply say okay so here I simply say some designation let's say job I've got changed as a job okay and also if
82:26
Speaker A
you want I can change the name also I can simply change name also name and job is got changed and this data I'm passing here same content type but instead of post we have to use put request and
82:39
Speaker A
check the URL is correct or not for put request update request I think this is the same URL same URL but here something is different same URL but here we have to pass ID of the user and which ID we have to pass whichever ID we generated in the second request create user this
83:01
Speaker A
ID we have to pass so whenever you executed this test the ID is generated ID is written into this variable so the variable is a global variable we created right so can we use this ID yes here instead of using instead of passing this to hardcoded Value we can just pass ID so what
83:20
Speaker A
we can do now we can just remove this hardcoded value and the concatenate with concatenate with ID okay concatenation concatenate with ID so this value dynamically get from the second requester once a user is created same user we are going to update with the another set of data
83:44
Speaker A
so here we don't need to return anything just we need to do some validation so for that what you can do you can enable then section and here we no need to get any ID so given when then
83:56
Speaker A
and remove the semicolon here because that's not end up end of the statement you can just remove this entire thing so then status code and the logger what is the status code for updation for updation 201 again it is same and I'm logging all the response in my consolator so this is a how
84:16
Speaker A
we can update user so now create user update user these two tests are linked together so create user is linked with the update user so if the create user is successful then only we will able to update the user is there any dependency or not yes so in test engine we have some feature for
84:40
Speaker A
example if this test is passed or successfully done then only execute the next request if the create user is got failed then obviously I can skip update user how we can achieve that unnecessarily I don't want to execute update user every time if the creative user is successful then
84:59
Speaker A
only I will execute update user otherwise I just want to skip update user how we can specify that so before executing this update user I want to check create user is pass or not how it is possible people who already know test NG they should know this
85:17
Speaker A
yes we have to specify the depends on methods so we can add one parameter here depends on depends on methods equal to in the curly braces we can specify what is that method create user okay so then before executing this update user it will check create user is passed or not if the create
85:39
Speaker A
user is passed then update user will execute otherwise it will skip it and uh from where this will get this ID before update user we have to execute a create user then only we will get the ID and that ID I can use in the create user method okay done so let's try to execute and see
86:00
Speaker A
now second request create and update our both are linked together so we have to execute them one so I will also enable the first one so one two three totally three requests we have automated get users create user then update user okay so let us try to execute run as test engine test
86:31
Speaker A
okay now everything is executed now let's see update user is got failed so white has got failed we are expecting 2 0 1 but it is a returning status as 200 let us see for update user what is the status for update user
86:52
Speaker A
put request right for put request you can see for put request uh 200 is a response actually so we have put invalid value that is actually 200 not 201 okay let's write execute and see once again okay so now you can see all three requests have got pass create user update user and get users
87:33
Speaker A
everything is got passed fine so so far we have achieved three different type of requesting get update get create and update now let us see deletion path so let me create one more method void delete user and it is destination I'll say priority equal to 4 okay now again same
88:01
Speaker A
thing we will repeat first of all what is the section given next one is what when next one is what when the next one is what then so first write these three statements then you can divide entire statements into three different parts okay now for deletion
88:19
Speaker A
of user do you have any prerequisite in the given section for deleting users but just go here for deleting user do you want to pass anything as part of request body not no need right you can just keep this empty now go to when section here we have to send a delete request so dot delete
88:39
Speaker A
dot delete and here specify the delete request URL so this is a delete request URL and again this ID we should get dynamically this ID so I can say plus ID concatenation so whatever ID we used here for updation the same ID I am using here for deletion
89:03
Speaker A
this is a delete request and what are all things we can validate after deletion what is the status code which is giving let us try this 204 it is giving so let's change the status code dot status code is 2 0 4 and do we have any content in the response body
89:24
Speaker A
nothing is there right after deletion there is no content displayed in the body empty so even if you put dot log dot all it will not give you any response but it will give you some headers information because even though we don't have any response body content it will return some
89:41
Speaker A
headers cookies and other information right so we can still use it dot lot dot all we will have a separate session for this logging logging process but for now just understand at very high level so there are again multiple options are there in this log method we will discuss them later so
90:01
Speaker A
this is a delete request given section we don't have anything in the when section we have to send delete request and in the then section we have to verify status code and then we are printing under the response in the console window so now all the tests are enabled get users is Priority
90:19
Speaker A
One create user is priority to update user is priority three and then delete user is a last request and again what are the methods are linked here after creation of users we are getting the ID that ID I'm using in the update user and also in the delete user okay so
90:45
Speaker A
so we don't need to delete anything because the this is just a variable right we have variable we are maintaining to store the ID so that same ID we are using in every request so let me just run as a test NG test so here we don't have such type of concept
91:02
Speaker A
unsetting or undeleting variables no this is a programming language in the programming language once you declare a variable that is still alive okay that variable we are using throughout the automation script wherever it is required so we can't unzet or we
91:20
Speaker A
can't remove that variable okay yeah so now all four requests are successfully executed create user delete user update user get users and if you see here all get user create user update user did all are successfully executed so this is how we can just automate the dash in
91:41
Speaker A
rest assured the process is same but again we will learn so many things here what are the different things we can keep in the given section all these things we are going to discuss okay and a different type of validations even response body also we need to validate by using
91:58
Speaker A
Json path XML path so many other options or we can also verify headers we can also verify the cookies and as part of given section we can also pass authentication query parameter path parameter Header information content type okay in the coming session we will discuss in
92:14
Speaker A
detail so here in today's session I've just given very high level information just for understanding Basics okay so once it is done so in the next session we will continue further okay
Topics:Rest AssuredAPI TestingREST APIsJavaEclipse IDETestNGMavenHTTP MethodsAutomation TestingBDD

Frequently Asked Questions

What is Rest Assured and what types of APIs does it support?

Rest Assured is an API/library used to automate REST API testing. It supports only REST APIs and does not support other API types.

What are the prerequisites for setting up Rest Assured?

The prerequisites include having Java and Eclipse IDE installed, TestNG framework added to Eclipse, and Maven for dependency management. Modern Eclipse versions bundle Java and Maven.

Do I need to install Cucumber to use BDD style tests with Rest Assured?

No, Rest Assured supports BDD style test writing by default and does not require additional Cucumber plugins.

Get More with the Söz AI App

Transcribe recordings, audio files, and YouTube videos — with AI summaries, speaker detection, and unlimited transcriptions.

Or transcribe another YouTube video here →