TestNG Framework- Selenium Tutorial Part-1

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
okay so today I'm going to cover that is the most famous topic okay that is called test in G okay how to write how to design a test in G class and how to write tests in G assertions and how can we integrate test energy with selenium okay and how can you design a very good test energy framework or testing framework okay so today we will cover all those things and yeah last time we did from a file so that that is a dataone framework right yes that is a kind of data driven framework yeah so first of all what is stingy see so let's write some note notes about testing G then you will understand what exactly okay so I'm going to create a simple file okay let's see test in G notes so what is test changing so test in G is testing new generation framework okay I would say it's a unit testing framework okay it's a very famous framework which is used by developers to write their test cases give it level - sketches okay whenever they are writing their code so they are writing their unit level test cases also okay by using J unit or test Genji so both are unit testing framework but automation engineers also they can use test ng and they can integrate with selenium and they can write very good selenium test cases also okay it's a very powerful tool it gives lot of options and features okay to design your test cases to generate the HTML reports and everything so test chain G is all about what is the purpose the purpose is simple purpose design test kisses okay the purpose is design test cases in a systematic way okay in a proper systematic way it will design your test cases test ng is first of all open source okay it's freely available in the market you can just need to download it and you start using it so it's open source it's free okay it's available in the form of jar files so they will give you one test change you don't jar file so available in the form of jar file and this is also called in Java unit testing framework okay so it's only and only applicable with Java lets you tomorrow you want to work with PHP then they will be another PHP unit is available you want to work with dotnet or c-sharp then n unit is available for editing the test case is okay but J unit and test in G both are used only and only with in Java both are Java testing framework okay so for each and every language they have their separate testing framework okay what are different advantages the first advantage that I told you that okay design your test cases in a systematic way another way is that okay it will generate very good HTML reports okay good HTML reports it in generate apart from that it gives lot of annotation different annotation I would say I will tell you what is annotation it gives lot of annotations lot of other features like we have different features like priorities you can define your test cases that okay which one should be executed first which one should be executed last okay you can define the priorities or the sequence or the test cases also you can define I would say sequence ok sequence also sequence of the test case also you can design apart from that there are some other features like dependency feature what is dependency feature okay one test case is one test case is dependent on another taste test case okay you can defy the different dependency is also okay dependency is there apart from that you can define number of let's say you have a hundred test cases and you can define the grouping also well tell you what is grouping okay grouping also is possible in test ng most most important feature is data provider feature let's see you want to execute your test case multiple times with a different set of data let's see one login feature is there and you want to pass user name password again and again okay let's see you have ten username and password so you want to execute same test case again and again ten times with a ten set of data in that case data provider is the amazing feature is available in testing G okay and it's a very famous interview question as well as in any project if you are using test in G with selenium data providers you have to use okay so data provider is also very very good feature is available in destined G and life will be very easy with test genji that you just need to concentrate on your logic and the entire thing will be taken care by exchanging okay so these are the different features are available in testing G so that's fair whenever we are designing any automation framework we always use test ng to write our test cases so in other form test ng is also called TDD framework what do you mean by T ready see these days in agile methodology we are you know her we are hearing this term that what is TDD TDD means test-driven development okay test-driven development so this is also called TDD framework what do you mean by test-driven development development means along with whatever they are writing your test cases whatever they're designing their code and everything along with that we can also design a test cases in agile methodology so test energy will help you to design your test cases in a systematic way whatever the prerequisite e's are they're after the test case what exactly you want to do in all those things okay so that's what it is called test-driven development framework also you can drive your test cases with the help of test Genji framework okay so if you learn this particular framework then it's really good it's really good to go with the you know with the interviews with your designing of the new framework a new company if you have some very fresh project in your company and then if you want to start the fresh framework from the scratch you can design a vertical test in your framework like that okay now the second thing another thing is that how to install okay installed test ng okay in Eclipse so there are okay I mean there is a one way that you can install test in G what you have to do okay so let's go to I will give you one URL from there you have to download so what is a URL is that you just need to search on Google that test change e plug-in you have to download s change a plug-in in Eclipse so just write test ng plug-in for Eclipse and what you have to do there is one URL I'll tell you where exam what is that URL not this one just a minute let's URL is there just a minute we will note down that URL okay yeah this is the URL see copy this URL I'll give you that you are okay this is a URL so no need to hit this URL directly what you have to do you have to go to your help and click on install new software okay go to help and click on install new software and here work in this particular field you have to copy paste this particular URL and enter and then it will search that where exactly this URL is connected with so still showing pending it will give you a test in G after a few seconds so still searching the plug in the correct plug-in on this particular URL just wait for few seconds okay so you can see that test in G is over there you select this plug-in like this and click on this contact all updates I during install to find required software this last option make sure you are selecting and click on next ok so it will start calculating all the dependencies and everything ok and three options will be displayed okay let it be like this and click on next you have to accept the License Agreement of okay of testing G this is Apache based or partial License Agreement you have to accept and click on finish the moment you finish it will install it will start installing the test changing ok so once it is completed I'll tell you what you have to do okay so let it install okay so that will give you one security warning so click on ok [Music] ok so after that it will ask you to restart your Eclipse so just click on yes so that your rectoress will be restarted ok so that it restart and ok so I'll share this particular UIL with you guys and so first start is restart so one eclipse will be launched again ok now this is our project and in this particular project what we have to do we have to add s ng libraries so how do I test in G libraries so just right click on your project ok go to properties and then you have to click on Java build path ok then you have to go to build path and you have to click on add library we have to add sjg library just click on add library select test ng so if test in G is you know installed properly then it will give you an option over here test in G and click on next and click on finish so you will see that along with all the selenium BR files we have JRE jar files Java jar files and testing GDR fights if you open sea it will give you one test change in your file over here these four jar files are provided by test in G so as I told you earlier that this change is available in the form of jar files so you need to click on apply and click on OK ok so it's updating your project so let it update and then we will start okay so you will see that we have a JRE system library and all the selenium to our files and destiny library also we have added now we are good to write the test cases so what I'll do for test Genji let's create a separate package so I am going to create a package let's see my package name is comm dot test package ok and click on finish so in this particular package what I will do I will create a class ok so let's see I'm going to create a class let's see test ng basics ok always remember intestine G don't select main method we never write main method inside the test changing we we don't need main method executors ok because test changes will automatically execute ok the class we don't need any main method to execute our class so don't select main method in test Genji we never work with a main method simple right the class name and click on finish ok so this is the class and intestine G same Java code we have to write but testing G provides some other features which is available in the form of annotations now what do you mean by a road test changing annotations are that in the form of at the rate we have to write okay so what is annotation the first annotation in test in G is that we have this annotation before class annotation B capital C capital with starting with at the rate so there are different types of annotations we have some prerequisite ease preconditions annotation we have some test cases annotations and we have some post condition annotations okay which I explain you what exactly these annotation can be used for so adder it before class annotation is available okay how will you get to know that this is an addition a notation should have start with at the rate right so when have you ever seen that some code is there that is starting with at the rate it means that is an annotation okay so we have this annotation at the read before class always remember one thing with each and every annotation okay it should be associated with one method so we have a method public void let's say I'm going to create a method public void launch browser method is there okay so I'm not going to write the selenium code I'm simply writing simple basic okay Java method so I've created one method public void launch browser what we have to do first edge giving you an error at the read before class we have to import this from s change e see add read before class from test chain generation just import it so this add read before class annotation is coming from test change a jar file okay now we have written this method public voice launch browser and simple as right let's see I'm printing system dot out dot println I'm writing launch Chrome browser ok this is my method name okay we have another annotation at the rate before I'll tell you what is the purpose of at the rate after class and read before class okay we have another elevation at the read before method and then I write with public void let's see enter URL okay public wide entry URL again add read before method is available in des change e so just import it okay let's see simple I'm writing system dot out dot println enter you are okay so entry URL is also there fine so what is my first step my first step is launch the Chrome browser and then enter the URL okay we have another annotation in add there it before test I rotation simple right public void let's see some method name is login method ok system brought over println we all get method and this add the before test is available again in test chain G so just import it from test engine ok we have on top one more annotation that is called at the rate before speed annotation public I'll tell you don't worry I'll tell you what exactly the purpose of each and every a rotation why I am writing like this public void let's see some very precondition let's see I'm going to write one method set up that is there and system dot out dot println ok HD install Chrome or maybe I'll write setup system property for Chrome something like this I am just writing random some system dot out dot println and this added before sweet is available in test change e so import this thing from des change yours ok so see I have defined different kind of 3d qualities preconditions so let's see if you want to open google.com what is the first step first step is that you have to setup the property for Chrome then you have to end launch the Google Chrome then you have to enter the URL and then you have to login right and then you have to write some test pieces similarly so these are called prerequisite easier rotation and read before and read before and thread before answer it before but what is the purpose of entered before sweet what is the purpose of enter before it lasts before method and before test I will tell you okay in couple of minutes now we have on test case at the rate test case at the rate test right and my test case is let's see public void let's see I want to open Google page Google title test is the method name this is my test case that I want to verify the title of the Google is coming properly or not so I want to check what is a Google title so this will I'll write inside with at the rate test CK so always remember one thing each and every ad rotation should be associated with one method I cannot write only at the rate test it should be associated with some method entered before so it should be associated with one method and then before class it should be linked with one method okay same thing at the retest is available in tests in G so imported from testing G okay let's see simple embedding system dot out dot println Google I didn't test okay this is my one test case I have written now once the test case is done what I want I want to define my post conditions after my test case is done what you want after my post condition is done I want to write at the rate before method so enter it before method at the after method add red after method what I want I want public void log out okay and I'm simply writing system dot out dot println log out a method or simple I'll write log in in log in to act and you log out from ever something like this and I'd read after method is available in test in G so they'll get imported right and then so I'll write in a sequence like this better we write like this okay and then we have and write another at the rate after test Tran simple right public void so we have another annotation that at the rate after test okay so what do you mean a what do you want at the reducti test let's say add rate after that I want delete all cookies and simple system dot out dot println simple I want to print this right now I'm not writing any selenium code I'm just simply printing all these values okay and at the rate after test is there and then I want to write at the rate after class and I'd say I want to write public void and the Chi closed browser so simple I'll write system dot out dot println simple and write closed browser okay and at the rate after class available a test in G so imported from testing G and then we have one more last I rotation that is called add the read after write public void let's see what's closing the browser also what I want generate test report something like this and system dot out dot println sample I'll write generate test report okay in this enter it after sweet is available in test change e so just import it now see I have written so many annotations right so annotations are starting with at the rate before it is called okay pre difference it is a notation or I'll write preconditions okay starting with at the rate before okay add there before keyword so all these four are create facilities annotation this is your test case so test case means annotations this is your test case starting with at the rate test okay so we have only one test case because we have written only one at the rate test it means we have only one test case starting with at the rate test it means this is a test case these are post conditions starting with at the rate after annotation okay so these four are once your test case done what do you want I want to logout and delete all the cookies and close the browser and generate the report something like that I haven't received I am too written any selenium code right so I have divided my tests in G class into three parts preconditions test cases and post conditions so always remember in any test ng class we have three different conditions three different annotations there or maybe I will say three different sections the first section is precondition section then what is your test case and what is your post condition and once your test cases are done what do you want and the execution sequence of each and every annotation will be different okay what is the purpose of edit before suite what is the purpose of enter it before class I'll tell you now see if you run this class however you learn simple right click and go to run as instead of java application it will give you tests in G okay so done else test in G so if you run this class what will happen you see the output see it's generating the report I mean it's generating the output like this okay I'll tell you now see sequences like this it's giving you the output like this sorry okay so first step is saying that interesting first step is saying that set up system property for Google Chrome then log into the app and then launch Chrome browser okay set see the sequence is different now enter the URL Google title test log out from app close the browser and delete all the cookies now see what is the first annotation we have written at the rate before sweet okay so add the rate before sweet this particular annotation will be executed first okay immediately after that this particular annotation will be executed so I'll write immediately after this actually that will be better to understand add that before test okay will be executed second time this particular login method will be executed so I'll do one thing I'll instead of login better I change the naming and mentioned that launch the browser I'll write launch the browser and this I'm three login actually that will be better approach login okay now see first method is getting integrated this add read before sweet it's printing system setup system property for Chrome okay fine then it's executing to login to app okay so the second test case it's executing at the rate okay before it last method login to app okay so let's run it again okay now see system set property then it's executing at the rate before test method okay so this will be the proper sequence okay I'll write it once again okay so see sequence is very important test in G first method of executing setup system property for chrome setup system property for Co means the first method is executing at the red before suite a notation is getting executed second thing is launch the browser means and then it will give you the preference to add the read before test annotation and then at the rate before class annotation is getting executed and the read before class annotation is getting executed and then at the rate before method is getting executed at number nine number okay okay the for sequence look at this and then how many test cases we have here only one test case then this particular thing will be executed okay and then logout from app so then add the rate after method will be executed at like okay six position right and after that close the browser okay so close the browser will be executed at and after that delete all the cookies so then con like okay eight number did it all the cookies and at last at ninth position this particular thing is getting executed generate test browser I mean reporter okay generate test report okay so let's run it again okay see the sequence is like this setup system property for Chrome then launch the browser the log into web they enter the URL and then enter Google title test then log out from app and close the browser and delete all the cookies okay I'll tell you later why it is not printing this thing so let's comment this language or delete this we don't need this entered after sweet okay now see the sequence properly okay whenever you are going to execute a particular test in jigglers first time it will execute at the red before sweet annotation okay the first name it will the preference means the before sweet whatever the test suite we have written the first two friends will be given to add the read before C so whatever you have written inside ended before sweet method will be executed first okay immediately after that it will execute your at the read before test so before your test cases or before your test in G class what you want to execute before all the test cases I want to execute this thing launch the browser ok launch the browser now the third preference will be given to your class and the read before class okay now address before class will be executed the third position okay now immediately after that it will check how many test cases you have written I have written only one test case what is my test case this is a test case so add red before method the property is added before method will be executed before your test case what is my test case this is my test case and then this particular test case will be executed and then immediately after that it will execute at the rate after method okay so it will create pair add red before method at the rate test and add rate after method it will be executed like this okay now immediately after that once you're all the test cases are done then it will execute your this particular test case at the rate after class I will write over here so that the sequence will be proper see I know it's little confusing but it will be clear don't worry and then add rate after class will be executed and the last reference will be given to add the rate after test once everything is done at the rate after class is also done then add read after test ok will be executed now let's see I have to write some more test cases two more test cases I have to write so so far how many test cases we have so far we have only one test case at the rate test so if I ask you if anyone asked you that how many test cases you have in this particular class you just need to count how many add the rate test annotations are there so we have only one at the rate test a notation it means we have only one test case okay if you have only one at the retest rotation it means we have only one test is if you have five at the retest annotation it means you have five test cases so let's see I am going to create one more test case and and you can create n number of test cases with at the red test I rotation okay public avoid let's see mat test case his name is Serge test okay and I'm simply writing system out ordered println and printing search test okay now I have two test cases because I have to add the red test annotations okay it means I have two test cases now if you run this program now see it carefully if you run this program see the output okay the output is same preference will be given to see the output from here system set of system property for Chrome ad before sweet okay then the second preference will be given to add their before test that is your launch browser so that is also fine then login to app ok then log into web and read before class method will be executed then we have to enter the URL it means add read before method is getting executed enter the URL and then Google title test okay the first test case is Google title test it will execute Google title test and then log out from app it means at the rate after method will be executed now see and then again it will execute at the rate before method enter the URL and search test and log out from app and then close the browser and delete all the cookies now if you see one sequence here enter URL Google title test and logout from app enter your search test and logout from app ok so it will create the pair like this add the red before method at the rate test and add the red after method again add the red before method at the rate test case number 2 and enter it after method ok so the sequence will be like this at the rate before method then add the rate test case let's see number 1 and add the rate after method again it will create one more pair so it will check how many test cases are there two test cases between two pairs will be created at the rate before method and the red test case number two then add the rate after method like this it will be it will execute the sequence like this so see what what we have written at the red before method enter the URL Google title test and add the rate after method means logout from app again enter URL search test test case number two and no got from app so if you see the output see enter the URL Google title test and log out from there again entered the URL search test and log out from app ok this will be the sequence let's see tomorrow you have written one more test case at the rate test one more test case I lied public avoid let's see Google logo test ok and I'll write system.out.println simple I'm writing Google logo yes now how many test cases we have three test cases it means it will create three pair add there before method test one add read after before method test to add read after again at the rate before method second test case I mean third test case test case number three and at the rate after method okay so if you run this program see it's creating three pair see the sequence it will it it's not like first if you pick a test case number one and the test case number two and test case number three randomly it will pick any of them any test case but the pair will remain same see it's picking enter the URL Google title test the third test case I mean yeah the first test case and logout from app no see if you see it's coming from here enter the URL Google logo test the third test case and logout from app again enter the URL Google title test and logout from M again enter to the URL search test and logout from app so how many test cases we have three test cases we have so it will create three pair okay three pair of add the rate before method at the rate test and add the rate after method again add dry before method at the rate test enter it after and fourth third - if you have hundred test cases it will create 100 pair ok it will create hundreds with this add before test one and read after method like this okay but it will the pair will be created only in only with ed did before method and enter it after method okay and all these methods before class before test and before sweet okay this is only one time execution it will be executed only once okay before all the test cases these things will be executed so if you see the sequence first its executing sis first preference will be given to this guy at the it before sweet okay so I better I'll write like this and then the for sweet second preference will be given to add the rate before test okay the third preference will be given to add read before class like this and then your respective add before method will be executed okay on the basis of how many test cases you have written so let's see I have written this particular test case see you guys see whence is very important in testing gee it's little confusing but you once you practice automatically you will understand and the same sequence will be asked at a time of interview okay so let me copy paste these things so that you will understand it back it did it after test okay so let's run it again now see this is the pair okay and read before sweet will be okay this is a final pair I'll write it and copy this and then paste it over here comment okay the first preference will be given to add the red before sweet so if added before sweet annotation is available in your ing class the first preference will be given to this guy add the red before sweet okay the first preference is this I'll write again first difference is this second preference will be given to add the red before test okay will be given to this all before all the test cases add before tests will be executed third preference will be given to this guy at the red before class and then a pad read before method is there it will start creating the pair on the basis of test cases the pair will be created okay with the add that before method and add it after method only like this three pairs will be created like this how many pairs three pairs will be created pair number one the Google logo test Google title test and source test okay on the basis of the test cases the pair's will be created and then your this method at the rate after class will be executed okay so the third preference for persons will be given to this guy and then this will be executed then this will be executed and you know the last reference will be given to these ways okay and the rate after class and entered after test method will be executed at last so this is the sequence to design that is changing class but in real time programs we don't need all these number of annotations okay we don't define all these annotations maximum to maximum we use at the read before class and add red before method and add the rate test and same time add rate after method and enter it after class annotation generally we use okay but the sequence is very important they will ask you at a time of interview that how many different annotations are available in test in G so you will have to give the answer like this there are different annotations all prerequisite ease annotations test case annotations and post condition annotations so that you can design your test cases in a sequencing manner okay and now accordingly we will write our selenium code now let's write a selenium code with these annotations okay not for all these annotations but we will use some important annotations so let's create another class and my class name is let's see whatever let's see I'll pick Google test okay see the test in G class also you have to give like this let's say you're working in Facebook or Google or let's say you're working in Amazon you have to write the class name like Amazon search page test so give test keyword in your test class okay test keyword in your test class Google test it means this is your Google test class okay like this so it is a good practice that you are following some good naming convention so immediately if a new guy comes he will check okay Google test is the test class okay because test being written you can write Google also or Google feature also but you should write Google feature test or Google test test keyboard should be written now what I want first I'll initialize my webdriver here okay simple webdriver driver that's it so that I can use this driver immediately after the class I have initialize so that I can use this particular driver instance throughout my program and this webdriver is available in selenium so just imported okay fine now what I'll do first I'll define my at the rate before method I don't need any other annotation simple I will create the pairs the simplest and the most popular way of writing a test change is simple right add the red before method and all the previous cities you have to done over here method name generally we use an industry setup method okay public void setup you can use any method ABCD whatever you want to use but generally we use the name is set of method with a dread before method and import it from selenium or sorry test in G and what I want in setup method I have to define system property in all those things I want my complete setup so let's copy paste that code okay so this is the code force defining the system property and then launch my browser okay this is a system property and this is my driver okay instance is equal to new chromedriver right and after that what I want I want to drive a dot I want to maximize my window so driver on manage dot window dot maximize I wanted the previous trees like I want driver dot manage dot delete all the cookies and Driver dot I will define my timeouts and try for dot timeouts dot let's see page load time out please no timeout is 40 please refer other videos like how what is timeout what is phase no timeout and what is maximized and although step that we have already covered in other videos got seconds okay and we have to define diaper dot manage dot timeout not implicitly weight implicitly but also we have already covered so I'm not going to explain it again here time unit dot seconds ok so these are the different prerequisite ease so whatever the prerequisite ease are there just right all the very requested ease all together inside this setup method okay and then we will write our at the rate after method once everything is done what do you want I want method public void let's see my method name is teardown method generally we doubt we write teardown okay at the rate after method we have to import okay and what I want once everything is done I want to quit the browser drive or to quit okay so add the red before method I have written and add red after method I have written now I have to write the test cases let's see my first first test cases at the rate test public void let's see Google title test ok and at the rate test is available in tests in G so don't import from J and J unit important text in G and what I want simple I want to get the title so simple how to get the title driver dot you get tight method is there right but I would get title method and what I'll store I'll stored in some string variable string title is equal to this right and I'll simple print system daughter printer and write it okay so I have written this particular test case and then I'm going to execute this class so what will happen first it will execute add the red before method it will create the pair add there before method then add the rate test and then add the rate after method will be executed so it will create only one bear because we have only one at the rate test method okay just a minute so let's execute this class so how to execute simple right click on it and click on run s okay so see browser is getting launched it's done okay so it's saying Google title test okay let's run it again run as test in G and it's executing and it's launching the Google Chrome and it's so fast it's simple getting a title and printing it on the console and then I think it's done oh it's not printing on the console let's do it again we haven't entered the URL guys driver dot get method also we have to use and we have to use HTTP www.google.com right there only we will get the title okay so now cut on it again it's launching Google and then it's printing Google title then see it will generate the report like this Google title - one test case path see it will generate one more tab the result of this result of test in G Google test is the class and Google title test is the method so everything is green green means passed right now what I'll do I'll create another test public void let's see Google logo test okay so let's open Google and we'll see this image is coming or not okay so this is the logo this is a XPath and what I'll do simple driver dot find element by dot X path and XPath is this I want to verify that is X this part logo is available or not right simple I have use is displayed okay simple is displayed okay so if this particular logo is displayed it means it will return true or false so what I will do I will store in some boolean variable let's see boolean B is equal to this because obviously is displayed method is giving one boolean value either true or false okay and we will write some assertions also just wait for two minutes so now what exactly I have done I have created two at the rate test it means two test cases I have created it means it will create two pairs first it will execute a date before method then at the rate test and then add it after method again it will execute enter it before method second test and add rate after method okay so it will create two pairs it means every time it is going to launch the browser okay chromedriver maximize do everything enter the google.com and then execute this particular test case and then quit the browser again add that before method will be executed how many test cases are pending only one test case pending and it will execute this method and then at the after method will be executed so let's say I'm going to write one more test at the rate test public void let's see what can we test here let's see this mail link is there or not okay this mail link is there or not so public void mail link just something like that okay and simple I'm writing driver dot find element by dot link test and link Texas mail and again I'm checking it's displayed or not is displayed and then it if it is displayed then it will return one boolean value let's see boolean B is equal to this okay simple I'm just verifying is displayed is displayed or not that's it how many test cases three test cases it means three pairs will be created at the red before method then this one and enter it after method again at the rate after method it will pick this one and this one again at the rate after method it will pick the third one and add red after method so whenever we are going to execute test change a class first it will check how many test cases are there three test cases are there between three pairs will be created well we'll pick add the adapter method then it will check how many test cases three test cases randomly it will pick any of them let's see it is picking this one okay so the first test case will be executed this at at let's exit it's picking this one and then add the rate after method third time it will be executed again it will check how many test cases are pending two test cases but again it will execute this one so on forth number it will execute this it will check two test cases are still pending randomly it will break any of them let's each picking this one so again it will execute at the rate after method or six number again it will check how many test cases are there only one test case so but before that it will execute this one seventh number and then it will execute this and at last it will execute this this we will see see they will ask you at a time of NW these kind of sequences okay so like this okay before method test after method before method test after method before method test after method like this so let's run it you can directly run it from here also now see three times browser will be launched the first time okay second time launched third time okay see now the Gmail is there and we have written mail so it will be failed okay so and we have given implicitly weight of 30 seconds so it's gonna wait for 30 seconds if because we have written mail we have not written Gmail okay so it's gonna wait for 30 second then it will be failed just wait and see things are gone and then if you see the output it will generate the report how many test cases you got pass three test cases were there out of three two passed Google logo test first it picked Google logo test okay then it pick Google title test we will title test and then mail link test is getting failed by its same unable to locate element this mail and if you see the test engine report also this is by class Google test is the class in this particular class we have Google logo test got pass this is green Google title test this is green this is also passed and mail link test got failed because there is no mail link there is a gmail link so it will give you a feel if you see test change your report properly it's seeing it's saying that okay no such element exception okay this will give you the proper error but it will generate the report like this you can share this report to your manager let's see you have written 100 test cases it will generate hunter - cases like this but the pre diversities is that it will create the pair before method and the rate test after method before method and the retest after method before method and three tests after method like this okay so this is the first session in tests in G a little covered like what are the other feature that we yeah I mean and that how to run it like that right-click and test in G we were doing like to run that particular method yes yes so simple see if any particular class is having main method always remember and if you right-click then you will see run as java application so main method infinitum right click run as java application will be there but if executing test ng class right because there is no main method then we will get run as test in G class okay got it yeah and every time it will follow the same sequence rate which you have mentioned that one two three and four five six okay see but the test in all that which we have written right it doesn't depend if we want to execute one test it will go through the all the tests before which we have mentioned yes exactly but the sequence of the test case is random it will pick any of them first it is not decide but okay I have one more annotation that I will tell you later what variety also you can define if you write priority is equal to one two three then I'll tell you later tomorrow okay but if you don't write any priority then it randomly it will pick any of them okay so not go according to the order it will just pick oh yeah it will just matter that okay you have written first Google title day then it will execute this one only no it can pick mail link test also and it will pick this one and then it this one if you have written 50 days randomly it will pick any of them okay but it will create the pair with at there it before method and add that after method okay but if you want to define the priority the sequence one keyword is their priority keyword is there okay so let's island I will show you right away the priority is equal to 1 let's see inside the bracket here - right priority keyword variety is equal to 2 and quite variety is equal to 3 now the sequence is defined then and there it before method priority 1 and the rate of chemical added before method priority to add rate after method add before method priority 3 and add the rate after method like this it will be executed okay now if you run this program let's run it see 3 times browser will be launched second time and the third time without a checking okay so I'm going to close this browser I am NOT going to be it for 30 seconds okay no see first google title test google right to the test and then google logo test google lower test mail link test third numbers mean so if you want to define the priority one keyword is their priority keyword is there okay lets you have hundred test cases you want to define in priority one two hundred you can define i want this test case should be executed for then this test case should be educated is like this you can define the priority randomly one then i want then three and then this is two like this also you can define first they execute this one then i execute this one and then execute this one like that also you can define with the help of priority keyword okay so we will talk about it later in the next session okay so that's all for today okay I'll see you tomorrow then
Info
Channel: Naveen AutomationLabs
Views: 507,658
Rating: undefined out of 5
Keywords: TestNg, Selenium, Webdriver, Java, Automation, Framework, NaveenAutomationLabs, 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 Training Tutorial, TestNG Framework for Selenium, testng selenium webdriver example, software testing tutorial, @test testng annotation, Testng Tutorial for Beginners, Mukesh Otwani
Id: 0Gew2XOuum8
Channel Id: undefined
Length: 63min 17sec (3797 seconds)
Published: Mon Sep 11 2017
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.