Appium Beginner Tutorial | How to add extent reports in Appium Java project

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello and welcome today we will learn in a very easy way how to add extent reports to our APM Java project and this will be very easy and very interesting and I will go very basic step-by-step so here we have created our Java project in the earlier session for appium and you can see this is the project happy m demo project and this is a maven project and we have we are also using test Angie and if I go inside the SSA test Java and under test folder we have created a base class and tests class so this is what we have done in the earlier session now I want to add reporting to my project and for that we can use extent reports so I will go to Google and search for extent reports and this will take me to this website extent reports comm this is the official website for extent reports I will go here and you can see this is our report that we are going to create so I will go to Docs and you can see version 4 is the latest I will go to Java and here you can see some documentation and to download we can use a maven dependency or Gradle I will go to maven so here you can add a dependency like this I will go to maven repository and here this is the maven repository and when repository dot-com website and here I will search for extent reports and you will see this is the extent reports which is from comm events tech I will go here and you can see all the versions here I will go to the latest version which is 4.0 dot nine at the time of recording this video and I will just copy this maven dependency from here and go back to my project go to form dot XML and here I will go down and in dependencies section I will add it and to correct the identity I will select everything and press control I or command I in case of math and now I will save the project once you save it will download all libraries and I can also go to project and clean the project so I will say clean and now we should be having all the extent report libraries in our maven dependencies so here you should be having all the extant reports libraries and you can see like this so we have added the library or the dependency and now I can add the code so if I again go to the extent reports website here now here I can go to I will just go back and I will go to Docs and I will actually go to version 3 and go to Java because there is some very good documentation available here if I go to the basic usage and not the basic usage I should go to the examples so yes you will see examples at the bottom I will go here and under examples we have basic usage example and this is how we can use it so this will be very handy I will go to my project and now under the test folder I am going to create another class I will select a new class and I will say this is extent reports demo you can name it anything don't limit as extent reports because that is a class that we will be using so I'm seeing extent reports demo and say finish now here this is my class I will create some setup and teardown method so I will say public void report setup and I will say public void report clear down and this I can say this is before sweet so I want to run this before running all the test cases so I am using the test ng a notation before sweet and here I will say after suet and I will import from test ng now I will add the code to generate report here so if I go to the example you can see this is what we have to use so I will just copy it from here and I will add it here so the first statement is extent HTML reporter and any variable name new extent HTML reporter and this is the report name now if you just give the name without giving any path it will get saved in the main folder of your project or the home folder of your project so this if I say extend or HTML it will be saved below this a p.m. demo project folder or you can give an absolute path so I will just keep it as it is for now and then I also have to import it so if I hover over this if I hover over this HTML extend HTML reporter I will import it from com dot events tank extent reports reporter and I will save this similarly this extent report I will again over over this and import from extend reports here and that's it so we have added this code and now if you see this we can now create our test cases and then we can keep on adding the log statements so here when wherever we are creating our test case we will add these statements so if we have a test here so for example I have public void I will say demo test and if I give the annotation at test this will be a test ng test and inside this function I can add this code however we do not want to add it here we want to add it to our test cases that we have already created in our earlier sessions so I will do that and before I do that we also have to flush the report in the after suite function so this is the last statement that you should be calling after everything is done so this is extend not flush now if you see here it is throwing an error because this extent variable is created inside this function and it is not visible here so to make it visible to all the functions I will just copy this and take it to the global level or the class level and here I do not need to have this and similarly this extent reports extent also I will copy and add it to the class level and I do not have to use this here I will select everything by pressing ctrl a or command + a on the keyboard and then press ctrl I or command I on Mac to correct the indentation and now this is done so we are also flushing the report now if you see in our base class so this is the base class we've already created where we are setting up the mobile driver desired capabilities and then everything from here is being used in the test class where we have our tests so we cannot directly use this extent report functions or this extent reporter extend all this here so for that I will have to in the base class I will have to say extents so I will say extend and I will say extent report demo class so our base class is extending the extend reports demo class and then our test class is extending the base class so whatever functions and variables I have here will be visible to the base class because it is extending this class and whatever functions variable we have here will be visible to the test class so everything that we have here will be visible now in test class so we can create our test separately in the separate class and still use the extent functions now you can also have this before suet and after suet methods within this base class so you do not have to create a separate as ten reports demo class you can have everything in the base class but just for easy understanding I have created this separate class so now I have done the extension as well so now I can go to tests and here inside every test I will start our test statement for extent reports like this extent test and I can give the name and the description like this so I will say here so here I can say I will go to the okay this is not required I will just import the extent test class and that's it and here I will say this is test one and I can give some description sample test case for a demo and now on every step I can keep on logging the statements so for example I can log on info statement like this so I will say here test dot log status not info this step shows some usage logs or I will just say here test one started so this is information and here again I have to import status from event stag extent reports and that's it so I can name this as test one and here I will also say test one and then whenever I do any step I will say again test one dot log now instead of info I will this time say pass and I will say here because this will pass and after that this will run the statement I will say navigate to HTTP google.com similarly after this step I will say test one dot log pass and here I will say enter automation in Google search box and here I will say this is again pass it to the keyboard Enter key and all these test cases we have created in our earlier session and then at the end I can again just log information message I will say log dot status dot info test one completed also you can see instead of info and pass you can have multiple other statuses like debug.error failed fatal info skype etc warning as well so you can do this so for now I have just done this and then we are anyways flushing the report which is important now if I run my test so for that I have to make sure my device is connected and IBM server is running so I have connected my Android device to my laptop if I run ADB devices I can see my devices there and to run the appium server I will just say IBM and hit enter and they should start at him on the default server default port for 7 to 3 so now I can run my test and we should have a report called extent or HTML created this time so I will say run s test in G test and let us see and also I will show you my mobile device it is here so you can see that mobile devices here with the help of wiser I can see the screen of my mobile on my laptop and let us see it is running our test we can see their logs on a team server ok I think this we had in the last session we were doing tests on iOS so that is why it is starting iOS let me stop this because I us it will take some time to start the emulators and to start the simulator so I will just say Android and I will turn this again and I will just quit the stimulator and yes now it should turn on Android device so we are getting the logs on appium server and they should open the Chrome browser and yes it is opening the Chrome browser and running the login test so for login test we have anyways not added the extent report statements so that is fine we can do it later so this is running fine so our login test is done now it should run our Google search test and they should also be logged in to our reports and this is the third test this is done if I go back to eclipse let us wait it is still running so if I go to destiny results you can see everything is fine and now if I go to my project folder here do a right-click and I will say refresh and you can see as I refreshed you can see extend dot HTML is here if I click here it should show me the extent report and it is here and I will open in a browser so I will say right click open with system editor it will open in default browser of your system in my case this is Safari and you can see the extent report here and from here you can change the theme you can see this bottom left there is this button I will click this it will change into dark theme and this is our extent report so you can see the status here pass/fail and here you can view the dashboard toggle dashboard here if you want to search anything you can search it shows the overall status these are the filters here so if you do not want to see pass or fail only all this you can do here and here this is our test as of now we have a single test we have not added more than one test in the report you can see here the start time the end time and the total time taken and all the steps here again here are some filters and all the steps here and if you go to this view dashboard you can see the overall status and here you can see the again the filters the time and the number of tests number of steps and all these things are here and again now if you go to your tests and you can keep on adding these log statements wherever you are running your tests and with every statement you can put the log statements now you might have a question that when it fails how exactly we are going to log so for that either you can put a try-catch for every test case and whenever there will be any error or a failure it will go to catch block and for in the cache block you can log failure or error for extent reports or we can also use test ng listeners so test ng listeners we can see later on but this is how in a very very basic way you can use extent reports in IBM Java project I hope the session was useful for you and if you have any doubts you can put them down in the comment section below and I will try to reply you as soon as I can and I will meet you in the next episode thank you for watching
Info
Channel: Automation Step by Step
Views: 15,333
Rating: undefined out of 5
Keywords: how to use extent reports in appium java project
Id: dRv963BmbFg
Channel Id: undefined
Length: 16min 43sec (1003 seconds)
Published: Thu May 30 2019
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.