Parameters in TestNG - P8 | TestNG | Testing Framework |

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello everyone i am yada yada and welcome to my channel hbi tutorials in this video i'm going to explain about parameters intestine g so this is the agenda for today's session guys so first we will discuss about what is the use of testing g parameters then we will also see how to use the test ng parameters so these are the two points i am going to explain inside this video so the first thing first what is the use of test engine parameters so generally before i explain anything about these testing parameters first try to recollect the concept of the parameters so this parameters concept is not just introduced in test engineering so this parameters concept is already present inside every programming language so here we are using the java programming language with testing right so even in java also we have the parameters concept so how do you use the parameters i mean what is the use of parameters basically so as a user if i want to pass any information to the method then i am going to use the parameters right so in the similar way here intestine j also if as a user if you want to pass any information to the test ng methods then you need to use some parameters so those parameters are called as test ng parameters okay so that is the use of test change parameters basically but in which scenario we are going to use the test engine parameters so the requirement is in your hands guys okay so i'm going to tell you one small example here so for suppose i have a suit with some hundred test cases so i want to run these 100 test cases against different different browsers and against different different urls also so in our testing we will have multiple urls right like production url and pretest pre-production url and testing url and development url like that right and also we will have different different browsers so we need to perform the testing on different browsers right so for suppose i have 100 test cases right so i want to execute the first test in chrome browser and second in firefox and third in edge so as a user i want to decide that that means as a user i am passing the information the browser name information i am passing right so i am passing the information to the test method saying that okay the faster test should be executed in this browser and the second test should be executed in this browser so like that i am passing the information and in the similar way as a user i'm passing the url information also right so as a user i'm passing the url information like the production url or testing url or development url so as a user i'm passing the url information also so for handling these kind of scenarios i need to have the parameters only right so for that purpose we are going to use the test ng parameters i mean this is one small small example guys but in your real-time applications you might have a different requirement okay so wherever you want to pass any value to the test ng method then you need to use the test ng parameters fine so now let me show you how to use them so generally in java how do you use the parameters so first we will create one method with some parameters like this then whenever we are calling the method we are going to pass the information right so as a user i want to pass the information to this method so but when i will pass that information so whenever i am calling that method i am going to pass that information right so in the similar way here in test ng i need to pass the information whenever i'm calling the method right but in testing g i'm not going to create any object or i'm not going to call this method physically right so how do i call the methods in test engine so i'm going to have one testing xml file and inside the testing xml file i'm going to mention what are the methods that you want to execute that means what are the methods that you want to call basically right so from the testing gxml file you are calling the methods right so you are mentioning the methods i mean the list of methods that you want to call basically right so that means i need to pass the information also from the testing gxml file only because this is the place from where i am actually calling the methods so that means i need to pass the parameter values also from here only right so that point is very clear now right so here if you want to have anything i mean if you want to call a class or if you want to call it test or if you want to call a suit so for all the things we are going to have on tag one xml tag right so like that for parameters also do we have any tag yes we have one tag the tag name is parameter so let me show you so when i type para you can see so there is a parameter tag with two attributes so what are those attributes the first one is name and the second one is value so for every parameter we should have a name right so here in java you can see this parameter is having one name so what is that name this a is the name and this parameter is also having one name so what is the name this b is the name right so like that every parameter should have the name and also it should have the value also right because we are passing the values from here so that is why we should have the name as well as value also here fine so this parameters can be passed at the suit level as well as at the test level also guys why is like that so if you want to pass any parameters that are common across all the test cases then you can pass a parameter at the suit level okay so if you mention any parameter at the suit level this parameter value can be reused i mean this parameter value can be accessed in almost every test method okay almost in every test case here but if you mention any parameter inside the test then that parameter scope will be limited to only the tester so that means if you want to pass any parameters that are specific to the test then you need to go for the test level parameters that means you need to pass the parameter inside the test because when you pass the parameter inside the test the scope of this parameter is going to be limited to this test case only so when you pass the parameter outside of this test then the scope of the parameter is going to be limited to the entire suit so inside the suit whatever the test cases are there all the test cases can access this parameter value fine so now let's first go with suit level parameters then we will see the test level parameters so first what are the parameters i need to create so first let me open this class this orange hrm class so this class we have created in our m in previous sessions right so here what we are exactly doing we are opening the browser and we are launching the application orange hrm then we are entering the login details and we are verifying whether the login is successful or not right so in the similar way there is another test case that is open the browser then launch the application then enter the login details and then navigate to my information tab and verify whether the my information tab is actually displayed or not so these are the test cases i have right so here can you tell me where exactly can i use the parameters so here i'm opening the browser right so i want to take the browser name from the user so i can use the parameter here right so in the similar way here i have a url so i want to take the information from the user itself the url information from the user then i can use the parameters here also and here we have something called credentials right the username and password so these informations also i want to capture from the user only so i can use the parameters here also right so like this the requirement will be in different different guys so here i have only this requirement but in your application you might have a different requirement for that right so first let me add the parameters so the first thing is browser name basically so let me add one parameter for the browser name browser name so let me give a small letter here because it is a parameter name right so the parameter name should be always camel case basically so the first letter should be in the small so next the value so what is the value so you can pass a chrome also okay chrome browser or firefox browser or edge browser so which browser you want to really open that value you need to pass here so first i will pass the chrome browser only so you don't need to provide like these guys okay so you can directly provide the self closing also because inside the parameter again we are not going to pass anything fine so let me add one more parameter that is url so what is the url here so i want to pass this url basically let me copy that and put it here so this is the url i want to pass let's so let me close this one itself closing so now two parameters are actually created so i want to pass this parameters right so i mean these parameters are actually present inside the testing xml file only right so i want to read this parameter information inside the methods right so if you directly pass this parameters so how do you know that these parameters are actually going into the methods so the method also should able to capture the parameters right so whenever you pass the values here so let me show you so if i pass the values 4 comma 5 like this so if i don't mention the parameters here at the method level then the values are not going to go okay because the method method also should be able to capture those values right so that is why we need to mention the parameters also inside the these methods also okay so first we need to access these values from the xml so this variable names and these variable values we need to access from the xml right so further first we need to use one tag that one annotation that is at the right parameters fine so this annotation will allow us to read the values from the textngxml file then from here we can feed those values into the method guys so you can use the at the right parameters annotation and you need to pass the parameter name here so you don't need to pass all the parameters here so whatever the parameter that you want to use inside this method only pass that parameter value here right so which parameter i want to use here i want to use the browser name so let me copy this browser in parameter name so this name should be same guys so inside this parameter annotation that name whatever the name that you have given inside the testing xml file that name should be exactly matching so i'm reading this browser name information and it is coming and it's sitting here but i want to actually capture this browser name value inside my method right so for that i need to again have one parameter here fine browser name so this name and this name can be same and cannot be seen so there is no rule like this name and this name should be same so let me add one switch condition here so i want to handle the browser right so i want to open the browser based on the user input so i will say chrome and let me just cut this and put it here and in the similar way i want to open the browser for multiple things okay like firefox browser and edge browser like that i want to open multiple browsers edge and file box so here i need to change the code for the edge driver right so in the similar way edge fine and here it is firefox and here also it is firefox so if the user is not passing any of these browsers okay so today my code is actually accepting only three browsers so if the user by mistakenly passes any other value so i need to handle that one also right so i'm going to handle that one here so i'll just print that one inside red color i mean i'm just going to print the cis out statement only i'm not going to throw any exception here so i'll just say browser name is invalid is invalid so you can throw the exception actually but i'm just you know you know printing the statement here guys okay so the user can pass the value in the capital letters or small letters or any any case right so i want to handle that scenario also so i need to come i mean i need to convert this one into lowercase then i can verify that in the lowercase only fine so this browser name one is perfectly created so next i want to use the url also right so again add the parameters tag here i mean annotation then inside this method i want to read only url information right so i need to add the url so this is the name same exact name as this one fine so next i need to capture this url value inside this method right so i will write string url so this url i want to use here right so i don't want to open this url i want to basically use this url here so whatever the value that is coming from the user that is going to replace to here fine so now the values are actually replaced and let me do some more refactoring here so in my previous session we have already discussed about the assertions so before that session i have already created this class file so let me add the assertions here so i have simply add the c server statement previously so let me add the assertions here so first i will say boolean so this is the actual value right so whatever i'm getting from the cylinder webdriver that is actual value so here what exactly i'm doing i'm trying to verify whether the my information tab is actually displayed or not so this is going to return a boolean value so i'm storing that one inside the boolean so when you have the boolean value which condition you need to use i mean which asset statement you need to use we need to use asset true right so let me use asset true so i need to pass the actual value here so like this and in the similar way i need to verify the login also so i am verifying this one okay so let me show you that so this is the welcome text right so this welcome message is there or not i want to verify so first i need to verify whether that is displayed or not and next i want to verify the text but here the name is there right so this name is going to change always so i'm going to just verify this welcome only okay so let me add the code for that so again i'm going to use the asset true because i have something called is displayed so this is displayed is going to return the boolean value right so that is why i'm going to use the asset rule and next i need to verify the welcome text so this welcome text i need to verify but when i use get text method the entire text is going to come so i need to mention this one as starts with right so i need to verify that it starts with text the starting text is welcome so this is going to return the boolean value right that means i need to use the asset true assertion basically fine as a true this one and let's remove this statements from here and now my code is perfectly all right so let me execute this so i'm going to execute two test cases basically the first one is going to verify the login and the second one is going to verify the my information tab so let me execute this so this time you need to remember that i am passing the browser name from this exchange xml file and also the url from the testing xml file so now you can see the chrome browser is actually opened that means the parameters are actually passing to the methods and the url is also open and the first test is completed and the second one is getting run so let's wait for this to finish so it's clicked on my info and the verification is completed and you can see i have executed seven and seven are passed okay the seven is nothing but the test methods here basically so these are the three and these are the four so all the seven test methods are actually passed fine so this is how you need to pass the user information to the methods guys okay so now i have shown you only a single parameter right so i'm reading only a single parameter value like this so let's show you two values also so here i have credentials right so this is like more than one so let me use this one so let's create the parameters for that also parameter and first parameter is going to be username and the value is going to be admin let's close this one itself closing and next parameter is going to be password and what is the password the password is admin one two three so now i want to read these two values these two parameter values inside this method right this enter login details method how do i read those values so generally when you have a single value you are calling like this right so with double quotes first i need to mention the username so again if i want to pass another value i need to use comma symbol so generally in every i mean either it is array or either this is a collection or anywhere right so you will use the comma symbol to store multiple values right so here also i'm using the comma symbol and i'm passing password like this but here it is throwing the exception it says syntax error on token so why we are getting the exception here that is because whenever you have a single value it will be a normal single value only okay it is not like a collection of type or array of type so you have a single value so that is why you no need to enclose this one inside in any brackets so you can directly pass it like this but whenever you have multiple values you need to pass them in the array format basically so how the array will look like so array will have the curly brackets right so instead the curly brackets you will have the values so this username is one value and password is one value inside this array so you need to pass in the form of an array okay so that means you need to use the curly brackets so whenever you have more than one parameter then you need to use the curly brackets so now let me create the parameters here so how many number of parameters are using here the same number of parameters you need to create at the method level also guys because this value you need to capture in the method right so that is why username comma string password okay so let me replace this username and this one with password fine so let me execute this one more time so this time i will do one thing i will change the browser so that i can cover one more test also right so let me run this so this time it should open the browser as edge so you can see ms edge browser was successfully launched and it is executing the test cases so let's wait for the test cases to complete so the tests are completed so as a user i have changed the browser name from here and simply my tests are running fine right so i'm not going to touch my code here i'm not going to touch my code base so the code base is always freezed so i'm going to change the values from in this xml file only so as a user i'm going to change the values from the xml file here we have seen the suit level parameters right so let's see the test level parameters also so for that first let's remove this suit level parameter the browser and let's add that one in the test inside this other one also i need to provide the parameter here right so this time i will do one thing i will perform the cross browser testing that means i am going to open the first test in the chrome browser and the second test in the fire i mean edge browser or let's open this one in the firefox we did not open anything in the firefox till now right so let's open the first test in the firefox and open the second one in the edge browser so this time this parameter is having the scope to only this test and this one is also having the scope to only this test right that means this test is going to open the firefox browser and this one is going to open in the edge browser but whenever you are using the suit level parameter right so all the test cases present inside the suit are going to open with the same browser that you mentioned here right so let me execute this so this time firefox and edge should be opened not chrome so you see firefox browser is opened and the faster test is executing in the firefox browser the login tester and the my input test should be executed in the edge browser right firefox is closed and edge browser is open this time so this is how we have to work with the test level parameters guys so the concept is similar only i mean the concept for the suit level parameters and for the test level parameters it is same on the and the syntax and everything is going to be same only okay so nothing is going to change the only difference is that so if you mention any parameter at the suit level all the test cases inside that suit can access the suit level parameter so if you mention any parameter at the test level then only this test be able to access this parameter value so other test cannot access this value okay because this parameter scope is going to restricted to only this tester fine so there is one more scenario guys so first suppose what if i pass like this so i have one parameter at the suit level and i have some parameters at the test level also but unfortunately i am providing them same with same name okay so here in the suit level i am saying that open all the test cases in the chrome browser but in the test level i am saying that open this test at the firefox and open this one in the edge so in this kind of scenarios which one will have the highest priority so obviously test is going to have the highest priority why it is why it is like that that is because whenever the test is actually invoked first it will invoke all the parameters i mean all the suit level parameters then it will invoke this test level parameters so first suitable parameters are actually invoked then you are reading the testable parameters so obviously it is going to replace so the suit level parameter value is going to replaced by this test level parameter that means only this one is going to have the highest scope here so let me execute this so that you will understand so at the suit level i am saying open all the test cases in the chrome browser but in this test level i am saying the first one should be opened in the firefox and the second one should be opened in the edge but here you can see it is not opening the chrome browser it is opening in the firefox browser the first test is opening in the firefox browser right that means the suit level the test level parameters having the highest precedence fine and the second test is open in the edge browser so if i have any two parameters with the same name like this the suit level parameter and test level parameter with the same name then the test level parameter will have the highest precedence okay this will have the highest ranking you can say fine so this is how we have to read the values guys so this is how we have to read the values and one more thing i will show you guys so here you can actually read the data in the proper format also what exactly it is so here browser name is actually a text format right so as it is a text you need to read that one in the string so you can read every value in the string format or you can specify which type of value it is actually holding okay so i will add one thing here so i will give some thread.sleep so the thread dot sleep is going to be an integer value right so i don't need to provide but i'm just showing you guys so i'll say sleep time so by default i want to provide some three second sleep time here let's close this so i want to read that parameter here so i will show you in both the ways guys here first let's copy this parameter name let's replace here and first i'm going to read that value in the form of a string so i'll say sleep time right then the sleep time then i will use thread.sleep so here i need to provide the long value but i'm actually reading in the form of string right so let's convert that long dot value of string so what is that string sleep time so let's throw the exception also because i am using the thread dot sleep so if i use the super class of exception i don't need to provide the other one so like this i need to use right so let's execute this and let's see whether the 3000 is actually getting printed in the console or not so here what exactly i am trying to show you is you can directly read the specific format of data also without conversion you can directly read the specific format of data also so i'll show you i mean whenever i explain right you will understand easily so the test is completed here in the console you can see 3000 is already printed okay so the for the faster test case 3000 is printed and for the second also 3000 is printed but here i'm reading this value as a string right but this value is not actually a string so i'm internally again converting that value to long so why do i convert that value i mean for suppose here i have only one instance so the sleep time i am using only for one time here but for suppose if i have 10 occurrences like this in every occurrence i need to convert this value right so that is a waste of time right so instead of that you can directly provide the long value here i mean you can directly mention that this is this value whatever you are going to read that is a long value so in that case what you can do you don't need to perform the conversion here right so let me execute this i know this is not a great one but just learn this one also so you can see 3000 is printed in the console and the browser window is also closed right that means we are able to read that value 3000 value directly in the form of long so instead of reading that one into the string and again converting we are able to directly read that value into the long format itself so that is the thing i want to explain here so here we are directly reading the value in the form of long guys so that is about this video guys so now you understand the concept what exactly this parameter is and why we need to use the parameters and how to use the parameters and all so let's summarize one more time so the first thing is what is the use of testing parameters so the test engine parameters can be used to pass the values to the test methods i mean as a user i want to pass some information to the test methods so i need to use the test change parameters and next how to use the test ng parameters so we need to use the testing parameters that means we need to define the test engine parameters inside the test ngxml file so you can define the test engine parameters at the suit level as well as at the test level so if you define any parameter at the suit level that parameter scope is going to be limited to entire suit okay that means the parameter scope is going to be decided to the entire suit so inside the suit whatever the test cases are there all those test cases can access this parameter and if you define any parameter inside the test that scope of this parameter is going to be restricted to only this test that means you cannot access this parameter value outside of this tester fine and one more thing is if you have two parameters with the same name that is at the suit level and at this test level then the test level parameter is going to have the highest ranking okay so that is one more thing and one more thing is you can directly read the specific format of data also so if you feel this value is actually long you can directly read that value in the long format instead of reading that one the string format and converting that you can directly read that value in the long format itself so this is the concept guys so this is about the test ng parameters basically fine so i hope you understand this video if you like the video please hit the like button and also share this video with your friends and also don't forget to subscribe to the channel guys so thank you bye bye
Info
Channel: H Y R Tutorials
Views: 2,073
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 Framework for Selenium, parameters in testng, What is the use of TestNG parameters, How to use the TestNG parameters, parameters
Id: w7ObteNcxVA
Channel Id: undefined
Length: 26min 29sec (1589 seconds)
Published: Fri Aug 13 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.