Automatically manage the different browser driver download & env setup

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello all welcome back so in our selenium series today we are going to see a new library that is supporting some functionalities and that is called as webdriver manager so what exactly this webdriver manager does and why it is helpful for us to know and implement in our framework that is what i am going to discuss today now what is web driver manager so it's a selenium java library or a dependency i would say which helps us to automatically manage the browser drivers and also it is helping us to set up the environment variable as well now what exactly this does what is the problem with our existing without using this particular library those things i will be showing you guys so let's first move into our code base and here you can see uh so in our previous session we have already seen a kind of a get started guide with the framework right where we have set up the driver initialization and then sharing the driver object so today i'm going to show what is the issue with having this system.set property this line okay so let me do one thing let me first run this particular test so as you can see the test was working fine right in our previous session when we were seeing now i didn't change a single line of code as well in this particular framework but why exactly this is failing the reason if you see if you go to the uh the exception it is a session not created exception it means that the driver is not yet initialized the reason is that could not start a new session because of the some server error and that issue is the version of the chrome driver only supports the chrome browser version 92. see we all know right to run our selenium test we need the browser drivers that's how the selenium is communicating with the browsers so the browser which i did actually couple of days back while creating this framework it was 92 so that is the reason this particular chrome driver if you go to this base test you see this chrome driver this was working fine but in the duration within this couple of days my browser chrome browser got updated to 94. how do you see let me show you that so if you come here you go to this and then you go to the help and about and you can see it is the 94 version but before it was 92 so in a normal scenario what i have to do so i have to go back to this particular screen or maybe in google and i will say that chrome driver download i will say because i want to get the latest version right so for the 94 i need to get this one i need to click on this so that it will download my 94 version of the driver here based on whether it is mac or windows you will be extracting that and put it under this particular location actually so that the system.set property what exactly this does so this is basically setting your environmental variables so when you say this key value pair so that selenium goes whenever you are saying driver dot new chrome driver selenium basically looks for this particular key webdriver.chrome.driver that's how it is getting the path actually path and then it is what you call performing your operation now this is the problem actually when your chrome browser is updating it's just a chrome right now tomorrow let's say that your edge driver or firefox driver all these browsers are keep on updating right i mean if you see these browsers normally in a month at least once they will be updating because of some security patch or some issues now at that moment and when you're running your selenium test cases in your ci cd pipelines you will be getting uh failures right in your test case and this is not problem with your project or the way you are coding this is problem with your setup or the configurations that you are doing now that's where actually your web driver manager is coming into the picture now what exactly this webdriver manager does so let me just show you the documentation first so and then the github link actually so let's first go to the github link so if you see this is the github link this is a person bonnie who is a contributor to the selenium as well so he came out with a web driver manager library now what it does i will be letting you know in a moment but uh so the recent version is 5.0.3 you can see now whenever you are coming to this particular github you can see on the right hand side some releases now based on these things you will come to know what is the latest version of this particular release and what are the major benefits or major changes so that you need to update in your test case okay so now if you see there are two major things so there are a couple of things that they have changed to the way so if some of you might have even come to know about this web driver manager before right so where you can download your so let me first show you the documentation so this is what actually he maintained one nice documentation so i don't need to maintain anything i can just go over the main points that you need so that it can make you more interest and you can go back and include in your framework as well so the first thing is that webdriver manager it's a downloader i would say that now what else it is doing that's what i'm going to show you guys so you can see it is the driver which is a mediator between your test script and then the browser so whenever you are sending any kind of request this browser driver understands your code base whether it is java or c-sharp or javascript anything now it converts into an understandable language that the browser can understand and it performs the action and revert you back with the response in a high level actually this is the concept so as you can see there are actually four main uh steps that this webdriver manager does so before going to the first line in detail let me first get back to the installation and how do you really set up into your what you call framework so the first thing we need to get the webdriver manager 5.0.3 this is the maven dependency that we need as you can see this is the latest version so i'll just copy here and then paste it here and you guys know right how to install this one i can skip the test you can see if you're using uh your intellij as a as your editor you to install any of the dependencies you need to click on this thunder which is skipping your test cases you can see skip your running test cases so that existing test cases will not run when i say install so let me quickly install this one probably it will install quickly because i already installed this one as you can see uh it's all saying that everything is good now after that as always let me go back to this right click go to the maven and reload my project so that this dependency will be uploaded to my or it is loading to my particular project how do i see that i already told to you guys before so you have to go to the particular library so that is actually io dot github you can see io.github okay so this is the way you can verify that the dependency is downloaded or not now it's very so till now so far whatever this sessions 40 or 50 videos that we have seen we did not really come to this particular what you call libraries right but this made me so much interest to get into this how exactly he is doing that is what i'm going to show you guys so first thing is that first let me go back to the documentation so here if you go to the algorithm or the way he is doing so first thing what it is telling it is getting the browser version what kind of version and it is telling that commands database now if you go to this particular so this is again another project right libraries are nothing but it is just a project only or just a program they created a jar file and given to you guys to use it now we can extract this jar file in fact we can see all the files whatever it is there inside this so here you can see commands dot properties file so this is where actually he is getting to know what kind of version you have now let's say that chrome i'm taking a simple scenario and that is applicable for all browsers that's how the all the browsers have designed so to get the chrome let's say that i'm using windows now for windows if you go to this particular screen or this particular command you will come to know what what version of the chrome browser is installed you can see it is just taking the program files whether it is 32-bit or 64-bit and everything and it is getting the chrome chrome inside that application and chrome dot exe and they're executing one command actually so this command is get version so it will give you the version at this moment i have 94 right which i have shown in the help about so that's how he is getting the particular version of your system and this is an over overview and then if you want to go in detail you have to get into individual you have to search in google to see how can i get this command to achieve this one so that you will get in detail okay so the first thing is that he is executing certain commands to get the browser version now the next thing what he is doing next thing is that he is after getting the browser version he's finding the proper driver version okay this is again interesting right now based on your browser driver version browser version is first searching into the browser driver actually and that is into the versions database now what is this versions database so this is nothing but versions dot properties so he's keep on updating all the versions of the browser drivers actually you can see for chrome 94 you will see 94 point this one now this one you can see even here if you go to this for 94 for 94 browser what is it it is exactly 4606 61 right the same thing if you go to the code base you will get to know you see like this actually he is matching actually those things and every time one new chrome browser version is coming is keep on adding this particular file okay so that is how one thing is doing so this is the way the second one and you can see it is not just limited to chrome firefox and then opera key value pads simple properties file only is using now the third thing what is doing let's see that once the driver version is discovered means he got the driver version what is it by matching that browser version then what he is doing he is saying that he is downloading that browser actually browser driver okay like as i was doing manually right i just clicked on this and it downloaded but in reality we cannot do you can see what it is happening so if i copy this link address let me paste it here okay you can see what is this combination you can see till here it is correct okay till here it is constant only you can see till here it is constant the next thing what is doing is getting your browser version in your system what is the browser version based on that he is getting what has to be the exact version of the driver actually by using this versions dot properties file you can see he is he is getting this one okay now by taking this particular browser driver version he's building this url okay after that what he's doing this is an executable url see if i enter this one it downloads it goes to here and then if i click it will just download that that's how is doing that and now if i go to here you can see the url got changed here like for an instance let me copy link address and let me go here and you can see after this when i'm only setting this one i'm getting this one if i build this one to chrome driver win32 then it is coming this link now i can enter this one and then it downloads now this is what he is doing by using by using some kind of http get call actually this is a api call he is doing by building this url let me show you that into the code base so if i am correct let me just get into this one so there is something called as a web driver actually uh give me a moment i think under this you can see there is something called as a cl download actually inside this download what is doing forget about all these things let me show you this one so this webdrivermanager.class has a download method this download in turn calls another download method actually but this download method is not in this where it is it is inside the downloader now let me go back to this implementation so if i go to this implementation you can see here this is again going into another method actually here so first it is checking whether it is already there in our system or not if it is not there you can see if it is not present what is not present the browser driver then it is going to this so it is again another method it is calling now where it will check now it is checking your local path actually target file where it is so it is basically in here so if you see the documentation it is inside your cache selenium now if i copy this one this particular path and let me go to the spotlight and here and if i search this one you can see this is my local path actually it is already set in the program whenever you are installing this library and you can see under this chrome driver because i'm using max see now getting this mac or windows it's easy actually by by using java you can get os dot arc and then you will get it whether it is mac or windows or even 32 bit or 64 bit as well after this it is getting this particular version from where it is getting it is getting from that properties file and then it is creating a folder structure inside this a chrome driver okay if i delete this one then your else statement will be executing else means this if condition will be true actually you can see driver dot is present if i'm deleting that one then this if condition will become true then it will go to this one actually so drive this download dot and extract let me go to this one what it does now you can see it is getting a url actually what is this url this url is nothing but this one what i have shown right just now so they're building this url by first they see this is very much strict right this url is fixed for chrome browser okay and i can show you that as well so if you go to this web driver manager properties you can see this url is fixed actually here now they keep on appending appending what actually whether it is a chrome browser or firefox browser whether it is mac or windows whether it is which kind of version so all these three criterias they are getting into this code they are kind of extracting from your system information and they are building this url which in turn they're sending to this particular url after that you can see here they are getting a http client this is again one of the javas api library actually by using that they are doing a get call you can see create http get call after that once they as soon as they will do this get call it will download that file as a response it will download that file which they are keeping it inside a temporary file let me just go to this let's see where exactly the temporary file is there yeah so you here you can see target file there again moving to a another file actually now what is this file this file is nothing but your cache selenium that path which i was shown in my directory right that is what they are saving it once they do this one after that what they are doing there so let me just show you so download and extract is done let me come back to here so this is done actually now where they are using this one so after that they're exporting actually so if you see here the third one the third one is done right they are setting up that url once that url is set up they are just doing a get call only after that what they are doing they are exporting this one to your and java system properties we were doing system.set property right that is what they are doing automatically once see now let me go back to here to make more understand see to do this one what we are doing before writing this line we are downloading that now system dot set property of this key value pair they are doing in an export actually so now that export method is inside this only you here you can see export driver they are taking this one and using your system.set property what is variable name variable name is nothing but your that webdriver.chrome.driver now value is nothing but the path of that particular chrome browser so here they are sending it from the export driver simple concepts now i'm not making a big like the detailed line by line that would be like taking along but i'm saying the exact four or five steps what we are doing manually they are doing it for us actually it's a very simple but very effective way of what you call automating this process actually for sure actually the time how much i spent i got to know this much but yeah depending on your interest you can go inside and try to get to know what and all different concepts they are using to perform this operation let's now utilize their library so here what i'm going to do what are the different steps i need to do for sure now i'm not going to use this particular line of code instead of that what i'm going to do i will use web driver manager you can import now you can see from where it is coming io.github.bonnie garcia who is the owner or author of this particular library or who created this one now they are saying if you go to this github see i'm not doing my own actually i'm reading all the setup configuration whatever he is telling and i'm following him and here you can see this line of code for chrome if you are using chrome so you can just use it that's it now till setup if you are doing all those four steps which i explained right everything is done in this actually this particular line of code now you're just using the same way i don't want to now again i don't want to do all these manual steps what i'm going to do i'll do like this but in this case i will save firefox for each of the browser actually they have created a classes and from where you can use these methods actually and then they have pretty much he has been provided all browsers that we are using for automation testing and we can use this particular line of code okay so at this moment because my framework i have only kept chrome or firefox that's why i mentioned but yeah you are free to use any kind of browser that they are providing you fine so we have written this line of code now let's try to install and at this moment what i'm going to do i'll explicitly i will delete this one okay now at this moment let's see what it is doing now i don't need to do any change now you can see this is just one line of code you need to do no worries about your browser version no worries about what kind of driver you have downloaded where exactly you have kept everything we shouldn't be worrying about that now at this moment i'll go to my test case and i'll right click and run this one it is now executing my test cases properly but before it wasn't executing right now there are certain things that i need to tell it's not just doing this much actually some people are using some older version of the libraries in the sense like in real time what it is happening see for practice i can use any kind of rc version beta version or anything but in real time when you are executing your test cases into a specific environment means in your ec2 instances or in your docker you might not updating your chrome browser or your framework all these things as and when it is available into the market so normally in real time what we do we first create our own sample project whenever we are getting latest version of these libraries we do it in our locally actually to make sure that these things are working fine or not if it is working then only we are updating but by the time we are testing all these things your test cases i mean if you update it at that moment then it is a problem right now what you are doing actually by that time so now for an example let's say that now the chrome browser is 94 latest is in my real-time project i might be using 92 only so what you can do explicitly you can specify to the web driver manager okay latest is 94 but you download this particular version of the browser only okay for an instance let's say that i want to install or download the 92 version of the chrome browser though i have 94 even you can do that so let me show you that so what you need to do here so you will see first thing is that you need to specify what kind of browser that is based on this method now here if you put dot here dot you can see there are a lot of different methods they are using here okay one thing is that a browser version so here what you can do you can specify you can see it is asking the string accepting a string what is your browser version let's say that i want to utilize 92 so you just need to specify 92 that's it now when you do this one what it does it won't download the latest version of the uh browser driver actually so it will go to this particular version 92 and it will compare into the versions dot properties file what exactly the version number and then by taking that it will build that url and download that particular file for you or the browser driver now this is one good concept if you are sticking to a particular browser actually or if you are using multiple browsers now another way is there dot chrome driver okay dot and you will see something driver version actually let's see here you can see driver version means you can specify the driver version instead of the browser version you can specify the driver version but you have to make sure that the exact driver version what you want to download for an instance if i go to this one let's say that you want to install this 93 so what you can do you can copy paste this one and then you can come back here and then you can specify this one that's it you just need to do this much only okay so what it does it won't worry about what kind of browser version is there because you have explicitly mentioned that what browser it is to download it is doing this one okay so that is one of the way it is just giving you a flexibility to use to download the drivers in multiple way situations okay but i always stick to the this particular thing because uh my real-time project or i'm not worrying about multiple browser versions and anything so what it is even though you are what you call you are restricting your chrome browser to to have a specific version this chrome driver dot setup does the same thing because it first checks your browser version right so you don't need to worry about that but still i'm just giving you these two lines of code in case you need certain situations where you want to explicitly download a particular version so then also you can use this particular line of code okay so at this moment i have limited myself to have chrome and firefox but yeah you can try safari actually doesn't need any driver so you shouldn't be worrying about that because it downloads default actually along with your safari browser but yeah any other things edge driver opera and all those things you can just keep adding this effects conditions and you can practice it make sure that that particular browser is installed in your machine okay so hope this particular session is helpful and you got an idea about this particular library okay so stay tuned we will be seeing some more interesting topics how to build a framework how to make it more flexible so stay tuned and do subscribe to this youtube channel and share with your friends thank you for watching
Info
Channel: qavbox
Views: 133
Rating: undefined out of 5
Keywords:
Id: i7S_p-vVcFk
Channel Id: undefined
Length: 25min 16sec (1516 seconds)
Published: Tue Sep 28 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.