Basic structure of TestNG xml file - P4 | TestNG | Testing Framework |

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello everyone i'm yada garadi and welcome to my channel hpr tutorials in this video i'm going to talk about testng xml file so here i'm going to cover all these points basically so the first point is what is testing xml and what is the need of testing gxml and how to create the testing gxml file and how to add the test cases to the testnj xml file and how to execute those test cases using testnj xml file okay so these are the points that i am going to cover in this video so this is the agenda for this session guys so first thing first what is testing xml file so test engine xml file is a configuration file which contains the test execution details okay so here the test execution details is nothing but the test execution flow so how you want to execute your test cases and what are the test cases that you want to exactly execute so all those informations will be saved under one configuration file and that configuration file is nothing but the testnj xml files so the next one is what is the need of testing xml file so here i will do one thing guys so to make this concept very clear for these two questions so the answer is going to be only one okay basically the answer is going to be one so i'll tell you one scenario then you will understand these two questions clearly so first i will go to the scenario then i will answer these two questions after that so first let me open the eclipse so in our previous video what we have done we have created one class file okay we have created one class file and we have added two test methods to the class file right so if you want to execute one test method from this class file how do you execute that you will simply click on this run so this test method will be executed and if i want to execute all the test methods present inside this class i am going to click on this run all or i just simply right click on this and go to run as and i'll run this one as a test ng test right so this entire test class will be executed that means all the test methods that are present inside the test class are going to execute so here i have only two methods so it is very easy so i can either choose this one or i can individually choose this one or i can choose the entire thing right but if i have three methods okay if i have three methods inside the class or if i have multiple class files and multiple test methods in each class file so in that scenario how you are going to execute so in the real-time scenarios you are not going to have a two test cases only right so for project you are not going to have only two test cases you are going to have multiple test cases sometimes it is going to be in thousands also so it is not even hundreds it is going to be thousands also okay so how do you execute all those test cases so let me give you one example here so let me write that first test first class so i have two classes basically first class and second class let me add one more class also for clear understanding so inside the first class i have a comma b methods and in the second class i have c comma e sorry d comma e and in the third class i have f g h i so i have four methods in inside this one so in the first one i have only two methods and in the second one i have three methods and in the fourth one i have four methods i mean the third one i have four methods basically so i want to execute only particular methods from the particular classes i don't want to execute all the methods here so how many are there basically 2 5 and 9 so on and overall in my test project i have 10 test cases right so around 10 test cases so let me add one more here and i'll say i have 10 test cases but i don't want to execute all the 10 test cases i want to execute only particularly three test cases so what are those three test cases so i'll say d comma e comma h so these are the methods i want to execute only these are the test test cases i want to execute so here how you will choose this you cannot directly go into the first class and execute only b then come back to the second class and execute only e and come back to the third class and execute only h so that is not possible right because i want to execute these three test cases in single execution so when i press one button so when i click on run all three test cases should be executed so that is my requirement right so how do i achieve this requirement i cannot achieve this one right so i mean if you are following the traditional approach what i have shown you yesterday so if you are following that approach you cannot execute that right so because each and every time you cannot go into the class and you can you cannot click on the run button right so we should have something which can have the information of our execution that means we need to have some file where we can mention like okay execute this test method execute this test method and execute this test method so that kind of file we need right so that is the configuration file that we are actually talking about so this file we are actually calling it as a configuration file and this configuration file itself we are calling as a test ng xml file so inside this testnj xml file we are going to mention our test cases what we want to execute and in which order we want to execute and how many times we want to execute and all the information about the execution that we are going to mention inside this configuration file so that is about the testing gxml file guys so now we got the idea right what is the testing xml file restoring xml file is a configuration file which will have the execution information like what are the test cases that you want to execute and how you want to execute them and what is the need of the testing xml file so now i have on you right so you need to have the testing gxml file because you cannot go into each and every class and you cannot pick the individual test cases so you need some kind of a file where you can mention the test cases i mean the list of test cases that you want to execute so that is why you need the testing gxml file and the next one is how to create the testng xml file so now we know what is a test ngxml file and how to use that one also okay i mean what is the need of that one also but how do we create that one so let's see so if you want to create any file in your java project how do you create that so you will just go to the package and you will just right click on that and click on new and you will select the other if it is a class file you will directly pick it from here if it is an enum file you will directly click on this one if it is an interface you will click on this if the file i mean that you are looking for is not displayed here then you are going to click on other right from here you need to search and you need to create that file right so that part is very clear right so you all know how to create that file basically so here which file we want to create we want to create the testng xml file right so here one more thing i want to convey guys okay so many people are actually asking okay many people are actually asking in the google that our testng xml file name should be test ng only i mean is it is it like a rule or something so here extension xml file means it is a xml file okay the extension is xml and we are creating this xml file inside our testng project right so it is going to have the test ng related information that means we want to add the test cases that we want to execute so this is entirely in the test ng format right so that is the only reason we are calling this file as a testing gxml file so it's not like the name itself is a test ng okay we are calling this file as a testing gxml file because this file is present inside our testng project and it is having the test ng related information that is the only reason we are calling this one as a test in the xml file but you don't need to have the name also as a test ng only you can have any name basically you can have dummy.xml you can have fastertest.xml you can have like new file.xml anything anything basically so that is one one main important thing guys you need to remember so many people are actually when they start practicing right they will immediately create testng.xml so it is not a rule guys it is not a rule that you need to create only testng.xml the file name also should be testng.xml it is not a rule okay you can have any name and you can have any file okay you can have any number of files in your project also okay so that is also possible you can have any number of test ng files also in your project and each file can have a different name for suppose if you are having 10 files you cannot have all the temp files with same name right like test engine.xml so you need to differentiate each file so you can have any file name and you can have n number of files also so that is the one important thing that you need to remember so this is this lead out only but it is actually a valid doubt because every i mean if you go to youtube or if you go to google or anywhere right so people actually find like this test ng.xml so people assume that the file name itself like a testing dot xml so they don't know right so it they will assume that the file name itself is a test engine.xml basically it is like this testng xml not testng.xml so here i have intentionally put test engine.xml to explain this concept basically so let me remove that so that it will be good for us because as we have discussed the concept now so it is good for us to remove this one now so now we want to see i mean how to create the testing gxml file so as i said it is a xml file and you can have any name for that so here i need to create the xml file right so let me first check whether i am able to directly create the testngxml file or not so when i type test ng here i'm getting only test ng class so i don't have any option to create the testng xml file here right so then what we need to do so as i said it is a xml file so we can create an xml file with any name right then we can add the testing related code to that one that is a possible one all right so how do you create the xml file just type xml here so here we have the option to create the xml file right so let me click on next so here actually we have two ways to create the xml file guys so first i am showing you with entirely manual process then i will show you how to generate the testng xml file so here i can have a name like new file.xml so this is valid only right so i am going to create this file in under the resources folder so if you are creating anything like if you are adding a driver executable files or if you are creating the xml files or properties files or anything those comes under the resources okay those will not be i mean those will not be stored under any package those comes under the resources folder so i'm going to create them under the resources folder and let me click on finish so now the xml file is created so when you create any xml by default this will come okay so it is going to represent what is the version and what is the encoding format of this xml file so if you want to keep it it is fine you can keep it if you don't want to keep it that is also fine just you can remove it so i'm going to i'm going to keep this one and then we need to add the test engine related information here right so what we need to add so to make that clear let me tell you one more example here okay so generally in our java what we will have we will have the packages right so inside the package what we will have we will have the class files so inside the class what we will have again we will have the methods so this is like a structure right so you will have a package under the package you have a class file under the class file you have a method so in the similar way here also we are going to have a test to suit so generally manually what you will have for suppose if you want to keep all the 100 test cases at one place what you will call that place that is a test suit right so inside the test suit you are going to have the test cases basically right so the first thing is test suit inside the test suit we are going to have the test cases so i can say test inside the test i am going to have the test steps right test steps so inside the package i have a class inside the class i have methods so in the similar way i have a test to suit inside the test suite i have multiple tests and each test is having multiple test steps also right so let me implement the same here but here i am going to implement in a different concept guys so i am going to implement in a little different concept here so first let me add the suit so here it is suit not test suit basically so i need to add the suit first so in xml everything is a tag only right so you can have any number of user defined tags here so suit is one tag and again test is one tag class is one tag so here i have created a suit tag so inside the suit what we are going to have we are going to have the tests so multiple tests we are going to have right your tag name should not be tests okay because it is a plural but you are going to create a singular one here right so like this you can have multiple things so then we can say tests so you can have like this but for now i will go with only one test and let me uh like this so inside the test i'm going to have the test steps right but i don't have any i mean any tag called test step so i should not write any tag called test step so where exactly these steps are actually reciting it so when you create any class under the class you are actually creating the test methods right so each test method is going to represent one test step okay each test method is going to represent one test step so where exactly this test method is actually present it is present inside one class file right so if you want to access the test method you need to access the class first right so that means we need to have the classes so under the class we are going to first pick one class and under that class we are going to pick multiple methods so in each class you are going to have multiple methods right so like this so let me align this so this is the order that you need to follow guys okay this is the order that you need to follow basically so if you don't want to mention the methods and if you want to execute all the test methods inside a class then you don't need to have the methods tag here you can directly write like class name something and it's going to be a self-closing tag so like this you can have multiple classes also right so for suppose if i want to create one test with multiple test steps so in this scenario so if you consider this entire thing as a test so if you consider each one as a test step so i am creating one test case like this b e h so if i execute these three methods then my test will be completed so like this i can have one more test that is a d and i now i have two test cases with each one is having three steps so like this i want to build so in this scenario i'm going to have the mult i mean methods tag but here if you want to execute all the method i mean all the test steps inside one class then you don't have to mention the methods tag here okay you can directly like this so if you want to execute multiple classes you need to write like this you can have multiple classes also because all your test methods cannot be in the same class right they can be in different different classes also like this for suppose i want to execute all these methods and all these methods also then i need to execute two classes right so in that scenario you can have two class tags here so inside the classes you can have two class tags or three class tags also any number of class tags you can have okay based on your test basically so now what i'm going to show you is so in our previous video we have created this one right so some people are actually asking like why you are actually showing with the basic websites like google and facebook so we want to see something new so we have something called orange hrm demo so this is one good website for practicing selenium orange hrm demo so you might have already come across this website so this is the website guys you can find the username and password on the login screen itself so once you log into that one you have so many options okay you have so many options and if you click on anything so you will have again so many options you can you can have any number of drop downs you can have a number of check boxes and you can have data date controls so everything you can practice from here guys so that is why i'm going to choose this website basically so here what i'm going to do i want to test two scenarios so what are those i want to log into the application and i want to see whether i logged in or not that is the one scenario and the next scenario is i want to log into the application then i need to click on this my info tab and i need to see whether these things are actually displayed or not so these are the two test cases that i want to execute along with the test google and test facebook also so how do i write that so i have already created one class file okay for the time saving i have already created one class file called orange hrm so inside the class file i have added few test methods so what are those methods one method is for launching the app so what exactly it will do it will launch the chrome browser and it will maximize the browser and it will navigate to orange hrm website then i have another test method that will enter the login details and click on login and i have another test method for navigating to my info tab so once you log into this one i need to click on this my info tab right so for that again i have one more test method because as i said every test method is going to represent one test step right so that is why i have like this and next i have something called verify my info so once i log in i mean once i open this one once i click on this my info i need to verify whether these details are actually displayed or not so that is another test method and here one more thing is verify login so in the first test as i said we want to verify the law i mean login is successful or not right so for that i need to verify the login also okay so i have added the code so here i'm not doing much verification guys so in the verify login what i'm doing i'm verifying the welcome message so where it exactly it is so let me show you that so this is the one welcome is there right so this is the one i'm actually verifying so you can see this is the id so if i get this welcome message that means that my login is successful right so if i don't get this one then my login is failed and in the similar way here instead of verifying all this text and details i am simply verifying the due tag here so what is the due tag so let me take this entire due so this is the employee details due so if this employee details dv is displayed maybe all this information is also displayed for now we are not actually narrowing down okay we are just doing this one at the high level so i'm just verifying whether this db is actually displayed or not that's it so now i want to add these test cases okay so if here if i right click on this and run as then all the tests will be executed and they will be executed based on the alphabetical order that is the first thing that you need to remember so when you right click on any class and execute the test cases they are going to execute in the alphabetical order they will not be executed in the particular order right so to avoid that we are going to use the testng xml okay we have another way but that way we are going to look in our upcoming videos so for now we want to learn the testng xml file also right so that is why i'm going to show you from here so how do i add there first i need to have one class right one class i want to have and inside the class i want to have the methods so here i'm not getting the art of suggestions basically guys so that that feels like you know odd so i'm not liking this one so whenever you type you know mvt you are not getting the auto suggestion so it is not automatically filling that is because this is a manually created xml file and we don't have any dtd specified here so we we haven't specified any template here that like you know uh this xml file should have all these tags like that so that is why we are not getting any auto suggestions here so i don't like this one and even you don't like it right so you have to type everything manually so to avoid this i'm going to generate the testing gxml file okay i'm going to generate it this time i'm not going to create manually i'm going to generate the testing gxml file did you observe my work i'm going to generate the testngxml file so how do i generate that so let me just right click on the project so here for support i want to create this testing gxml file under this resources folder right so i'll simply right click on this and go to testng so here in this menu bar you will find something called testng so if you don't find this option that means you should not install the testng eclipse plugin so if you find that option then your testng eclipse plugin is installed successfully so once you find this one just go to that one so here we have something called convert to test ng so click on that one so here it is showing the options okay it is showing basically so first let me delete this okay so it is having the okay now it is deleted basically so let me right click on this basically or let me right click on the project itself this time and convert to test engine so now you can see we have the xml file created here right we have the preview of xml file so i mean our testng project is by default creating one xml file for us with all the information so now we have two class files and each class file is having some test methods in it so that is why two class files are actually added here so if you want to modify that how do you modify that so after you generate this xml file you can directly go into that xml file and modify that file right so here it is asking the location where you want to create the file so by default the name is going to be testng.xml file so you can change the name also so where i want to create that file i want to create that file under src under test under resources folder so inside the resources folder i will say mytest.xml i am not going to choose the testng.xml so i am not going to choose that name testng here here i'm going to choose my file name as my test dot xml so what is that suit name so you can provide the suit name and you can provide the text name also so by default the suit name will be suit only and by default text name will be test only so let's keep like that only and i will show you where to change and everything so let's click on finish the xml file is actually created so let's open that so let me remove these stacks actually and these are the comment lines so it is going to disturb us okay so i have removed them so now you can see here we have something called doctype this is the dtd that i'm talking about so if you have this dtd right so inside this gtd all the information is going to be available like i mean what is the format that you need to follow and how many tags you need to have everything so what are those default attacks that you need to have every information is going to be available inside this dtd file so that is why here we will get the auto suggestions so here you can see we have something called suit and for the suit we have something name you can name it anything so i'm just naming it as demo suit and i have some one test also for this test i have something called thread count so i'm going to remove that so i'll explain about the thread count in our upcoming videos for now just ignore that one so for test also we have something called name okay you can name your tester so manually you will have a subject for your test right so in the similar way here also you can have some name on and name and description also so what is the name i will say login hrm orange hrm login orange hrm login so in the similar way i can have another text also right i can have another test so that test name will be orange hrm my info and i can have another test also what is the test google simply i can have multiple tests like this guys so inside your suit right you can have n number of test cases so inside each test i need to specify what are the methods that i want to execute right so here by default all the class files are actually displayed so i don't want to use all the class files so here it is actually pointing to orange hrm login that means i need to only perform the login operation here so here if you mention this class name all the test methods inside the class are going to execute but i don't want to do like that i want to specifically mention the methods here so then you need to have methods tag inside the class tag so methods the tag name is methods so this time i'm not going to type the entire thing so i'll simply write mut and i'll press ctrl space now you see we are automatically getting it right so these are the auto suggestions and auto generation that we are actually had because of this dtd so inside the methods we are not going to have anything called method okay we are going to have include so that is little bit confusing but don't confuse so inside the classes we have something called class so this is the plural and this is singular so this is a plural inside the methods we should have a method right we will not have a method we will have something called include that means what are the methods that you want to include basically so under this methods tag what are the methods that you want to include so that is a tag include tags so when i say i n c automatically you are getting okay for this include tag we are getting one property also that is name so what is the method name so here you need to mention the method name also so first i want to perform login operation for login what you need to do first you need to launch the application right so i'll mention launch application first then here so inside the matter we are not going to again specify anything so you can have the self closing tag here so if you want to mention anything again you need to write the tags like this but if you don't want to mention anything inside this you can have a self closing what is the self closing so at the end of this one if you put a slash then it is a self closing or auto closing also so some people call it as a self-closing and some people call it as an art of closing so you can have this kind of tags so this is one method like this i want to add another method also right so what is the other method so after launching i need to enter the login details here so let me go here enter the login details then i need to verify the login information okay so verify login is the method right so this is one first test method so let me align this so now it is beautifully aligned right you can see under the suit we have test under the test we have classes under the classes we have class under the class we have methods under the methods we have include so the spacing and everything is properly aligned so you can easily understand this one so now the first test is ready and let's prepare the second test so what is the second test my info so this is the same class right so i'll just copy this but the methods that i am going to use are going to little bit different so i launched the application i will enter the login details but instead of verifying the login i'm going to verify them in my information okay so if you want to verify the my information first you need to navigate to the my information so i will navigate to my information then i will verify the my information so i need to add one more method here so while i'm doing this thing right you need to observe one more thing guys so i'm adding multiple test cases and i'm adding multiple methods also so in this class i am specifically mentioning what are the methods that i want to actually execute that is what we have actually discussed right so that is what the testng xml is it is a configuration file which says like what are the methods to execute and in which order they want to execute okay so those are the information that i'm actually adding here so that is what i have explained right so the next one is test google so the test google is actually present inside the first test so inside the first test i need to have this this thing so inside the faster test class i need to execute only test google method so i'm going to have only a single method inside this let's see so now how many tests i have i have three test cases orange hrm login is one test case and orange hrm my info is one test case and test google is one test case okay inside the test google i have only one test method and here i have four test methods and here i have three test methods right so generally from the java file i mean from this testing class how did you execute the test cases you either click on this run or click on run all or right click on this and go to run as and run as test so you need to observe this one carefully we have something called test ng test but here if you want to execute this testng xml file you need to right click on the testnj xml file itself and go to run as here you will find testng suit so what is the difference there so there we have test engine test and here we have test engine suit here we have testing suit because in the test engine tool we have multiple test cases we have the i mean super tag as suit so inside the suit we have multiple test cases and each test is having multiple steps basically right so here that is why we have something called test suit so we need to run like this run as test changes suit or you can simply right click on this one from here itself you can right click on this xml file and go to test and run as and run as testng suit so let me run this one so first my orange hrm login should be executed then my info should be executed and in the end my i mean google should be executed so login is completed you can see it printed the text also then now my info is actually executing so login is completed and it has to click on my info and my info is also displayed right so now in the last it is executing the google google test basically so here it says eight tests are actually executed here this console is going to show you the test method count so how many test methods you executed here we have executed three and here for three plus four seven and here one so this is eight right so the test method count it is going to show you here so you can see the suit name is demo suit and here we have something called test change results also so go to that one so here we have demo suit under the demo suite you can find three test cases orange hrm login orange hrm info test google so inside the orange hrm login we have one class and under that class we have three test steps and in the similar way inside the orange hrmi info we have four test steps and in the similar way inside test google we have one test step so we can verify from here or we can go to our root directory okay so where we have actually created the project so this is my project so under this project test output folder will be created so just open that so here you will see something called index.html okay click on that so you can see demo suit is the suit name and we have three test cases right so when you click on that you can see orange hrm login orange hr mine for test google three test cases are actually displayed right here it is saying three test not eight tests so in the console it is going to show you all the test steps but here in the testng result file it is going to show you only three tests so now you understand right so how to add the test cases we have seen so let me go back to this one so we have finished with testng xml what is the testing xml and we have seen what is the need of testing gxml and we have seen how to create the testing xml file we have created something manually and we have generated using auto generation option also right and here we have added the test methods so how did we add so after creation of xml file we have added like this manually right so we have to pick the class name using package so this is something important guys so some people actually what they will do they will remove this one and they will think right okay my class name is orange hrm only i need to mention orange hrm you should not mention like that because you will have multiple packages so where it has to look for so for suppose you may have one to ten packages so your class may present in fifth package or sixth package or seventh package so our testng xml file doesn't know where it has to look for right so that is why you need to always mention the package also your class name should start with the package name so this is the entire path and for the methods you don't need to mention because inside the class file you are referring to the methods okay you need to mention the method name only that's it so this is how we need to add the test cases and we need to execute the test cases fine so we will take everything slow so no hurry guys okay no hurry we are going to learn each and every topic very clearly by splitting separate separate sections so we don't want to rush everything and we want we don't want to learn the entire test engine in just an hour right so we don't have any rule like that so as we are starting from the scratch we want to understand every concept so you should know what is the reason behind adding the testing gxml file and you should know why we need to add in this format also we have created first suit under the suit we have created a test under the test we have created the classes right so you should not think like okay this is a syntax that i need to follow you need to understand why you are actually following the syntax then only it will come into your mind okay otherwise you will always go in that way and you will not understand what exactly you are doing so if you enter your ask you also you will say that okay this is the format and if interviewer ask you why you need to provide like this you will have a blank face right so that should never happen so whatever you are learning learn with full concept so that is my motto guys here so we don't want to take the big steps we want to take the baby steps so let me show you one thing so i don't want to be like this big root so i don't want to take the big steps i want to be like this small group here so like this group i want to take the steps okay i want to take the small small steps under understand the each concept and enjoy the each concept so we should not feel like okay this is so boring like that we should not feel we should have the interest to learn this so that is what actually i want from you guys so if you haven't subscribed to my channel right please subscribe to the channel so you need to show the support right so i'm spending so much time and i'm creating the videos and you need to show the support from your site so that support is going to give so much motivation for me so that i can create more and more videos for you so if you subscribe to the channel and if you write your comment also like did you like the video and what part did you like the video and if you have a doubt you need to mention that in the comment section right you need to mention that in the comment section like what did what you did not like and where i can improve that so if you mention then only i can improve that so everything whatever either it is a good thing or that is a bad thing you need to mention the comment guys the feedback is something that you need to constantly maintain with your trainer so either it is me or your real-time trainer or anyone so the feedback is something that you need to maintain so that is going to give me some motivation and so that i can make more and more videos for you so that is for this video guys i hope you understand this video if you have any doubts please let me know in the comment section below thank you for watching bye
Info
Channel: H Y R Tutorials
Views: 4,863
Rating: undefined out of 5
Keywords: hyr tutorials, h y r tutorials, selenium webdriver, selenium java, testng, testng tutorial for beginners, testng tutorial, testng annotations, testng selenium, testng framework in selenium, testng framework for selenium, testng framework, testing framework, testng tutorial for selenium webdriver, testng tutorial java, testng framework tutorial, testng annotations in selenium webdriver, TestNG Framework for Selenium, what is TestNG xml file, How to create testng xml, testng.xml
Id: iEOZ2FmTWe0
Channel Id: undefined
Length: 33min 30sec (2010 seconds)
Published: Thu Jul 29 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.