TestNG Framework- Selenium Tutorial Part-2

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
okay so in the previous session we have seen that okay how to write the annotations and how can we install tests in G and how can we configure tests in G in Eclipse and then we wrote some basic scripts like in the form of different tests in G what are different tests changing methods and you know annotations are available and what it is exactly the sequence and how exactly it's creating the pair between before method test method and after method and we wrote one basic selenium script also okay to check the sequence is working fine or not so we have written so this is a standard way of writing the test cases in every company if you join somewhere and in your project also if you want to implement test ng framework okay you have to use the first annotation you have to use at the red before method annotation then you have to use add red after method annotation and number of test cases you can write okay with the help of enter a test annotation so these are the different at the red test annotation means these three annotation means at the red test a notation means we have three test cases tomorrow if you have 50 at the red test annotation it means 50 test cases are there so if I ask you how many test cases you have in this particular class so you have to count total number of at the red test annotation which will give you the total number of test cases okay add the red before method and add the red after method okay not considered as a test case these are preconditions and postconditions before each and every test case I want to execute I want to launch my Google Chrome then maximize and delete all the cookies and drivers launch the URL and everything and then I want to perform my test cases right and always remember one thing the test cases are independent to each other okay this test case is not dependent on this this case test case is not dependent on this particular test case the test cases are always independent okay so today we will learn some more about some other features are available in test gingy okay so yesterday we have seen that see I have written these three test cases so let's see I'll create some more test cases let's see and create one more test case test simple public void let's see test case number one I'm not writing any selenium code this simple I'm writing lacing system dot println and print it a printing test one so let's see I will create some more test case just one test2 and test3 okay so if you ask how many test cases we have 3 and +3 six test cases I have written right so yesterday we have seen that if you want to prioritize your test cases so we have to find a prioritization that priority is equal to one and two then three then if you want to it you know give priority is equal to four we can give this variety variety is equal to five try T is equal to six like this so now whatever the priority we have given on the basis of that priority it will be executed the sequence will be maintained on the basis of the priority so it's a very famous interview equation they will ask at a time of interview how will you execute your test cases in a sequencing manner however you define the sequencing of your test cases when you have to tell we have one keyword priority keyword and immediately after at the rate test we have to write like this variety is equal to CP is it priority is a keyword so P small okay so now if you run this program let's run it and I'll do one thing it was earlier it was Gmail actually okay so let's run it and we will see all the six test cases will be executed one by one on the basis of the priority so if you see three times we are launching the browser okay for these test cases and these test cases will be executed we are not writing anything it will execute and build test 1 1 1 or whatever the value we are printing ok so I think still running and we can see that Google title test and ok this is again one more time chrome is running there one more time chrome is running and one more time Google Chrome is running so it should be executed six times because six test cases we have executed and it's printing all the values one by one right and if you see the report so there is a report when tab will be created this is the report if you see the report in this particular Google test we have six test cases on the basis of sequence what executed the first sequence was Google title list so Google title test then mail link test and then Google logo test right we are simply verifying that logo is displayed or not and test1 test2 and test3 like that right now one more important feature is that so this is one type of reporting we are getting ok if you see one test ng result I can will be created you can click on it and this is the report we are getting and in the console also we are getting some report that how many test cases were there six test cases this is a report of your six test cases so you can copy this and you can send it to your manager or lead or you can just you know share with your team members the DS test case you got pals and one is failed and immediately after failed test cases it will give you the reason what exactly the problem with this particular test case whatever the exception or any no such element or whatever X for the shoe or ideation okay but we are not bothered about why it is getting failed we are bothered about it got failed and these test cases got passed right now if you this is your project morning sessions and if you refresh this page so I'm going to refresh how to refresh the project not the page sorry how to refresh the project simple this is your project the main project folder right click on it and click on refresh so after clicking on refresh you will see what folder will be created automatically test output folder in this particular project you need to open this test output folder and you will see some number of files ok number of files are over here ok so test output means what exactly the output of your test result output of your test cases after the execution so we have one file here index dot HTML file so what you have to do you just need to right click on it index dot HTML file go to properties and this is the location ok you just need to copy this location just copy this and open your Google Chrome or any browser and paste over here this location and you will see that this is an output I'm getting the HTML report ok so you will see that the left hand side some links are available so we have total number of methods 6 test cases you could execute it one field and 5 passed and this is the main link test is the failure test case and if you see the pass method show okay all these are green color okay green check it means these three test case five red case you got passed and one is failed so you can send this report to your manager right and if you want to see the chronological view also you can see chronological view like this so see it's creating the pair set up Google titled test and teardown set up male link test and teardown and may link test got failed so that's why the giving Cross Red Cross okay some important like times on the basis of time so also you want to see how many test cases six test cases are there zero to five these are the methods in which class it's available in this particular class it's available how much time it took to around 30 milliseconds for first test case and then three one two and ninety six and one one in 1:1 milliseconds for last two three test cases so you can see the timer report also like that okay but this is etched basic HTML report generated by test ng automatically by default this is another very good advantage of test ng that it gives you the HTML report this is the HTML report right the HTML report name is index dot HTML file so how to get to the index dot HTML file I'll repeat first after the execution every time you have to you have to refresh your project so just refresh it sorry and then test output folder will be created inside the test output folder this index dot HTML file is available automatically it will be created and then right click on it and go to properties so this is the location ok somewhere in your workspace somewhere in your you know in your machine so it will be this index dot HTML maybe in your case it will be C dry or D dry or whatever where exactly your workspace is available index dot HTML file is there just copy this location path and paste it in your URL ok in your address bar on your browser so you will get that particular report like this ok this is another advantage you can show this report to your manager this entire report that ok this particular task is getting failed ok and these are getting passed this is a very basic report we are getting although in again another session we will check how can you regenerate a very good reports like extend report and all those things I'll teach you later but this is a test in G basic report we are getting ok this is another feature that ok it's generating good reports second thing is so so far we have seen the K this variety now I want to define that ok I want to give some grouping also let's see I have 100 test cases in a class and out of these 100 test cases let's see first test cases are related to title so what we can do we can define the grouping also so let's see if you are defined priority then put comma attribute or a rather feature we can define like this groups is equal to what is my group name let's see this is related to tie to the group okay let's see this is related to groups is equal to logo this is related to groups is equal to link test or something like that and last three are related to same group let's see groups is equal to let's see my group name is test simple okay and I'll write the same thing for these last two test cases okay group this and for this also okay so I am defined one more keyword groups it means this particular test case related to group NH up to you whatever the group name you want to give you can give let's see I have hundred test cases out of hundred test cases ten test cases are related to let's see search page so I can define group is equal to search ten test cases are related to registration feature so I can write group is equal to registration or something like that right so if you run this program let's run it again so group eyes also you can define and in the report it will generate group face report so grouping also you can define for your test cases so let it run and I will show you how exactly it's defining on the basis of groups okay execute all the test cases I think this stress case taking time this particular test case because explicitly we are making it failed okay so it's gonna wait for we have given them perfectly weight of 30 seconds that you're gonna wait for 30 seconds now it's gone now it will be fast this test case also cause so 6 times browser will be launched because 6 test cases we have written and one more time it will be launched okay and that report is done you see the report we are getting the report once again 6 failure 6 test cases one failure 5 passed again I have to what I have to refresh my I have to refresh my project and go to index dot HTML file get the location and I'll go to my browser copy that location again and you will see that same 5 test case I got passed one fail but if you see 4 groups are there you click on it so you can see the grouping group wise report also this is a very good feature I really like this feature you can define the group face feature that for link tests we have won this case for logo we have this particular for test group we have these three test cases for title we have only one test case let's see for title you have written 5 test cases so all the 5 test cases will be categorized under title group right for low boleterĂ­a return around 10 test cases all the fun logo generally we don't write 10 - you see let's see five test cases logo test one logo test to logo test three or multiple images you are checking so everything is coming inside a single group okay let's like this test1 test2 test3 we have written inside the test group okay so this is a very good feature that you can give the grouping also and it's very famous interview question that how will define the grouping and test changee so we have to use group keyword groups keyword not group groups keyword like that we have to define okay okay another thing is let's create one more class II I'm going to create one more exchanging class simple right click new and a class let's see test in G features as I told you that we don't write main method inside test in G class but simple click on finish and okay so let's see I'm going to create three test cases I'm not going to add any I'd read before or enter it after simple I'm going to create at the rate three test cases let's see public avoid login yes okay and simple I'm printing I'm not writing any selenium code simple and printing login test and this test is a notation is available in testing G so just import it okay then I'll just copy paste and I'll write two more - cases let's see login test then homepage test and the T then search page test right so these three things I have written let's see I have forget about search page I'm going to comment this okay I have only two test cases login test and home page test right so if you run this program quickly run as test in G immediately it will give you login test both the test cases are fine two test cases are fine right both the test case you got past simple we're just printing it that's it but I want there are some chances that some test case is dependent on some other test case so what we have to do let's see let's take the scenario we have an application let's say login is failed logon is not working today so there is no point to execute other test cases right for other test cases execution you have to get into the application then only you can do that the t facebook login is not working then what is the need of texting other features the login itself not working I cannot get into the app so there is no point to execute okay other test cases there is no point to waste my time right so what we have to do we can define one keyword and we know that login test is the most important test case and all other test cases are totally dependent on noggin test right so what we can do and we know that home based test is totally dependent on login test so we can define the dependency between these two test cases how to do that again bracket we have one keyword depends on methods okay on which method it depends it depends is equal to only single equal to login test like this we have to write it means at the rate test okay this particular home base test is totally dependent on login test see exact method name you have to copy paste here and the keyword is depends on method so if depends on method will define that this particular test case home page test is totally dependent on login test so I'll write case okay home page test is totally dependent on login test now the condition here is if login test is getting passed then only this particular test will be considered okay if flog in test is getting failed then this particular test is will be failed automatically I mean this particular test is not be failed it will be ignored it will not be considered it will be executed right so right now what is happening if you run this program login test obviously it's getting passed then control will come over here this change you will try to execute this it will check okay it depends on login test and it will check what is the condition of login test what is the status of login test the state of login test is pass it means then homepage test will be executed then the preference will be given to home business otherwise homepage test will not be executed so if you run this program see it's very very important feature run as text in G see the output write both the test cases got past login test and homepage test if you see the output log integers past then homepage test is past the home page test is totally dependent on login test now what if login test is getting failed so what I'll do I'll make it fail simple I'll write int I is equal to let's see 9 divided by 0 so 9 divided by 0 I cannot divide any value by 0 any number by 0 it will give you some exception right what will give you divide Z divided by zero error some exception it will give you it means this particular test case will be failed if this is getting failed then this particular test case will be skipped it will not be considered okay test ng is not going to execute this particular test tube so let's run it okay so it's testing first test case now see my first test case login test got failed at giving arithmetic exception to divide by zero error line by zero it will give you an finite so this is a divide by zero error I can in in programming okay I cannot do i cannot divide any number by zero it will give you arithmetic exception it means this desk is giving some exception right so this test case will be mom there is failed right if it is failed and we know that home base test is totally dependent on login test and login itself getting failed then why we are getting executing this login is not happening and why we are moving to home page test right so if you see the report also so you see login test got failed what is the reason of failure reason is arithmetic exception divided by zero error so that's my home page x is the yellow mark to yellow means skipped it got skipped okay it will not be considered to be executed okay so an in fact and you see in the console report also this particular test case you've got magnetic field so see it's not going to execute homepage test there is no home page test right and immediately it will give you two test cases got executed but out of them only one is failed so another one is skipped there were two test cases one is failed one is skipped so let's see tomorrow we have one this particular test case also we have when we have defined it depends on on this also depends on method is equal to log interest right it means both the test cases are dependent on login test and let's see I'll write one more test case let's see to the station page the registration page search page test okay so we have four test cases login home page search page and registration page okay that's me and right like this right now all these three test cases home paste a search based test and registration test okay all these stages are dependent on login test okay because we have written depends on method equal to login tells depends on method equal to login test depends on method is equal to log interest if first one is getting failed login test is getting filled all these three test cases will be skipped immediately exchange II will not consider these things see this is the biggest advantage if login is getting filled then there is no point to execute other test cases immediately your automation will be terminated it will give you the report third boss your noggin - noggin is not happening in the application please fix that issue then execute other test cases right so you run this program and you see that login immediately will be failed and other test it will be ignored will be skipped we will see that for test cases were there one got failed and three skipped in the report also login test is PAH I mean failed and then these three test cases got ignored okay but if login test is working fine let J come in this line into equal nine divided by zero right if login test is passed then all the test cases will be executed one by one now it doesn't matter that maybe registration pages getting failed okay that doesn't matter that's a separate thing but it will be considered okay because login test is getting passed then it will be considered if you run this program okay so it's executing login page test it's executing homepage registration page why it is not executing other test cases okay login page should execute okay let's run it again okay now it's executing okay some problem with the Eclipse earlier so see when maven login page is passed and homepage tests gestation page and search page stairs okay so this is a feature of depends on methods please remember this keyword they will ask you at a time of interview and in your project also you can implement okay okay one more important feature we will see invocation count test what is invocation count I'll tell you let's see I have a method public void let's see some method is there right and inside this method simple I'm writing in a is equal to 10 and B is equal to 20 and in C is equal to simple a plus B okay and this at the rate test is available in tests in G so imported and then I am printing system dot out dot println sum is plus C okay so let's run this program simple rather is test in G so sum is 30 it's printing because C is equal to 10 plus 20 30 fine what I want I want to execute the same test case 10 times okay the same test case I want to execute 10 times or 100 times or 20 times right so no need to write someone like this no need to write some other test case ten times with a different name like this then some two then some three some four because I want to execute ten times okay then no need to write time's different test methods you have to create no no need to create so what we have we have one keyword is available again chain vocation count how many times you want to execute the same test case I want to execute 10 times let's see invocation count is equal to 10 so this particular test cases this particular test case will be executed 10 times so if you run it see what executed 10 times immediately so no need to write 10 test cases see it got some 1 by 10 2 by 10 3 by 10 4 by 10 it means out of 10 1 out of 10 2 out of 10 3 out of 10 and 10 by 10 10 times has got executed some method got executed change so sometime what happens generally we don't use invocation count but sometime what happens let's see you want to execute the same test case again and again right let's you want to dump the data into the system in that is you can use invocation count equal to 10 you want to execute the same test case multiple times 5 times or 10 times you want to generate the report or if you want to generate a data or something ok no need to call that method again again or write the method again again simple right invocation count 10 times it will be invoke ated okay this is again one of the important feature ok ok now one important thing these days lot of people are asking at a time of interview that exception timeout test okay see again I have one test case let's see test public void my test name is Lexi test one right and imported from Destin G let's see what else case name is in finite loop test okay so what i'm doing here let's say meeting one variable int I is equal to one and I'm writing when a while loop while I is equal to equal to 110 simple print system dot overtrain telling the value of i okay so what will happen simple first time it will check I equal to one okay I equal to 1 1 equal to equal to one condition true or false condition is true it will print i right it will print 1 again i equal to 1 we are not increasing the value of i right so again i equal to 1 so i again i equal to equal to 1 again i equal to 1 so it will generate an infinite loop in finite times it will be executed right so if you run this program you get a point ok i'll repeat i equal to 1 fine 1 equal to equal to 1 condition is satisfied it will come inside the while loop it will print 1 right again will check 1 equal to equal to 1 yes condition is again satisfied it will print 1 again 1 equal to equal to 1 so it will be executed in finite times okay why because I am NOT terminating my loop I am NOT increasing the value of ie ok my condition is like that only that I generating infinite loop right so let's see you have 100 test cases you have written and one of that and one of the maybe test case is getting taking a lot of time okay so and your test case is fine it checking infinite loop and tomorrow morning you see the report okay still the fifty number desk is good okay taking some time it's stuck somewhere infinite loop okay but we have one mechanism if a particular test case is stuck somewhere due to infinite loop or maybe some time time issues okay so let's first run this program and you see that I see infrared to which keep printing one one one one one one so if you want to terminate this program you have to terminate manually you could click on Yahoo terminate see it's printing one one one one one one in finite time it will print okay so manually you have to terminate your program but we have one method time-out method okay and you can give some seconds let's see two milliseconds I have given timeout is equal to two milliseconds it means if any infinite loop so maximum timeout means we are giving just that you know if that particular test case should be executed within two seconds right it should not take more than two seconds so let it timeout I have given for say rhenium test case I have given thirty thousand milliseconds min 30 seconds so maximum time we are giving for that particular test case is 30 seconds within 30 seconds if it can be executed it is fine otherwise it will be terminated okay so let's see I have given two milliseconds okay so for two seconds it will be executed oh that's generating just a minute really difficult although we never you see infinite loop got executed it showing array index of bound exception so we have more invocation timeout is equal to 32 seconds I don't remember exactly what maybe invocation time outlets on it okay the see is still running just a minute timeout is coming let's give only two maybe 2000 milliseconds it does not accept a lecture tonight again okay see it's still keep running and immediately it will give you error okay array index out of one exception this is an invocation timeout okay so that I will check if we have to give in milliseconds or two seconds the description is not written over here they have written that invocation timeout in log let me it's ayah the number of milliseconds the maximum number of milliseconds we have to provide okay so be it should be executed it should be terminated within two seconds but it's not but giving you the report okay but once you execute to Jenkins on me when then it will work maybe it's because of eclipse feature it's not to H keep you know or running your test cases but never use this thing because always try to avoid these infinite loop things infinite loop conditions in your program okay this is a bad way of writing the code that I'm not terminating my loop okay this is just for understanding okay so we never write these kind of things in our code in our automation framework designing okay we never write such you know infinite loops always avoid these kind of infinite loops okay this is a one thing another thing I think one more key word is they're not exactly you think ya expect exceptions sometimes you see that okay yes I'm expecting this exception so please don't a you know so don't uh terminate your test case or don't fail your test case so we have one expected exception so I'm expecting some exception what is my exception it can be whatever array index out Oh bond exceptional number format exception or whatever okay so you need to write that exception name here number format exception like this whatever the exact name you have to give okay number format exception so this is my expected it's asking actually last name so number format exception not the string number format exception that exception class you have to write dot class like this so I'm expecting although we don't use these are you know keywords but this is a feature okay so expected exception that I'm expecting this exception so please don't mark your test case has failed okay so they might ask you a time of interview that if you want to handle exceptions ok intestine G what is the key word we have expected exception that we are expecting this exception number format exception okay so please don't do that so let's see it let's test even I haven't tested it so let's test public void let's retest one ok and simple let's see I'm giving some number format exceptions so how to generate number format exception let's see I have one string remember string manipulation wrapper classes and I'm converting this integer dot parse int X right and obviously select comment this first of all otherwise it will give infinite loop so if you run this program then as test in G okay you see it's giving number format exception right why number format exception because I cannot convert 100 a into integer right so we are expecting this number homemade exception and this particular test case is getting filled and the failure reason is number format exception for input string hundred a now what I will do I will define expected exceptions is equal to number format exception dot class like this you have to give right so now if you run this program okay it's now it's got passed Y and C is getting passed why because we are expecting this exception so we are telling to selenium I mean not selenium to test in G that we are expecting number format exception okay so even though it's slowing number format exception still the desk is getting passed okay so this is an interview question it's a tricky question they want to ask if you want to handle it you know without the try catch block how will you handle it so we have rather straightforward keyword accepted condition and whatever the let's see array index out of bounds exception some error is out of bound but we are expecting that exception so you can do like that also okay so this is the concept of invocation timeout expected you know accept expected exceptions you can write like this okay yeah so although we don't use these kind of things in selenium if any exceptions are coming obviously we want to mark it failed we never we never do like okay we are expecting this called exception and then still the test case is getting passed know if any exceptions or errors are coming in that case obviously we want to mark our desk is filled okay but this is a feature you should know that in tests in G okay okay one more thing that intestine ji yesterday we created districts in G basics and we were taking the title of the page where is a title Google title test okay yeah Google test page we were taking the title right remember we were writing the selenium code and we were taking the driver or to get title storing in title variable and printing that on the console but this is not the full test case this is just a step driver don't get title giving you Google title write the title will be Google and we are printing on the console what if driver don't get title is giving you Facebook or Amazon then title is wrong title is incorrect how will you validate it now the test case will be passed every time right the test case will be passed everything so what I'll do let's create a class one more time one more class let's see how Google title test simple I am writing a simple class Google title test okay and what I will do I will copy this thing down here because I need this Google title test and I will copy add the rate after method also so that I can quit the browser okay then we have to initialize our web driver after the class so that this driver can be used okay throughout my program now simple what will happen and forget about this variety in all those things because we have only one test case now simple what will happen it's simple execute before method and to execute this test method and quit the browser but this is not the testing we are not creating any we are not checking any validation that expected versus actual result what is the actual result this is the actual result we are getting a title it see Google but we have to validate it right the validation is the most important thing in selenium in testing in automation or manual testing so you have to validate it that the whatever the title we are getting is correct or not otherwise then what is the use of writing the automation we are just opening the browser opening google.com getting the title but we are not validating might be tomorrow you are getting facebook instead of Google right so that is a incorrect title okay so what we have to do we have to validate it okay we have to validate the title is correct or not so validation is the most important thing in any des case now how to put validation we have to put validation in the form of assertion okay so what is an assertion assertion is a kind of validation so we have one class or third class so a capital okay assault dot and we have different methods assert equals method is there assert assert equals and what is the actual menu my actual value is title and what are you expecting I am expecting Google okay so this is I am expecting Google so no need to write F else condition that F title dot equals Google then print this else incorrect title no need to write like this simple assert dot assert equals will work title comma Google this is my actual result which I'm coming which I'm getting from the UI and this is the Google which is what I'm expecting okay it will compare both the things if it is past test case will be past if both are not matched test case will be fade if it is failed we can put one message also we have one more parameter that title is not match like this okay if it is failed then only this particular thing will be printed title is not matched if it is getting filled then only it will be printed okay so first thing we have to write what exactly you are it okay what is the actual value second thing we have to write what exactly you are expecting third thing if it is failed assertion is filled then print this message okay title is not matched so let's run this program okay so simple it will open Google Chrome then okay and then it will generate a report okay one dash K is pass if you see the report Google dead okay is passed right now Google test is pass so this is the assertion that we have to write it's very important then assertion is important let's see and deliberately I am expecting Google one two three it will give you title is Google so Google is equal to Google one two three no test case will be failed right I am expecting Google one two three deliberately I'm okay and we doing three in this test case so Google is not equal to Google one two three so obviously it will be failed so let's run it right so it's failed see see the result Google title test assertion error it will give you this is called assertion error title is not matched expected Google one two three but found Google double click on it it will give you this is the expectation our expectation is Google one two three but we are getting Google okay so this is assertion is the most important thing in testing G we have to write assertions like this okay let's see one more example of assertion let's see logo I want to check another test case is logo test so I'll write this test case remove this I don't need okay logo test so we are seeing that driver dot find element by it would expire this logo image is displayed or not so whatever if it is redisplayed it will give you be equal to two other might be equal to false doesn't matter if it is false also lexing logo is not displayed my test case will be marked as fast let's see logo is not there the test case will be passed logo is there still test case pass if logo is not available it will give you B equal to false it's not displayed be equal to false test is still passed then what is the use of writing the test cases we have to write the proper validation proper assertion that what we are expecting that we have to write simple assert dot we have one more C assert true what are you expecting we are expecting okay to be should be true now now C is displayed driver or find element by Road XPath if it is displayed it will return true so B will become true and we have a write a sir daughters are to be me means - it means the test case will be passed let's see if it is not displayed B will be false and a sir dot assert true will be false so it means assert to means we are expecting true but we are getting false so it will be failed great so if you run this program okay so first test case will be failed because this one Google one two three we are not expecting I mean we are expecting over one two three but we are getting Google okay so it will be fail again chrome will be launched okay okay got it before it executed okay yes Google logo test the Google logo test is fine why because we are getting logo is available we are getting this ID is equal to HP logo it's correctly fine it's returning true so B will become true so also dot assert true will be true but Google title test again the same thing Google one two three we are expecting we are getting Google okay so assertion we can write like this a sir daughter so it equals our daughters are true like this we can compare two boolean values we can compare two you know we can compare to string values also so here we are comparing two string values okay here we are come we are not comparing we are simply writing our daughters are true if you want to write us or dot assert equals you can write us or daughters are equals also it's up to you so what is the actual thing actual thing is this B what are you expecting I'm expecting truth so this is the comparison so either you can use this now you can use this both are same so B is what B is true so true equal to true condition is satisfied it will let's test case will be possible so like that also you can write assertion okay so this is the false of assertion okay now one last thing in test ng then test change e topic is over so how many test cases be how many test classes we have created see one two three four five six different test classes we have created so let's see in your project you have 50 test classes and you want to execute those test classes again and again one by one it's not like that first I'll open this and then I execute this then I'll open this then I'll execute this then I'll open this then I'll execute this not what 50 tests it's 50 tests classes are there or 100 classes are there it's not the right practice to open one by one and execute then no what we had do we have to execute combined we have to execute okay all the test cases okay combined it and then execute it so how to do that so we have to create one XML template file okay so how to create a Texel template file simple in your SRC folder let's right click on it and create a file go to other and click on file and click on next and you can give the file name is test ng dot XML file this is a name okay you can change the name also but then most ninety-nine percent cases we give exchange e dot XML file this is a template file and click on finish so what exactly it will do it will just simply create one XML file but what is the content we have to write here okay so no need to remember we just need to copy paste so I will give you the format of test in G dot XML file just a minute okay I'll give you this format we just need to copy paste and paste it over here okay okay let me modify this yeah okay let me explain so let's see whatever the the first attribute we have to give an XML sweet name what is your sweet name let's see my sweet name is Justin G session test automation suite right and what is your test name my test name is different let's change a feature test whatever the name you want to give in your application that you're working with Amazon so it will be Amazon test automation suite you're working on let's see check out module so check out feature test whatever the name it's up to you whatever the name you want to give and you have to give the entry of all the classes over here so my desk is available in Chrome but the package name you have to give always remember so my package name is C you have to give the entry of all the classes like this okay so this is the classes attribute inside the classes we have different classes we can create like this what is my first entry comm dot test is a package ok calm dot test dot what is my last name exception timeout so just get the class name ok exception timeout again calm test dot google dist don't write Java okay Google test again comm dot test dot Google title test right and we have three more classes so after that invocation count test SOCOM dot okay invocation count and then test ng basics test mg basic and test change a feature okay make sure no spelling mistakes test ng features right so six classes three plus three six six entries classes we have given over here now what we have to do this is a test in G dot XML file we have created what we have to do we have to right click on text change a dot XML and then this particular test change a dot eczema we have to execute no need to execute one by one separate individual classes no need to do that in your in your project and your framework lets you have 50 tests in G classes you can define 50 th in G classes over here like this okay and then just simple right click on text and you dot XML and run as test ng sweet what exactly it will do one by one whatever the entry you have given over here first it will execute this class then Google test you in Google title - this is this like this okay so simple right click on text in G dot XML run as test ng sweet now see it's executing one by one all the classes okay so let it run let's quickly whatever we have covered so far okay one by one it will execute okay saying 17 test cases quadrant one failure if you see the report see report is also very good like this it's giving you the report like this okay an exception timeout one test case Google title test 2 test cases are the invocation count 10 times we have executed we have given invocation count tes ng basics tes ng features all the test classes are getting executed like this and again refresh your page ok this index dot HTML file will be there right click go to properties get the location and now see how many test cases 17 methods 17 test cases are there one failed 16 pass see it's giving you the complete report one failed Google title test it will give you the result you were expecting Google one two three but found Google so they can share this report and your manager can see the report and easily can understand ok yes this particular test case got failed why because you were expecting Google one two three and we are getting Google this is what we write in manual test cases right when we execute my real test cases what we write we write expected result an actual result expected is what Google one two three then we write in an actual result that okay know as not expected it's giving you Google ok or Google one two three and then we market field in a status quality mark a sort of failed right simple the same thing we are doing in automation also we are generating these kind of reports and all these test cases are getting passed like that ok so you can generate the report like that so although this is not a very good-looking report you will see some other quotes although like extent report and all those stuff we will do that later ok so this is all about testing G it's a most important topic ok please practice a lot of things in testing G but simple it's very simple testing G is very simple but not of interview questions are there in testing G okay so that's all for today tomorrow in the next session we will see some other things we will start okay
Info
Channel: Naveen AutomationLabs
Views: 188,487
Rating: 4.8647981 out of 5
Keywords: Selenium, WebDriver, Java, TestNG, Core Java, Automaution, Assertion, Assert, testng framework tutorial, testng annotations in selenium webdriver example, selenium testng framework interview questions, testng framework architecture, testng example, testng example in eclipse, testng selenium webdriver example, software testing tutorial, @test testng annotation, TestNG -Selenium Training Tutorial, Naveen AutomationLabs, Testng Tutorial for Beginners, Mukesh Otwani
Id: NqN3JNpZZiY
Channel Id: undefined
Length: 58min 44sec (3524 seconds)
Published: Tue Sep 12 2017
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.