REST assured complete project on IntelliJ IDEA | Beginners Tutorial

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello and welcome to this beginner's tutorial on how to create a complete rest assured project on intellij idea i'm raghav and you can find all my work on my website automationstepbystep.com and in this session i am going to go very basic step by step so do not worry if you have no prior knowledge on rest assured or intellij i will go very basic and we will first learn the prerequisites and see what are the prerequisites required for our project we will create a median project we will then add the rest assured libraries in our project we will then create our first api request with the rest assured libraries and then we will finally create some reports so with this let's get started and first let us see some prerequisites the first prerequisite is you should be having java jdk on your system so for to check that you can go on your command line so let me go on my command prompt and you can follow this session on windows or mac operating system so if you go to your command prompt on windows and say java space hyphen version you will see the version of java on your system in case you do not find java or you get a command not found or some error i will show you exactly what to do in a moment but for now you can just check this command and you can also say java c space hyphen version to check the compiler version of java and then you can exit from here in case you are on mac you can go to terminal so i am pressing command space on my mac to bring up the spotlight search and then i will start typing terminal and i will hit enter to go to the terminal app and again here i will say java space hyphen version and java c space hyphen version to get the version of java and then i will exit from here now just in case you do not have java or jdk on your system you can go on my website that is automation step by step dot com and here if you scroll down you will find a link so under the programming section you will see a link for java this will take you to my youtube playlist on java and here you can see this video for windows how to install java on windows and for mac you can see this video how to install or update java on mac so once you have java on your system then we will go to the next prerequisite that is we should be having some ide that is integrated development environment where we will create our project so in this session we are going to use intellij i have also created a session on rest assured on eclipse earlier but this time i am going to use intellij and just in case you are completely new to intellij idea do not worry you can again go on my website automation step by step dot com and here under the ide and editors section you will see intellij idea and then you will it will take you to the youtube playlist and here you can see the beginner tutorials on intellij you can watch the first video how to download and set up and this will get you started with intellij and in case you want to use eclipse i already have a separate session for rest assured on eclipse so you can see there is a session for restaurant beginners and rest assured this is on eclipse and then the next prerequisite is you should be having maven on your system so if you go to your command prompt now this is not mandatory for now if you say mvn space hyphen v or mvn space hyphen version this will give you the maven version but even if you are not having maven for now it is okay uh we have maven already built in intellij idea so if we are going to run our project from intellij it is okay you do not need maven separately but later on when you want to run your project from your command prompt or terminal then you will need maven and just in case you want to learn that time again you can check my video here you can search for maven you can see here it is so this will again take you to my youtube playlist under build tools you will find maven and here you will see videos for windows and mac on how to install and get started with maven so we have this prerequisite and then test ng you should be having test ng added on your ide and in this case it is intellij and again for that you can watch my video under the intellij playlist we have this video here how to use test ng and how to get started with test ng on intellij so with this you will complete all your prerequisite and then we will move to the first step and that is we will open our intellij idea so i will go on my windows system and let me exit from here and i have my intellij open here so here i am going to create a project so step number two is we will create a maven project so i will go to projects and then say new project i will select maven here and you can select the jdk that you want to use in case you have multiple jdks on your system you can select the jdk from here you can also download a new jdk so i will go with this default for now see next i have skipped archetype selection i will directly give a name to my project so i will say rest assured project 1 and you can select where do you want to save it so i want to save it under let us say i will change the location i want to go to intellij projects and under this i want to say rest assured project so it will save here and then you can see this is the group id which is usually the company domain so let me keep it as it is and then you can see the artifact id which is usually the project name and if you want to give a version like this you can give let me keep the version as 1.0 and that says i will say finish and it has created a project and you can see the palm.xml file is here and this is our palm.xml file where we will manage all our dependencies and here you can see maven if you click here it will show you all the maven details so this is our project these are the maven lifecycles these are the when we add our dependency you will also see a section for dependency here and you can press ctrl e on your keyboard and you will see all the recent files and sections so you can go from even from here as well and this is our project structure so we have done step number two and now in our pom.xml file we will add dependencies for rest assured and test ng so testng is a testing framework that we will use and rest issued is our library for api testing so let us go to our palm.xml and here as of now i do not have any dependency section so i can go to code and say generate and i will say dependency so i will say rest showed and i am going to take this from io dot dresser showed and you can also check this on the maven repository and if you want you can get it directly from the maven repository as well so if you go to the maven repository and it is here mvnrepository.com and search for rest assured and you will see this is from io dot rest assured and if you go here you can see 4.4.0 is the latest version as of the time of recording this video and if you click here you can directly copy the dependency from here and copy in your palm.xml file but in intellij we have the direct way i can directly take it from here you can see this is again the latest version 4.4.0 and this is coming from io dot rest assured i will say add and you can see the dependency is added here i want to add dependency for test ng as well so again i will go to code and say generate there is a shortcut as well alt plus insert you can use that i will say dependency and here i will say test ng and here it is org.testng this is the latest version i can again verify it from maven repository i will search for testng and i want to get the testng library from this org.sng if i go here you can see this is the latest version 7.4.0 so this is what i'm getting it here so i will again add it and that's it i will save my project and if i go to the maven section now and click on refresh you will see there will be a dependency section and i have both of my dependencies added here and the best part of using maven is you can see there are some other dependencies or requirements that are needed for the primary library like in this case it is j commander or jquery etc so all this will be taken care by maven you do not have to do anything manually but if you create a java project then you may have to download and add all these jars manually so this is the advantage of having a maven project and you can check here as well under project external libraries you will see all your external libraries edit we have rest issued here and you will find test ng is here so everything is now added and our project is ready so we have done step number three now step number four is i will create a class and add some methods so let me go to my src folder and i have a test folder here a java folder here i can just create i can create first a folder and then put my files or i can directly create a java class and i will call this as api tests you can name it anything i'm calling it api tests and that's it so it has created a java class and now i will create a method so let me say i want to create i will say void and i will just say this is test one and that's it and to make this as a test ng test i will have to give the annotation at test and you can see it is giving me auto suggestion that do you want to get it from og.testng.annotations i will say yes and i will click and you can see it has imported this from here now i will have to write my api test so let us say let me just take some examples so you can use your own apis for now i will find some sample rest api for testing online and i will just go here req res dot in and here if i scroll down they have some sample apis for testing let me take this get api which is list users and you can see this is the api endpoint here and this is the response this is how i should get the response so i should get all these details of multiple users and this is if you click on this url or the endpoint it will take you to the complete url and this is what i can use in my api so i will say here so because this is rest assured i will say rest assured and you can see because we have already added the maven dependency i am getting this option i will say rest assured now i will say dot and because this is get i will say get and then i will have to give the url here so i will say i will copy and paste this endpoint or url of the api and then i will give a semicolon to end the statement so this is a method in rest assured to run a get request now if i want to store the response in some variable i can use the response class from rest assured so i will say response you can see again this is coming from rest assured i will take this and say i will give some variable name i can say response here you can use any name here and because java is case sensitive this response is different from this response so this is just a variable name and now our response will be stored here and using this response now i can get the details so i can say response dot get status code so this will give me the status code i can also say response dot get body or i can say response dot get header you can see get body get content type all these things i can get and to print it on the output window or the console i will have to use the print statement so i will say s out and enter so this will auto complete the print statement and here i will say i will put this status code and if i want i can also append something for easy readability so i will say status code will be this and similarly i will say s out and i will say here i want to also print the response so i will say response dot string so i will convert it into a string and print the response and let me just keep this at the top i will cut and paste it here and then i can also add i can say s out and then i will say here body and i can say here response dot cat body and it is here and again i will take print it as a string so i can do this i can also get the time of the response i can say here time taken and i will say response dot get time and there are so many things you can do so let me say if i want to get a header so i will say header value and i can say here response dot get header and i can also give the header that i want so i will say the header that i want to get is content type so all this i can do and let us try to run this now so i will you can see we have got a run button here so it will run all the methods i can run a single method by using this run button i can also do a right click and say run from here so all this i can do so let me just run from here and check the output and let us see what do we get so this will build the project first and then it will run and it is now running and yes it is done and you can see it is pass and you can see here this is our response this is our status code this is our body this is the time taken in milliseconds and this is the content type header of the response which is application json so this is how you can now run any of your apis now let us say if i want to do some assertions i can also store into some variable for example i want to check the status code i will create a integer type a variable which i will call as status code and then i will store the status quo from the response so i will say response dot get status code and then i will say assert dot assert equals and then i have to give the actual and the expected so actual is whatever we get in the status quo variable and the actual that we want to check is let us say 200 so you can see this is what we are doing here let me save and run again and let us see what happens now so it is building and running now and everything is passed you can see the accession has also passed just in case i change this i will make it 201 and now if i run and check this time the session should fail and it is building and you can see it has failed and you can see this is the failure there was a session error and here i can see the details as well so expected was 201 but actual was 200 so this was a error so this is how you can also add assertions now uh just in case if i make if i do a static import of the rest issued library let us say here i will say import static io.rest assured and let me say dot star so it will import everything now in this case i do not have to use this rest assured i can directly say get here so in case you want to do a static import and then directly use uh the methods of the rest issued library you can do like this and now i can also create another test and show you so let us say i will say test2 and now because we have done a static import i can directly say i can use i can just say given dot get and i will give the url which is this one so here i am also using the gherkin language given when then etc i will show you uh how you can learn bdd as well in a moment but let me just complete this statement i am saying given get this particular url then i want to check status code is 200 so you can see in a single line i am running a statement i am running this get api and then i am checking the status code is this if i want i can put this in different line as well for easy readability so i am saying given then and status code so this should also work let me try to run and check so i am going to run this again and see so this is building the project and yes you can see this is done and and we missed something it did not run test two because we have not added the test ng annotation so that was my mistake i missed it and now it is fine i will save and run again and this time it should run the test 2 as well so this is done and you can see test 2 is also executed and everything is fine so we are able to run the test now uh here we have created a class and a method we have also added a code to run a get api request we have run the test and then we can also add the test ng run configuration and then check the test ng reports and i have shown this in my test ng video on intellij you can check from here and let me also show you now so i can go to run and go to run and edit configurations and before i do this this should be a test ng plugin added in your intellij and by default it comes in built with intellij but still if you want you can check here you can go to settings and go to project structure you can also go from file menu and go to project structure and sorry this is not project structure you have to go to settings and go to settings or directly go to plugins from here so this will take you to the settings and plugins and here in the installed search for test ng and you should see test ng plugin which is installed and active just in case you do not find it you can go to the marketplace and then search for test ng and install it and then you can go to the run and edit configuration and here i will say i will go to testng and then create a new configuration i will call this as run as testng and i will select the class which is api tests and then under the listeners i can add the listeners like emailable report listener etc by using the plus button here or i can just say use default reporters apply and ok and now i am going to run as tess ng you can see now i am getting this option run as test ng so let me use this and this will also create some test ng reports for us and you can see it is run and you will find a new test output folder here which has these reports if you want you can select where you want to store the reports again you can go to the run and go to edit configurations and here you can see you can select the output directory here so it has created some reports if i go to the folder i will [Music] copy the location of this folder and then let me just open it into my window i will go to my system and go to a folder and i will open this here and you can see here we have got emailable report and this is how the email emailable report looks like we have test 1 test2 we have the status pass fail time taken etc and this is the complete status of the project and then you can find some more reports here so here is index.html and you can see the report here so you can see two methods two passed and you can see past methods here everything is available here so you can check all these reports and you can create test ng reports like this in your rest assured project and this is how you can create a complete test as your project in the coming session i will also show you some more options some more features we will create and run some more api request and please do hands-on and if you have any questions or if you face any doubts please let me know in the comment section below i will see you in the next session thank you for watching and never stop learning
Info
Channel: Automation Step by Step
Views: 62,436
Rating: undefined out of 5
Keywords: rest assured tutorial for beginners, rest assured api automation framework, intellij idea how to create rest assured project, rest assured on intellij idea beginners tutorial, rest assured project, rest assured automation framework for beginners, rest assured api testing quiz, rest assured project setup
Id: Orn8cP1yRJc
Channel Id: undefined
Length: 25min 37sec (1537 seconds)
Published: Tue Aug 31 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.