Extent Reports with Screenshots & Parallel Execution - Part 1 | Rahul Shetty

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
[Music] welcome guys this is your instructor Rahul Shetty from Rahul Shetty academy.com so in this video series let us try to understand what our extent reports and how to use these reports in any Java automation frameworks like selenium APM or rest api automation using rest assured okay so extent reports are one of the commonly used reporting techniques in most of the automation frameworks because they give lot of futures with dashboard facilities where no other reporting utility can come close to this and this is an open source right so based upon this people commonly use these reports for their framework needs so there are lot of information we have to learn about these reports it's not about just learning what are these reports you have to understand how to create for these for the test cases and also most importantly how to create these reports when tests are executing parallely okay so if you have some 50 test cases and when 50 test cases are running parallely all execution should be reported to one single HTML file with consolidation so that's an interesting thing we will go through each and everything to understand how to generate these reports in all type of situations and also at the end if something fails any of your test case then we will build one mechanism to automatically capture screenshot on test failure and that screenshot should be attached to the extant report for that specific test case okay so that's one of the cool feature and this will really really help you to find everything in one single place failure screenshots reports logs everything you can find in one HTML file okay so you need to come up with some code to achieve all this so in this video series we will try to understand step by step of we'll start from what is extent reports from there I will teach slowly and take you to go through all these concepts so that by end of this series you will know how to generate reports with all advanced futures present in this utility all right on high level this is how reporting looks like okay so right now I have four test cases here three are passed one is failed so that you will have one graphs like this with a pie chart showing how many pass how many failed okay and you will know duration of how many minutes these test cases ran and total test percentage start date you can also build like who is the tester who run this automation test cases everything you can configure and this is the report name automation results so you can customize this in your case if you are running API test cases you can say API results if you are running web automation then you can say web automation reserves everything can be customizable we can do it through our code you can also add tester name also from your code okay this is like high level and if you want to dig deep into it then you can go to that test where you have four test cases okay so I just had a sample of four tests and you can click each and every test to understand if it is passed or failed so right now this is failed validate have title and you will have the locks here why that test is failed okay so what is expected and what found so in general if something fails we will look into our eclipse logs right after your on test but with excellent reporting you can log your failure report directly on this file so that you can just come here and see by that fail and you will also have attach the screenshot so we will have some mechanism to automatically take a screenshot and test failure and you can attach it so that on failed test you see you a screenshot as well as test logs right so this is how we will gonna bring this extant report HTML file so i have taken sample for test cases and designed this alright so keeping this in mind let's get started so first let's create a new project in eclipse and we'll take it from there let's create one simple maven project to demonstrate this concept so rightly new project select maven okay so next and there are different templates maven provides so for automation you can simply rely on this QuickStart template so select this QuickStart template and do next right so here where you have to provide group ID and artifact ID to build any maven project you need to provide these two parameter values okay so artifact ID is nothing but it's a project name so here we are dealing with external reports and group ID is like package name so whenever you create Brayman project you should give version package artifact ID and group ID right so you can give any values so these will help you to identify your maven project unity now when you create this project and publish this project to maven repository anyone can download your published project if they can provide these details so that's why we will provide whenever you create new memory project will rely on this group ID artifact ID version package awesome select finish and that way you will see one maven template project you see that extend reports so whatever artifact ID name you provide that name will be your project name so when you expand you would see that one package is created with rafalgt academy.com right so our first thing is to get all dependencies of extend reports isn't it so pom dot XML is the place where you bring all the dependencies to support your extend portes code right so let me go back to our browser and I will go to maven repository so just search for extent reports here so it's not coming on the top list or you can just google extend reports maven so that will give you direct link you see that you can actually jump into that right so whenever you land on any page with Google search make sure you watch this section so we want to go with always the new version so tomorrow in your case you will see another new version number here so select that and then here you go so these are the dependencies we need you see that group ID artifact ID version so somebody created this extent reports and pushed their project in maven repository so that now for us to pull that extracted project if you give this dependent system and your form dot XML you will be able to access all those extant report Java jars okay so we don't need j-unit we will use test engine here let us remove that and I'll add extend reports and also we mean dustin's you to test Angie let's also use selenium so use the stable version which is available till date perfect so we got our extent report jars test Angie Jobs and selenium jars and that's it so these are the dependencies you need to work on to extend reports so for me to show demo I just need these information so that I can show how to create extend reports for your automation test cases ok so right so let me delete the existing test what got created by default and let's have our own test now so right-click new c we will follow an approach here first of all i would show how to generate extant reports with one single test i would pick one simple standalone selenium test to open browser and close and that way i can show you how to create a report for that simple test so once you understand that then we will add few more test cases and see how to generate consolidated report for all the test case results and then how to run them in parallel mode and have that consolidation happen okay step by step we will approach for now we will write one single test case so that you will understand the logic okay export firstly I would create one simple test to invoke Chrome browser and hit any URL ok so thereafter we will push extend reports into this class so I would create one test ng test initial demo is our method name right so move your cursor and import test ng related package import test perfect right so I will start with system dot set property step to define where my chrome driver is present and thereafter I will initialize chromedriver object webdriver driver screwdriver so let's import this package is very quick so now I will just land on our website Rakesh Shetty academy.com and there I would just take the title okay so once you land we can get the title of that web browser by using a method called driver dot get title isn't it so now to see this title in the output you can write this out so that title what it grabbed will get printed in your output so this is my simple test ok nothing fancy or complicated so how to introduce extend reports in this test right now so to prepare extend reports configuration I would write that in separate method maybe we can say before test so basically before test annotation will execute first before executing this test annotation isn't it method name I am using as a config and now let's try to import that right now let's actually define all the configuration belongs to extent reports so basically you have to remember and no two classes when you are dealing with extent reports one is extent report this is one class name external reports and another one is extend spark reporter so these two classes are very helpful for us to generate the reports extents Park report them so first of all we will try to create objects for these two classes and then I will show how to connect these two classes together in building the reports right so firstly let's create object for this extend spark reporter class and try to understand what exactly this means okay so to create object you need to write a syntax with new operator so here basically reporter is an object for extend spark report of so this extent spark reporter class expects a path where your report should be created okay so this is basically responsible for creating report so now you have to explicitly provide the path to store your reports so let's say I want to create reports by creating one new folder inside this project itself okay so to create the path dynamically through Java you can say system dot get property and user dot dir that will give you the project path dynamically no matter in which system you are working system dot get property user dot dir when you say this you will get the project path until extend reports so what is the project path until extend reports so this is the path in my system so this path will get automatically generated okay so under this path I have to create one more path like this slash slash let's say reports is one package and under the package let's have an HTML file so basically this index dot HTML file is the one which will have your extend reports okay so I would take that complete string what got created in one path variable so that I can send that path variable here awesome so this is the path so basically this path points to your project under this automatically when reports further will be created in that folder you will see this file so I'll carefully place that string path whatever I created in step number 15 because this extent spark reporter class expects that HTML file where it has to create write so import this perfect so that package is important and your error is gone so basically this extent spark reporter is responsible to create on html5 and to do some configurations so now let's do some configurations here now if you want to have one new name here so let's say you want to set your report to name as a web automation results so right now the existing report what we have it's saying automation results report right you can modify it using this reporter object as I said this object is responsible to make all configurations for your report so reporter dot config select this method config dot set you see that there are lot of methods available here to manipulate your reporting file so set a report name so this is the method which will help you to set report name here so let's give the name saying web automation results so this is a bad report name now so if you move your cursor on top you are seeing a title called Academy results okay so this is a document title ok so you can actually tweak this as well so everything is configurable in extent reports so that's the beauty of this open source tool reporter again dot config anything you start like this object dot configuration dot set you would see a method called set document title so here you can say test results let's have a title name as test results perfect so now reporter object is created and that object holds some details right now you have to create another class object called external reports so this is our main class so this is the one which is responsible to drive all your reporting execution let me show you so I am creating class so initially only we discussed right we need to create objects for two classes now let's import all the relevant packages perfect as I said this is the main class now you have to attach the report whatever you created with extant spark reporter okay so with this class you created some stuff like basic configurations and you also set where your path files should be stored right so you created one report so attach that complete report to this main class because this main class extent reports is responsible to create and consolidate all your test execution okay so the extend Sparky reporter is a helper class which is helping to create some configuration and that will finally report to its main class so there is a method called attach a reporter okay so once you create report you have to attach it to your main class and here you have to give the object of extend to spark reporter right so this is our object right so simply attach object so that automatically now your main class will have knowledge of your object and this object provides all these details perfect now if you want to say the tester name the tester name you can actually give it throw your extent reports main class we can say extent dot there is a method called set system info okay so here you can define your property called tester and you can write your name I'm just writing off your city for now awesome so that's it so you have successfully created a main class object which also have information about ods configuration now how to use this main class object here so till now what you have done you just created one file and gave some configuration but how you're testing is the report will be attached to this main class variable is our cushion now in your actual tests first of all you have to clearly say that when this test case is being started executing you should say extend dot you see that I am NOT able to call any method from this extent class object because this class is being created the variable is created which is local to this method and you cannot access this object outside this method so to make this happen you have to declare this extent reports variable in global level okay so if you define a global level so this extent object now can be handled in subsequent methods as well so remove it here because you already created and now you say extent dot you will have all the methods available you see that create test so you have to explicitly say that create one new test in the reporting file okay so once you create test and that's it automatically this variable will keep on monitoring the result of status of this if it reports pass then it will go back and update this test result as pass if it fails then extent will go back and mark it as a fail okay you need not worry about anything you just need to create test so that this extent object is aware there is one test case which is being executed so that it will create one in your report okay so this step is mandatory in every test so that extent report will have knowledge about what's happening and you have to provide test name okay so initial demo so this is our test name let us assume that so for now I am showing it here in our subsequent lectures I would show how to inject this extent reports in framework design you will not write anything in your test everything will be driving through test engine listeners and extent utilities I'll create one utility file so don't think that for every test I have to write all this information so first to understand core concept I am showing you and standalone test so that in next lectures we will separate these pieces and spread it into different parts so that it will have some framework field once you will test is done at the end you have to say extend our flush we'll be notified that test is done and it will no more start monitoring it okay so this method is also mandatory to add at the end of your complete execution let's say you have five Nesta cases after 50 test case you can do this flush method so that report will being generated for you okay so if not it will be still in listening mode awesome so that's all you need to do this is one simple test which will create my new test in extent reports it will monitor the results and after you flush it will update the status with pass or fail and it has done some basic reporting as well so let's run this test and see how this goes so this simple test should create one extent report file and report about this initial demo test results okay so it invokes storm browser just hit that URL of Rahul Shetty academy.com and that's a test execution is done awesome right so there are no failures and you can now open the report let's refresh this project right click refresh and you see that reports folder is being generated so inside this folder there is one index dot HTML file okay so let's cover this and let's go back to our browser and here you go so this is our first basic reporting of extant reports so when you go to dashboard you see that we have updated name - web automation results with configuration change using extents Park reporter and title name also you see test results and tester is Rakesh Shetty and here we have only one test isn't it so that test name is initial demo right so we created a new test saying initial demo and that's why it created and it passed because there is no failures now we will try to forcibly fail the test and see how that goes when you create test automatically one object is created for you complete test method okay so you can catch that object by writing extented test test right so this is the object comes from extend to test class so whenever you create test the extent reports will create one object which is unique to your test method so this object will be responsible to listen and report all the happenings back to the extent report okay so using this object so whenever you create first create test method this object will be created and you can use it in your further steps if you want to tweak that reporting for that specific test case now if I want to report a failure test dot and there are a lot of methods here if you want to attach the screenshot for the result of that specific test you can say test the dot add screen capture okay so when you add screenshot here automatically extended person know that this test object belongs to this method right so that will attach that screenshot to that specific test method so all this happening because of that newly object created right with this step now if you want to fail also if you just say dot you will have some methods here which will help you to fail your test okay so you can just pass the string saying result do not match you can close your browser once the execution is done so that browsers will not stay open in your test right so when you run this test now that will report fail because you are explicitly failing your extent report object so automatically this will go and report that my test got failed and accordingly it will get updated in your report file but do remember ideally we will not do this in our test because we don't know when it fails right so I am explicitly failing it but in real time it may fail at any time so that is why in our coming lectures we will integrate this to test ng listeners so that whenever your testing has failed automatically test ng listener will capture it and it will execute failed method right in that method we will pass this code so that way anytime whenever you are test is failed that listener will be invoked and that will report to extent reports that your test is failed not very we will see that so in this lecture I am trying to explain you some basic things like how what extent report generates with a fail method how test is created how configurations are done how to attach back to reporting so if you know these basic details in the next lectures when I talk and integrate this test engine is nice and parallel execution you will not get confused okay so if I teach everything together that will mess up you right so let me run this test and see what happens this time so it will again open the browser and do the same operations but we are reporting failure this time we are doing it explicitly okay awesome so let me go back to reporting refresh the browser and you see that you are testis failed now okay results do not match so whatever string you provided here is showing up here saying results do not match though your test is executed successfully here but while reporting to extend reports we are reporting as failure so that's why extend report have updated it so if you don't report then by default it will treat as a pass okay if your report failure then only it will turn to red mark okay so that's why in our next lectures we will handle listeners and whenever test is failed we will use this method to report to extend reports so this is the basic of extend report code which you have to know so keeping this code in mind let's try to introduce a framework related things and see how we handle this extend reports in real time when you have multiple test cases in place okay see you in the next video thank you
Info
Channel: Rahul Shetty Academy
Views: 14,144
Rating: undefined out of 5
Keywords: extentreports, selenium, automation, framework, testng, testnglisteners
Id: w5FbRziAzvo
Channel Id: undefined
Length: 28min 31sec (1711 seconds)
Published: Fri Apr 10 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.