TestNG Listeners & Extent Reports

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
the array that is a basically inner what is the essential is nur so when I write testing the test suppose if it is paid or if it is passed we are sending the path of failure message to the report right so when I open the report we can see the home in ear password how many are failed to test cases so then what is test angel' is not here so just understand what is the concept of this then we go for the program so what is test 10g Lisner so test angie listener or a class basically it is a class so which contains certain kind of methods okay so those methods will be automatically executed or automatically called whenever your test gets or fail or fast okay so let me give one example here like this suppose sometimes there are some situations for example let me give the diagram okay so now I have a test case I have written some test cases test case one test case two case three and similar way so this is a normal XML file Algrim this and this XML file will execute all my Java classes one by one right this is a test and XML file so we have many number of Java classes and the inside is we have different kinds of methods so if the particular test is passed or failed what we are sending now we are sending that information to the test ng report Stanzi reporter so this report contains either pass or it contains either fake so nothing else we are doing so what the essential listeners will do is suppose if test a particular test is passed what we need to do what is the next action and suppose if the test is kicked so what we need to do suppose the test is failed so what is the next action we can do so immediately instead of writing the path of failure mission if you want to do some other addition operation some other additional things suppose so many things we will do so not only sending path of failed message apart from this what we will do is whenever the test cases are fail or whenever the test case is passed or whenever the test case is keep what we will do is add additional operations we can write the message to the report that is a normal or normal operation apart from this we will generate the log files we will generate the log files log file innocence every test case whenever we are running it will log some messages in the file so that is basically log files so every application or every automation script should have some log files so so what is the use of log files suppose if some test case is failed somewhere so in the real time you have hundreds of test cases will go parallel running so some test case will somewhere it is fail so how we will know where it is failed exactly so you can see the back end locks you see the log files how many are executed very where the execution is blocked or where the errors are getting so that kind of information you can see in the logs okay that is the main uses of logs so usually applications will maintain the logs but here in automation also we will maintain the log file automation logs we can say like the automation logs so that is the additional stuff we can J we can do it as soon as we test case or running or pass or failure or whatever in whichever test static maybe some test cases not started some test cases still starting and some test cases still running and some test cases are already passed some cestas or lipids there are different statuses will be there right so every status we need to log is statement in the log file every status so by seeing the log file itself we can say what is the execution process where they execute what are the test cases or encoding where it is stopped and what are the different kinds of errors we are getting so that kind of information available of the log file okay that is one thing and other thing is suppose any test case is failed so immediately what we need to do is we need to take the screenshot so wherever it is fail so immediately why it is failing me if you want to analyze you screenshot is required right so we will take the screenshot on failures right so this is the some example I am giving here so apart from the pass or fail message sending to the report apart from this we also do logging and also taking the screenshots okay so like this we can do lot many operations okay so if you want to perform these things we should go for police is enough so listeners means it is a separate class we need to write listeners means it is a separate class we need to write so wherever the test case is passed or failed or skipped so what kind of action should be taken so that can be done by the listeners class okay now let me try once again now I have a test cases test case one okay and test case two and then test case 3 so on so number of test case I have this is a normal Java files okay so how we will run these test cases by using XML file by using X test and XML file we will run test ng XML file okay and then this is a normal class will execute one by one by all the methods and all the stuff and then suppose some test cases are failed or some methods are failed what pass was keep so whatever is happened what we need to do is we need to log that information all we need to take some screenshot up above this one apart from the sending information to the report so usually whenever it is pass or failure message what happens is automatically the information pass or failure message will be sent to the report this is a default mechanism of test ng but apart from this if you want to be additional stuff like we need to generate the log files or if you want to take the screenshot what we need to do is we need to write one more class apart from this class we need to write one more class this class contains listener matters test Angelenos metrics so visitor is a default class I will tell you what is the class name so if you import that particular class we will get different kinds of methods on star on skip or on failed on failure on success these are the different examples of methods so these methods which are already implemented in the listeners listeners class but we will import that particular class we will overwrite those methods based upon our requirement okay now will create one more listeners class this is a listener class okay now this listener class we need to specify in the tested XML now what happens when I run this test and XML automatically it will call our test cases it will going expiration is go popularly all executions will going on and suppose if there is any failures or passed or blocked or skip whatever is happened that kind of action will reason by the listener class and then immediately it will do certain operation maybe it will log the file not the information to the log file or if we take the screenshot or whatever it may be it will lose certain kind of things so this is a call as a basically region of class so this is a background about test engine listeners so what is test angelina's test engine listeners will decide the post action or pre or post actions after completion of test cases so what we can do after completion of test cases pass or failure message anyway we log into the report apart from this if you want to do some additional stuff then we can use a listeners classes this is a very important concept okay okay fine clear the concept is clear why we need to go for the business test ng listeners because if you want to do some additional operations apart from the pass or failure of test cases then we go for the reason obstruct this is a simple additional class and once we designed this class we need to specify this class in some XML file test and XML file so just we need to add one more tag here for this particular class okay and then we need to run this XML so this is the overall structure of test Angelis mess and then we will see now what are our listeners available what are all the different methods we will get so let me show you the program listeners so I have created a new package called isness under this I will show you first a normal test a login test dot java okay this is my login tester java tests ng test case so in this i have created two different methods one is login by email and here i am printing some message log in by email message and i am sending the message to o true message to the reporter see a set dot assertequals i am giving the two are same so what happens it will return true okay treat answer true to the report and then here login by facebook i have created one more method here as the dot as a t equals i am giving the separate names so it will return the false so what does it mean in this particular test one method will be passed and one method will be failed okay now let us execute this test alone test NJ test okay so now two test cases are run so one is failed so this is a normal simple test case okay then this is a normal test case suppose if you want to run this test kit through XML file how editorial we have I have created one more XML file here that is listener dot XML file so open this XML file so here this is a normal you can name it any name okay so it is busines is not mandatory you can give it any name just like a test ng XML file so here as usual we know first we need to define the suit and then test within the test classes and it allows us we need to space with a class and here we can also specify the methods so in previous examples in the last classes we don't say we haven't specified this right we don't deserve a haven't specified any method right so we can also specify the metal stack so here under methods I say like include name is equal to log in by email include name is equal to log in by Facebook so here also we can control water all matters we can execute or not execute so for example so I have a two different metals here right suppose at the runtime I don't want X good one of these methods suppose I do not want to execute login by email so what I can do is here I can say one more parameter enable is equal to false so this is the one way I can do it so he is a capital thing this is enable one second right enabled is equal to false so if I make this enable is equal to false false parameter what happens is when I execute this test case at the runtime it will ignore this particular test case it will ignore this particular matter so this will execute so this is one way otherwise suppose if I don't want to pass any parameter here in that case we can control from the XML file so in the XML file you specify all the classes right in the classes class tag we will specify the class actually class name you need to spit this file so this is more than enough in order to specify this but if you want to control at the method level then what we can do is we can add one more method methods attack methods here it is started and it is ended so inside these methods we need to specify the water or methods should be executed at the runtime and water all matter should not be excluded at runtime so we need to specify include or exclude list include and exclus oh now I say both are include so now when I exit this what happens is and Xcode is XML both will execute okay let me show you so first thing is first I let me show you enable is equal to false okay so in previous or sometime back I haven't run this test case ID so both the test cases are I've executed and one test case got failed and one test case got passed now I will execute once again the same test case but I make this method is response that means this method will not big scooted at run time now let us execute and see run master string G test one test case I made it as a false right now we can observe this only one test case is a rooted that test case is got fate that is login by Facebook I am intentionally failed the test case because I have a given wrong information here see both of different and strings right so it is not equals there is a reason it will fail so at the run time we can control water run method should be run and water all method should not be run by using enable is enable keyword in a table parameter for the @test annotation so this is the one way so other I have one question but it is not showing in escape right what does so in escape that it is keeping one test case right here just my decimate allergic it makes good one second okay now it is executed see now now it will not show any skip here just it will do it just ignore that method even though if you have that method there is no use if you mention enable is equal to false it will not consider at all okay if you just ignore that method so it will run only that particular method one particular method you can see above so which method is executed so login by Facebook is only executed but that is failed I am interested failed this test case okay so one test is included then that one is also not counted in not compile not counter at in escape justice it will not count so this is the one way you can do it the other ways you can do this through XML file so in that case you no need to specify this okay then other ways let me write the notes because you will forget after some time we have to a test am enabled is equal to true means is always execute in able false means true is by default even though if it don't space by 2 or by default it will execute if they want to make any change so if you do if you want to okay if you want to if you don't want to execute that particular method in that particular case you need to make it as a forms okay this is one parameter of test temptation remember this so whenever you want you one don't want to execute that particular matter then specify this parameter enabled is equal to false okay now we have another method we can also control our methods through Excel or XML file so the other method is I have created Lisner dot XML file right so this is an XML file so here apart from the classes so actually we no need to specify this okay just a moment this is enough right just class name if is enough it will execute everything two test cases two methods it will execute but inside the class in addition I will provide the methods tag so if you provide the method tag so now you have a control which method should be included and which method should not be included now login by Facebook method I wanted to exclude this exclude means it will not execute the include means this method will be be only executed okay so now let us see now now both are enable here now let us execute through XML file run mash testa nice suit now you observe only one test case is executed what is the test case so it is past what is that one login by email logging by email is only executed other methods are not executed so because login by Facebook is not executed because in the test is not at XML file I mentioned this as a exclude also explode mean it will not execute so this is the other way of controlling methods if you do not want to exclude those particular parameters inside the cloud step you can specify one more tag called methods and then you can control it so this is the other way now to the actual concept so and we are in the tail is nazca alright so now what we can do is I have a created login test or Java I have two different methods one method will be passed and one method will be fit now in is not XML I make both are include okay both are into now if I run this XML file both the test cases oh please not login test with two methods will be executed now what I want to be is it will automatically send the pass or failure message to the report that is sure but apart from this I wanted to do something else okay so what else I want to do so if you want to do something else I need to create a listeners dot Java so this is another class we need to create the name can be anything but I have given the related name but the class name can be anything you no need to give exact listeners so you can give any name but inside this class you need to do one thing inside this class what you need to do is here whenever you create the listeners class it will create it then immediately you need to extend test the listener adapter this is actually Lisner class it is implemented by T test result I T test result is an interface actually so from that but your interface this is implemented okay so this is a basically class test tool is not adapter so now inheritance you need to remember here so what text ins will do business is a normal class we have created okay I say experience testing Lisner adapter testily is our adapter is a predefined class now I am extending that particular class so now what happens if I say listeners extends test will ignore adapter testing is not adapter is a predefined class just ng business we are talking about the test angeles nurse test angel is not adapter is a class predefined class now for example there is a class called this is a class what is the class testing Lisner adapter testing is not our adapter so this is the pre different class which contains a method so whenever we say class it contains it and made us write whatever closet may be so water'll methods it contains on tests start this is the one method it contains all right over here this class contains on test stock this is a predefined method again it is there in the particular class and then on test success this is also it is a condensed on test success and then the another one is on test failure on test it on test failure on test success so these are the methods which are already there in the test ELISA adapter class test Elizabeth adapter class remember this so from where this destination adapter class implemented the test listener adapter class is implemented by using a tie T test result interface okay so now we have to import that Butler test ng contains this particular thing okay so test technically is our adapter so whenever I say extends listeners what happens now so whatever is matters which are already defined in test L is never after we go we got those particular methods in our class that is a little Aslam you got my point this is just like a method overloading method overriding ending he'll test concept you do remember what is method overriding method overriding do you remember what is method overriding hello I have a Class A suppose I have a class area not really yes Class A contains M one and M two there are two methods which are defined already the body also defined now I extend another Class B here I extended from Class A now B contains again M one and M two right so but here the body is already defined in ei now again if I define body here what happens overriding will happen right this is overriding concept in inheritance method overriding yes right you remember now so whichever method we already have maintain subgradient class if i do the same method again if i overate the body that is basically method overriding in inheritance concept the same concept is applicable here so testa listener adapter is a predefined class which is already there which contains a 10-meters contest contest success on test failures on disk if we haven't to define these methods okay these methods are syntactically it should be same we should not change anything because these methods are already present under test tool is another after class now we are extending the capital R class by using reasoner's class this is our own class okay we can name it as any game this is not suggest I have given the related name and then what we need to do we need to overwrite the existing method so on test start it is already there in the test user it is not a laptop class now it will take one parameter of object parameter of I T I test the result I test the result is a predefined in interfaces here so it will take the parameter of this one every method will take some parameter of ie test result so here I say TR right so this variable can be anything again so I test the result is a class again this is an object so every method requires certain parameters so in another next classes coming classes you will understand why this is taking different kind of parameters okay coming classes you will understand this one so but as of now just remember this every method we'll take this eye test a result object as a parameter and then insert these methods whatever you want you can write it okay so in futures we are going to provide logging message screenshots and so much of information we are going to do but as of now just for understanding purpose I have created just a simple message here on test success you need to print this one on test failure you need to print this on test script you need to print this so this is a just a listener class so what it contains it contains different methods when these methods are executed so login test our Java have created two meters write the login test our Java I have created two tests two methods whenever this particular case is suppose it is started for example login by a man is started and then immediately this method will be invoked and then it will print this message and after that suppose this particular method is failed and then immediately on test failure will be executed and test failed message will be displayed and suppose logging the email is tip or suppose access or passed then immediately on test successful method will be called automatically and then it will print a test pass a message in your console window so why I am saying this is the listener class methods which are automatically invoked whenever your methods are passed or failed or skipped so that is a reason we are using the is now start Java 5 clear now why we need to clear is not Java file so suppose if I want to do a post operation suppose if my method is pain or suppose my method is skipped or pass so what is the next action I am going to do but that next actions will be provided under these particular methods so these methods are required from test listener adapter class just lizard adapter class and then we are over ready in the body according to our requirement okay now this well we cannot take route alone if I exclude this method if I exclude this class alone nothing will happen because even though this is a normal listener class this is a simple class right it does not have any annotation and also does not have main method alright both are dozen time so when I good this it will not execute anything so when I try to Xcode you will not get testing G or Java applications nothing you will get because this this is just a class it doesn't have main method and also it doesn't have any tester annotations for methods so this is a basically supported method this is basically supported method I told you right so this is a supported method I have a normal Java class and I have xml file if i run this xml file this java class will be executed but the test engine is not class is different Liz Mathis is different so we need to associate this listener class in XML file and then if you run this XML file automatically these two Association will happen by using XML file so whenever these methods are passed or whenever these methods are failed immediately these methods will be executed okay so this is the way up flow is it clear both of you clear yes okay now we observe this now I have this listener class alone we cannot execute this class so we can use this class in XML file so now go come to the listener dot XML so usually the listener dot XML file we specify the suit right and test and our test classes under class we need to special the class name log in to our test inside this number of methods and I have included both the methods now before starting the test unit include one more tank or listen abstract this is a listeners tank under listeners tag you need to specify the class - name equal to business dot listeners so what is this listener this is a package name package name dot mic business class listeners dot java class so this is the file right we have created all the listener parameters in this particular class so here is need to associate so this name can be anything again so whichever name you have given this file you need to cover this thing got my point so this is XML will associated both the classes so now before including this particular test XML we initiate this particular file this now start listen up this file and then log in test to exclusion will stop okay so this is association so only through XML only through XML we can increase normal Java classes and elizabeth-class there is no other way okay now we can run this this is no dot XML file so now let me run and see so in the listeners methods what I have written system dot out dot test is started suppose it's test you started it shows test started and on their success it will print the test pass on dash values it will print the test fail on tests to skip it will print the test script so this is the way you need to write methods now ignore the test L is not dot XML file and run as test ng not here run at testing the suit now you observe observe this now so one test case is passed one is paid for method pass one is method fit now you observe this output messages test started test passed okay and test again started and test to fail so from where these messages are coming from these messages are coming from the listeners dot Java five here I have written right let's movement so this is a regional road Java file test started whenever the test is started it is the test started on test to start then login by is executed it is passed so after passing it immediately this method is executed on test success inside this I have written test pass so test pass is printed here and then again one more test is there on test failure is over sorry not this one another test is login by Facebook so that is starting so before that test started is executed on test to start method is executed and then Facebook is login by Facebook is executed that is failed so immediately what happened on test to failure is executed on test failure is exhibited so that's the reason if test fee is coming right so only login by facebook login by facebook login by email these are the only two test cases I have created so suppose if you go here this is the main test right so did I write anything here test pass voltage scale something like that no right nothing I have written but from where we are getting those messages from Lee's nos Java from these master Java okay so this is the basic concept of test ng listeners so very important concept in the framework also we will get this concepts so once you are familiar this then once you Cramer come then you will understand that concept okay so one surprise you need to practice this mo any questions on this is it clear both of you what is testicle is also why we need to use test engine reasoner's what are the methods we have under test engine business class so these are very important interview portions also how do we connect those both and why Maximus my advice not Java and XML files both the Java files we will call club in XML file so if you see XML file your listeners the tag I mentioned the listener slash okay and login test is as usual so here let's now start logging test we have I this is the be no other day but additional thing is we have specially added newly added please nurse Stein okay here we into space field is a stacked remember okay so we should not add this listener class under the test again so here you cannot add one more class that is wrong because this is the listener class right it is not a normal class it will assist to this or main class that is the reason okay so this is all about the whole contestant business test ng listener so these are inter equations what is test about our test Angeles's what is the use of test angel' is not and what are the different methods available under test angel is not an actor's because these are very important okay now next concept very important concept then the last one is on test script right oh yes we can recommend on test keep fine so now these are the test Angelina's class and then we will move on to the test angel reports this is most important concept again one more important so reports is very very important context concept because management is always looking for the reports right we know they do not know daily ways we or how many cases we are running on yet are so many o'clock how many escapes so these kind of information they require but they don't want to see the numbers so they do they want to see the good kind of reports are you a kind of reports it should be very attractive and very colorful and also the data should be appear on the pie charts or graphs are something like that so people will like those kind of reports but - so far we have seen test injury four types of course if we go for the test Angie here by default it will generate the reports but those are not much attractive actions they are just basic reports if we go test output refresh here and if you expand this you will get this report action so when you here index dot HTML if you go here open with system editor so here it will show the report see chronological view log in my face will be with the past of failed it is very simple and basic report and also it will generate one more report of test ng report so email able report dot HTML can you open this here from open with system militant this is one more report so here what are the test case we have run home parser how many pass how many escaped how may have failed how much time it is taken okay so this is the kind of information suppose if test case Israel it will use on what kind of exception it is so this is a basic report but it is not much attractive right so just is you see me as simple as HTML skeleton is their site you cannot is not much attractive basically so management doesn't like this report so we can generate a good and attractive colorful pie charts and bar chart bar charts like like that so they are customized report section so interview people will ask so what is the mechanism you have used for generating the reports so people will use different names there are different kinds of reports are there in the market so some people rely on the basic reports test send the reports and some people are really on the XSLT reports there is a different technology we have XSLT reports and for that we required me one or and and reports and require we require some technology and some kind of software that is different and the most popular technologies extent reports extent report so when you go a Google and just type here extend reports if you type here you will get to one website called extent reports calm so this extent reports calm is a API ok this will provide us a good and very attractive report ok we need to import these api's and we need to con we need to produce a small configuration and this is more than enough ok so this these people will provide lot many things actually ok so this is a basically a extent people calm it will provide the third-party aps for generating the reports it will be very attractive reports ok now we will discuss this one so how to generate how we can generate the extent reports so if you interview people will ask you can directly say we have used extend reports extend reports extend reports very important now so what are all things we require things for gender water'll additional things we required for exchange of course one is we require one XML file it is not destined XML we need some configuration XML file which we can download from site website so one XML file is required and one jar file is required so we can also download the jar file from the same website and then we need to write some program Java program I will show you how we can write that program okay so this is these are the main three things we required for generating the extent reports one is XML file one is the our file other one is Java program which we have to write ok now go to the program so here I have created one package for extended course here I have created normal Java class so whatever I have created this is a Java program okay now I will show you XML file and the jar so if you come down a little bit here extend I fun config dot XML this is the external why you require okay if I open this XML file you will see some tag this is basically the template it will show you the template of report so we should not change anything here okay we should not change anything it will detect the appearance of your report this XML temple basically decides appearance of your report so suppose here this color you can change theme you can change you can put standard or dark theme and the remaining stuff you should not change and report name you can change it report name you can change it but other than this you should not change anything this is the basically template okay template we should not change right just we need to provide some information that's it so this XML file will be required the second thing is I told you right one jar file is required so where we need to attach the jar on the project go to properties Java build path so here we have all psyllium webdriver Java and set apart from these jars we should also want to have one jar called extent reports - 2.41 dot-to-dot this is a version extent reports that they are named we start with the extension reports so this jar file we need to attach so now we have three things one is extent - config.xml extent - config example this also we can download so what is the jar file name boo here I will show you the path from we're going to download so it's here this is my extent reports extent extent reap or store or some version will be there okay one Java program we have to write our own program so these are the first two things like when one is one configuration file XML file and then Java so these two things we required so from where we need to click download these two files and where we need to keep these two files so go to the XML file now go to this particular site extend report a paid a dashboard here go to here Community Edition click on Community Edition so when I see here in this particular page you will see what is the latest version of this 3.0 dot six this is the latest version okay this is the latest version and this is a little bit older version let me take the latest version so you can write ecliptic here it will download the latest version of extend report just clown it will download the jar itself okay there you can see the XML point let me start downloading this click here I'll give this link just a moment just a moment sorry one second they put everything in the Google Drive so this is a link copy link and plus so this is a link from where we need to download if you go here click this and here I will show you one zip file so you need to download this zip file so click here and insert this it will have some Lib folders extended config.xml this is be required and this is a jar file we required other things we don't take but these are the two things we required so first what we can do is go back instead of clicking here just click here download so it will download entire zip file okay now it is starting downloading it is just five and B five okay now once it is downloaded just unzip this file you will get those vectors XML file required and also we require jar yes now it is downloaded success let me open this folder so here I have downloaded this is my chip so and make this put everything in my Eclipse folder yeah Program Files eclipse-based Road here okay now the previous version is 2.41 dot two or the latest version is p dot zero dot six so now it unzipped this one extract all extract right so once you excited you will get all the files but we do not require all the files only one jar file and XML file only these to be required and once we get this file where we need to keep this file so we always keep these files on the project home directory okay so let me show you extends playoffs if you the latest on it--so inside it so this is a jar file we require and apart from this we require this extended config file and it go will be polar water all things required so there are so many things are there but we don't require all that stuff ok so what we can do is let us see did I added all this stuff or not to click and check it with some usage ok so let us add all the stuff so whatever is downloaded from here so lib hack contains some jar files and apart from this app or outside we have one extend report or jar file so add all those just but this is the main important ok and then extended consequent where we need to put this particular XML file so this XML file we need to copy in your project home directory just copy this and go to my project directory how we will see the project directory test ng training so go to the properties here you can see we chose the location yes not build path so project location on the build path we need to add jar files ok oh yes jar files we need to add the build path because already I have added so I am NOT adding again there is a one thing and the XML file we need to copy on the here so this is a whole Directorate already copied here so this is X 10 - convict X + 1 5 so this is the only file you need to copy here Lib files you need to copy to your project print path okay so here download link this is our download link okay now where we need to keep this fence so we need to put this file X 10.7 this file we need to copy to your project directly project home directory directory in the workspace okay in the workspace this is the file and then go to the next step we need to add the we have a file right extend reports what is the file name in comeback this is a jar file so copy this and also you need to add all jar files copy this attach this one add jar file to your project build paths in Eclipse fine so these are the only two things you need to do so now setup is ready now what else is pending we need to write the Java program so easy clear till now how we need to do extend report configuration we need to down low to the website and then download this one is well instead of going website directly I have given the direct link okay and then this link contains the configuration XML file and jar file so configuration XML file you need to put it in the project home directory and extend repos jar files or Lib jar files should be added to the project build path that's it now we are ready to use those limiters whatever basically this extend report jar file which contains a lot of mini classes and methods so we are going to use them for generating the repeat ok so now we need to write a program right so let's move on to the program but the extended configuration example we should not change anything so as soon as you copy this file XML file in your project home directory and come back to your Eclipse and just refresh here automatically it will appear inside this particular tree okay now so come to the program again so now this is my java program externally for decorators and multi-page name under this I have created generate extend report word Java so let us open this program now let us understand this so now we need to execute this program okay see I have created normal program so here I have a created or different methods one is our greatest art report one more method is demo report pass other method demo report fail and then get result method I have created and after test end report so different methods are greeted so just for it will demonstrate the report actual how we can generate the report now as soon as we added the jar file extent affords our friend it will provide the two different matters one is extend rapport class and extend rapport desk these are the 2d predefined classes we will get okay predefined classes we will get those two packages are available under this particular package so these packages are coming only from that particular jar if you add that particular judge then only these packages will import it otherwise it cannot okay now so the first and most important thing is the report contains two parts let me show you the report contains the two parts one is report contains the two sections one side we need to provide the environment our configuration this is the one section in which environment in which configuration we ran our test cases that is one part second part is how many test cases are passed how many up fail how many escaped and it will show you some pie charts and it will show you some filters so our log files everything will be there in the body part only two sections one is the environment and configuration section other one is a body session so for defining environment session we have one class called extent recourse class for defining the body of the report we have one more class called extend test this is another class so for both the class cells we need to create an object so these objects we need to use okay so now we need to define the configuration for this particular report right in which environment we are running this report so and that information is also displayed in the report okay now for that that conservation session we need to define at the beginning itself that is the reason I have created a parameter called start report this method I have defined with at before test annotation at the before test annotation because before executing all my test methods first it will execute this method because the configuration is mandatory right so this is first thing we need to do so in starch report with this object what I need to do I need to send the my environment information so what we need to raise new extend reports new extend reports usually we need to create one statement but I have defined the object at the outside because these two variables should be available for all the methods suppose if I define both inside this method what happens these two methods or two variables will not available for other methods where is the reason because other methods also required two objects that is the reason okay I have defined these objects outside now new external reports in first line we need to define a system property so we need to say where our record should be stored where our report will be saved that path we need to specify that is the first statement extend equal to X so what is the extent here extent is nothing but the object of extant reports this is responsible for specifying the environment or configuration so extending equal to new extent reports here this is entire thing is a path actually so don't confuse because this is very useful this is the entire thing is a path so where I need to store the report actually all the reports will be I wanted the store in the test I have an output folder this is the folder right here we will get all the reports give a normal test engine reports also we will get under test I have an output folder so I wanted to store this report is also on the same folder so that is the reason where this test out wife and output folder is available this is available under my project home directory so if you want to give the complete path then where I need to go I need to go here right so I need to go here and then users so under users go to the user and then workspace here my projects are present under workspace we have a testing G training project this is the project and this is a home directory and here my test - output is present and inside this I want to store the report if I want to give the part I need to give entire path full path here here but instead of that what I am doing is I want to capture the project home directory and then from there I will give the remaining path so if I want to get the project home directly automatically then we need to use this one this is very useful just remember the system dot get a property this is system environment variable we use it for getting the current direct okay so system dot get property of use of dot dir so if I give this command what happens is it will return the current location current path so what is the current path tilt test ng training till this this is the current path so that message this statement will return the entire path tildes now from here testa is 1 output is our actual folder so now here append that one test - output slash my report dot HTML you can name as any name you can give any name here because I given my my own report or HTML this is my customized report okay so my report will be stored in this particular location okay and then what kind of information I need to add to the report so X 10.8 system info system infamous post name of your machine localhost and environment is QA username is power so you can give this information what is the hostname hostname is nothing but your computer name environment is nothing but dev or Q or devops whichever environment you want then which user is executing your test cases that username he'll to provide here so this is the information we need to send to the report and then finally last statement how this better how this particular class as know where my extent action config.xml file is located it does not know right so we need to associate that file here extend our load config this XML file we have copied in the project with home directory but there is nowhere relationship between this particular class and XML file right so we know we have to associate these two things the first thing is this is the main class and where my XML file is present this XML file is present under my home directory so how we will get the home directory again system dot gate property of user dot type so this is a command we will get the current project home directory in this home directory we have this XML file right so we need to load this XML file at the beginning itself this is just a configuration part so this will but first part of the report first section this part is done okay by using extend object okay is it clear till now both of you Yeah right so now we need to go for the second object that stops it why do you need to use this desktop set because we need to log so much information in the so much information to the report right so I have created one more method here I'll intentionally make this method pass or fail whatever okay see demo report pass just I named it as some method here so you can name you can give any name for this method so public void demo report pass here test equal to what is test here test is an object of x10 test class equal to extent dot start test what is the extent here extent is again object of extent reports test equal to extend dot start test demo report pass this message I am logging to the record and then true message I am logging to the report I am sending the true message to the report what does it mean it is just intentionally fail use meta if I say as a dot has a talk to what happens this method will pass that's it and this mitt whatever message I have given here this message will be logged into the report and test log log so this is also more important we have a method called log here we are sending the pass message because this method is passed right so I set out a set to means it is passed so we need to send the past message and also this is a flag actually basically okay the green flag it will show if I say log status start fail then red flag it will show in the report and then within the quotations we need to pass a message as at the pass as condition is true okay so just whatever I have created here just I am passing to the report so when you see this report then you will be clear okay why I have written this code and this is for pass scenario and other one is a failure scenario other method I have graded for failure scenario here again extend or start tests of demo report fail this is just normal message we are sending to the report then I make it this as a face internationally I make this method as a fail and then I am sending the failure message to the report I am printing this message in the report itself and then after completion of these two tests so I have created one more method after meter after metal so when this method will be called for every method for every test method after that this after method will be called right so suppose take this meter demo report pass so this is sending the report as a pass message to the report and this is completed immediately what happens this method will be executed so what is method will do after method suppose this will return the it will get the result actually so this method automatically get the results so that is the reason I have used this variable and if result dot gate test at equal to 80 dot test failure then send this message to the why I have created this method means if test is failed then we need to also send the entire log or failure information to the report that is the reason I have created this method so get status equal to 80 test result or failure if the my test is failed which tests the faster tests after excluding this this will exclude because I mentioned this as an after method okay so if it is a failure then what I'm saying test dot log of log status fail just send the failure message to the report and result not get through verbal so what this will give is this is basically if the log file so whenever you exclude your test cases in the console you will see red lines right bulk red lines so basically this method will capture those written acts and send everything to the report in the log files failure pass message everything we can see in the report itself we cannot go for log failing some other location that is the reason I have to use this method and after completion of all these natives finally end report so the method that the report will be flushed which means just it will clear the memory not see it this is a simple test I have created now with exclude this particular test what happens it will generate extant reports where we can see the report under test - output here it will generate okay so now let me execute this one run master string G test now you observe one method is failed one method is passed okay now we will see normal test injury but how it will be and then we will see the extent report where we will see the reports under test hyper not refresh this once again and then expand this go to the normal test report index dot HTML we will see right usually open with system later this is a normal test anchor report if you see show here nothing will be this not one that I had one question I just forgot that did you did you create that folder test Outlook or I haven't created it all - no no it will I haven't created but at the runtime and test in G will generate that folder by default when you create an empty project ah can you tell me as once again huh in my folder I'm not getting this folder test yes yes you will not get it so when you will get it is suppose whenever you run the test change XML file it will automatically generate the test type on output so once you click secure your test and XML file then refresh this project once only one time ok then you will see this particular folder every time whenever you run the test and only through tests and XML you can see this particular photo if you run only Java test suppose if you run this alone I cannot see ok so test and XML is must and should require okay now you have seen the normal report right so now after that I will show the extent report where it will generate extern report on the same test type and output folder there is what is the name we have provided for our report my own repo dot HTML the report should be in HTML format okay so now both is Seco here and the plus this test I have an output refresh here and then come here so which or what is the name of the report my own Depot dot HTML right click open with system editor now do you see so this is a report this is exchange report this is the name will appear here whichever name you have given in the XML file that will appear here then you can see this this is a home page actually this is a home page and go to the external report section here not here just a moment this is a home page right these are the buttons actually this is first click it will show the filter so if I click the pass how many cases paths we have mentioned just one test case right so this is passed and failed one test case is fail along with this we will get the log so for getting this log I have created this particular method so if you see you again core this is off step method I have created the code right so this code will generate a log here result dot get through verbal so whatever error message comes those error messages will be logged into report this is the log message and then skip so we don't have any skip test so if we cannot discredit it until your filter means it will clear everything so because do you default whichever metals you pass it will show here then go here second tap and third tap see this is a good kind of rapport see so total to put a serve run and then 50/50 percent is filled so red color and wiggle and environment see this is very important station so where from which method we have passed this information the first method whenever my test is started here start report here we are sending hostname environment and username these values we are sending right so these values will be populated on the report on the bottom side okay so pass percentage is 50% so this kind of information we can see if you have fuse number of test cases then it will be appear very excellent okay so this is the thing okay is it here now this is basically extend report so going further in the frameworks and project work we will go we are going to use this particular report not in the normal test in the report so no one will use normal test and a report so people will prefer to use exempted okay find so if you want to change the appearance of this report to little bit UI appearance then what you can do is just you need to change the XML format so go to the XML here which XML we need to modify extent - config example so instead of standard just specifies the dark just appearance will be changed and here also apart from this you can also change a report name for example my first report changing the name okay so that's the reason so that's it okay fine so here Cemil is modified then again once again run the same test generate extent report this is a method right so one AZ test ng test right executed and then again refresh the test type and output folder come here refresh this and then extend open again my one report dot HTML open with systemic see now completely dark when it appearance is just appearance that's it okay so this is very attractive right and compared to the first one so this is how this is the name of the report it just we have changed and these are the environment where we have done and if you go to the first thing here it will show how many pass or many are failed how my ass kicked kind of information here also you will see the only past failures so different statuses we have okay fine these are the digital just method name whichever method name we are given in the clip so say metonymically display here fine so this is all about the extend report and very important concept in entire test engine ok in interview people will ask many questions on this ok could you clear both of you any questions you can ask me now extend report and leave the best which I know it's clear
Info
Channel: SDET- Automation Techie
Views: 60,302
Rating: 4.8907104 out of 5
Keywords: Manual Testing, Selenium, QTP, UFT, IDE, Automation Testing, Grid, Web Driver, Automation Frameworks, Testing Tools Online Training, Software Testing Videos, SQL, Oracle, Java, Testing Listeners & Extent Reports
Id: 2yNo9Q2Tn70
Channel Id: undefined
Length: 64min 59sec (3899 seconds)
Published: Sat Jul 15 2017
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.