Cross Browser Testing in Selenium Webdriver using TestNG Parameters

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello welcome you all to learn Automation calm this is Mukesh so in this tutorial we are going to cover cross browser testing in selenium so you might have heard of the sentence number of times and you must be confused how to achieve this in selenium so today we are going to discuss the same so before starting let us see the high-level agenda so today we'll see what is cross browser testing actually and how to achieve cross browser testing in selenium so this tool will have theoretical and we'll see how to execute test cases and multiple browser using test in G parameters and finally we will see how to check how to execute test cases in multiple browsers in parallel mode okay so in the third point we will see how to execute in multiple browsers but you will see it will run in a sequence manner but later on we will add one more feature so it will run all the test cases in parallel mode okay and finally we will check the reports how exactly the reports will look like if we are running a cross-browser testing so let us get started I will open eclipse and I am assuming everyone has installed two selenium if you are not installed you can refer my previous tutorial and you can install selenium so I will directly create a small program which will execute in multiple browsers so I will click on SRC and I will create package and I will say cross browsers I will click on finish and let me quickly create one program before move to the actual program in cross browser means now let us say you have one test case and that test case you are executing in particular browser so let's say you are executing on Firefox but if you want to execute the same test case in multiple browsers like chrome eye Safari Opera and so on right so in that case you don't have to write multiple test cases what you can do you can create a small test case or it will be your actual test case and with the help of testing G we will be running that test case in multiple browsers without any additional coding okay so we are going to do the same now I will create a small program world verify title since it's a separate concept so remaining code will be same so you can achieve later on what exactly functionality you want to do in your test case as of now I will be a verifying title so I will quickly create a small program and if you know how to write this program you can simply move to the next topic as of now I will create to verify page title this the actual test case name and I will write a program now it is a three line of code I will say webdriver and I will take this webdriver as a cool global variable today because we are going to use this in multiple test cases so I will say webdriver driver so this is my global variable and I will be using this variable inside this test case okay so here now we will creat a notation test okay and I will assist in G now you need to take parameters today okay now what exactly this parameter means so we will parameterize this test case so whatever parameters will pass based on that parameters it will execute my test case so in this program we are running our test cases multiple browsers so I will take one parameters and make sure this parameters you are taking from test ng package because the same parameters you will get R in testing in a J unit as well so make sure you are not taking from the different package takes from orz tortoise 10g daughter notations okay in this parameters you need to specify a value which value you will pass from your XML file let me put my phone on silent yeah so this browser will pass from over XML file so we will discuss about XML file so what I will do I will compare now and whatever browser I will get so I will say browser and make sure is I did a small mistake whatever browser you are taking from XML you need to accept into your test so I will say browser name okay so whatever parameters will pass from XML it will store in this variable called browser name so I will simply compare this every time if browser name dot equal ignore case so this is a predefined method in Java kill which you will compare the values so we will compare if the parameter which we are passing from XML is equal to Firefox then we will initiate Firefox browser so I will say Firefox driver okay then I will write else I will put else--if now if it is not equal to Firefox definitely it will go to else and again I am writing 1 if condition like if browsers name dot equal ignore K is equal to chrome so don't worry we'll pass these parameters from XML then you will get this exact meaning so just give me a couple of minutes let me write this program then we'll pass the same parameters from XML file and if it is equal to Chrome will initiate chrome driver and as we all know that for executing different browsers like Chrome I safari o para we need two eggs give the system variables write system property because by default cinema's kit comes with Firefox of a chrome I need to add one more line called system dot set property ok and here we need to specify webdriver dot chrome door driver and in the second argument I need to specify the path of this driver I am assuming you're familiar with how to execute a test case on Chrome if not then you can refer my blog there I explained how to execute test cases on Chrome but if you are already familiar so let me simply add this chrome one so I will go to selenium driver so this is the folder where I generally keep all my drivers so in C Drive I have one folder called rhenium driver and 1/2 capsule chrome driver and I travel servile so let me specify the path here and this make the small change use to backward slash same thing I will do for IES well if it is not equal to Firefox and Chrome then it will check one more time like else if one more time again I will check if browser and names dot equals ignore case equal to ie ok then I will say driver dot Internet Explorer driver and for IES well we need to specify the same so I will simply copy this I will do a small change in my program will be ready so in spite of I Chrome I will say ie and Here I am to specify the path fork ie driver so let me check here it's ie driver server ie driver server dot exe that's all this is what you need to make changes in your program and once you are done with this this is your if-else conditions close so now once your driver initialize you can perform your rectory like driver dot manage dot windows dot maximized ok and i will open my blog now you can open your application so i will simply open esta TP colon double slash www.learnsindhi.com and after this title i will simply close my browser so i will say to have a dot quit so this is what my test case does so it will simply accept parameter browser parameter this parameter will pass now so depends on the parameter if I am passing parameter Firefox it will execute Firefox browser and it will perform the remaining activity since it is matching with if conditions it will not go to else statement so it will not execute your chrome and ie so depends on your parameters it will do the complete activity so let's run this and before running make sure you are creating an XML file because we need to pass the parameter so I will simply right click on my Java program and I will say convert to test in G again you can see here by default location is coming my package sorry if my for project and the XML file is coming destined to dot XML you can change it so let me change to cross browser dot XML suet name it would be class test name and right now I'm not getting this parallel mode later on will change this so as of now you can click on finish and you can see I am getting one cross browser dot XML if you don't rename this it's okay it's perfectly okay it's totally up to you I generally rename this so that once I check my code I can see why what exactly this XML file is doing so you can see here I had created this XML so I am NOT getting class name so let me quickly add so you need to add class name equal to in double quotes you need to specify the class name followed by package so our package is cross browser so you can check from here our packages cross browsers inside this browser cross browser package I have a separate class called verify title so let me take the complete path and I will say cross browsers dot and I will take this class name okay so yes and yes close this don't forget to close this otherwise it will throw error now the main important point so if you run this program it will simply run but here if we need to pass some parameters so type parameter it's not giving parameter no so let us take this I will say parameter name equal to browser and I will specify the value here case you need to specify the name here use space and say value so value I will give Firefox and let me close this so I will use this forward slash okay and I closed so it is giving issue here it is giving some issue test name equal to test okay let's run this and we'll analyze the output whereby it is giving this error as of now you can skip this because we are not running parallel II and for test it is throwing maybe some nag issue we will see this so if you run this program let us see what is the output run this as test in G test it is throwing some nullpointerexception it looks like some Destin G issue tests name it should not throw let me remove this let me close this okay I got the issue we have not added that class this is a tag here okay so let's add classes and you need to close this classes here okay inside processes we can add so we were missing this classes tag so let me give some space which will be more readable format okay so inside classes we have specified this parameter let's make it on top let us say here okay so it will be applicable for all the classes so now you can see I have this XML ready inside this XML I am passing one parameter called browser and this browser the value which I am passing it should match with your program so if I am passing browser here you should accept the same here called browser if I am passing here some browsers name it should match with the browser's name here okay so let us run this program and still it is giving one more error here so let's see it is saying it should be terminated so we will terminate this classes tag yes now let us run this test enjoyed because you can see it's running our XML file which is available here and what exactly it will do it will simply pass this parameter to our test case and we are passing Firefox right so your program will come here it will check it will store all the value here and it will store in this browser name so as you can see it's executing so let me minimize this because it will run simply by verifying the title and it will match with Firefox it will execute this particular code and it will exist UT or Firefox try for remaining code will be same but our question is we need to execute the same test case in multiple browsers okay so you can see this output in the console we are getting the title and the one test case has been possible so this is for one now for cross browser what you can do copy this test suit paste one more time and paste one more time okay so let us change this value so I will say Chrome and I will say this ie so if you run this program what exactly we did we are passing the parameters in different different test suits so it will execute this test suits and since you are specifying Firefox the control will come here it will store Firefox here and it will check if browser name equal to Firefox here so it will execute this piece of code and it will start your Firefox driver and simply it will terminate your program so next time when your next program will run you can see the second test suit this is one test suit not will start with another test suit and now it this time it will check the values chrome so again your program will receive chrome in this browser named variable and it will verify so definitely it will not match with the Firefox it will simply come to the else block and here this time it will match with chrome so it will start Chrome browser and remaining code will be same in the same way it will execute your third test suits in this case we are giving values ie so whatever value we are giving it will simply match so if equal to ie it will execute this so now one important point here you can see here in XML I am giving value as ie okay you can see it is in small letters but here I am giving capital letters so it is perfectly okay because the method which we are talking it's equal ignore case so it will simply check the content not this case sensitivity okay so even if I giving small ie or capital I it doesn't matter if you use equals then only it will matter as of now we are using equal ignore case so it will simply check the content so now let's run this hope it's clear for all and ideally this program will fail the reason I will tell you so if you let me clear this right click on this run as the stingy suit okay and yes X and this the same as expected and it is giving this issue that two tests in the same suit cannot have the same name the reason is we have simply copy pasted okay so you can see this - suit name is test this test suit name is test and for this also we are giving tests so you should not have the same name so let me change this to Firefox test cases in the same way I will change this for all the test suits in this I will say chrome test suits or sorry chrome test cases and same I will make changes for ie test cases okay now it should run and you can see here I am NOT giving any parallel attributes so now it will run in a sequence mode it will execute your Firefox first then Chrome and then I so once you start executing parallely we need to add one more attribute called parallel so let me run this first and you can see started your XML file cross browser dot XML since Firefox comes by default with selenium so it takes five to six seconds sometimes takes 10 seconds depends on your machine so it will open Firefox now it will simply open my blog very it will print the title and close so let us wait my net speed is quite slow to reduce taking so much time to load my page in your case it will run perfectly depends on your net speed so once the page will load perfectly it will simply close this yes and now it has started Chrome so you can see on the console and you can see the chrome is running little bit faster because chrome and I is the third-party driver we are using so it's quite fast so in case of I you will see it will run very fast and in the console as well you can see it's running a chrome driver 2.15 we are using the latest version of this chrome driver so again now page has been loaded it will close this still loading yeah and now finally your eyebrows err so you can see it on console and I also it's very fast it's loading very faster and you can see this message as well this is the initial start page for the webdriver server so it will run ok now let me check this here it's running your IE and we are running with 64-bit and if you go through this particular you can say another console result of running suit so you can see it's running your iso it has not given the status but for firefox for chrome it has given and yes i else i also it has executed so now it is giving you complete info ok like what are the parameters we have passed so you can verify this so now it is running sequentially but our main intention anyways if you are not running parallel it's completely ok you can sorry you can write the code in this way but in case if you have requirement that you have to execute all the tests in parallel mode then you can say here pa rate double allele parallel equal to tests okay so what did what does it means so write note is running your test sequence syllabus this is complete then will it's running the second test case then though so if you say parallel equal to tests what it will do it will create a three threads one thread will be assigned for Firefox one thread will be assigned for chrome one thread will be assigned for IE so it will start executing parallel it doesn't matter which test case are getting pass or fail each thread will be running separately so let's run this and analyze the same output as of now I will clear this console same I will clear this for okay so now let us run this XML finally and you will see it will start parallely okay you can see chrome is started I started running very fast so let me show you you can see this you can see Firefox is little lazy should still not appeared so chrome is appearing your ie appeared and now Firefox came so all test cases are running parallel you can see here and let's wait okay it will run your chrome completed it has closed I completed it closed so last one is your Firefox it will close this as well yes it's all done and you can see now console it's printing and all the test cases has been passed and this is the another way of checking your parameters the light for this particular suit we are passing Chrome for this particular test should we are passing IE and for this we are passing Firefox in the same way you can try in your application and it's very easy only need to specify these parameters in your test cases and the same parameter you need to specify in your XML file okay let me check the agenda whether we have code all the topics or not yes so what is cross-browser testing how to achieve this how to execute test cases in multiple browser and how to ICU test cases in multi browser in parallel more so finally if you want to check reports as well so let's refresh our project okay you will get this test output and if you open any of this report so let me open a Mabel report thank you so you can see here we are passing one parameter only so for this chrome test cases we are passing Chrome as one parameter for ie we are passing IE and for Firefox Firefox so right now in this example I have shown how to pass single parameter but you are not restricted to only one parameters you can pass multiple parameter based on your requirement so generally what we do in our organization we pass URL username password and browser okay so in the same way you can customize based on a requirement so in the next video I will show you how to pass multiple parameters and how to catch the multiple parameters in your test cases so hope you like this video okay and in case any doubt you can contact me my email id is Mukesh shoot 1.50 at the red gmail.com and in case if you liked this video please share with your friends subscribe to my channel for the future updates thanks for watching this video have a nice day this is Mukesh bye bye
Info
Channel: Mukesh otwani
Views: 138,117
Rating: 4.897233 out of 5
Keywords: Web Browser (Software Genre), Software (Industry), Selenium (Software), Testng, Java (Programming Language), Computer Science (Field Of Study), Software Testing (Industry)
Id: z3Ruc2bKnqI
Channel Id: undefined
Length: 24min 30sec (1470 seconds)
Published: Wed Jun 03 2015
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.