2. Selenium Grid 4 using Docker- Hub & Node Setup with Docker Compose

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
[Music] foreign [Music] this is the second video of our selenium grid for using Docker Series in the first video we have discussed about basics of selenium grade 4 architecture diagram of selenium grade 4 what are the various setups that are involved in selenium grade 4 and then we performed a demo using selenium grid for Standalone setup and with the help of docker today we are going to see how we can how we can use Hub and node setup using the docker so if you are watching this second video directly I will highly recommend you to go through the first video to get the basics of selenium grade 4 and we have discussed about these commands as well that we are going to discuss now so to start with it for hubby node for the very first time we will be needing a Docker Network so we need to create a Docker Network then we will set up a like in this particular command Docker network is being created then here a hub is being set up and this network is being used here after the Hub has been set up using this particular command which we have discussed in our previous video as well then we are setting up the three nodes and these uh notes if you see like this one is the Chrome node the first one and then we have the edge node and then we have the Firefox node and we have discussed about what is the concept about publisher and subscribers so event bus is being used for handling the inter communication between Hub and nodes and the various components which are there within the selenium grade 4 settings so like this is compulsory to publish And subscribe to these events and these are the ports that these nodes are being subscribed into and Publishing it so same port if you see four four four two four four four four three in all of these three nodes okay and this is the shared memory of 2GB like the host memory will be shared with these nodes and we are setting up at the 2GB and this thing as well we have discussed in our previous video so now the main thing here is like once you will execute these commands you will see that your grid will be up with the three nodes let us do that so first I'll open the command prompt so for me the network is already created so I I will get some error just let me check as well if the network is present or not okay so the network is already there so I can directly use the second command so here we are using the selenium Hub image for setting up the selenium grid hub so for me I the image is already downloaded in my system so setup was quick for me but for the very first time it can take some time so let us make sure whether our container is up so here we can see the container is up so the next thing is to use now these commands for setting up setting up the nodes so let me check I guess I will not be able to copy this so I have already placed it in my notepad let me go there and I'll paste it from there so this is our Chrome node then similarly we'll set up Edge node again it can take some time for you if you are downloading the image for the very first time okay we are all done here let us check the containers so we have four containers up and running and for checking the setup of our Hub and node we can just directly go to this particular IP 4444 as we are doing it on one machine so we will just check at the localhost level so what we have here we have Firefox with the maximum concurrency of 5 as with maximum concurrency of 1 and chrome with maximum concurrency of one so how did we got this five so if you see the command that I have used here I have specially specifically mentioned here that my Firefox node can have maximum five sessions so at a time if there are threads available we can have five sessions uh running at the same time for Firefox but for asgen Chrome there will be just single session because we haven't included any uh assassin specific to these particular nodes so by default this will be taking just one session so now let us demo this thing so for this what I have done in the IntelliJ and the test ng.xml level I have included three tests one using Edge the other using Chrome and the third one using Firefox so this is our Chrome one Firefox one and the S1 right so we are using the same test that we have created in our first part of this particular tutorial the only change is there like now we are passing the browser parameter from our destiny.xml file so for each test we we have different browser and that we are using in our thread before test and this is being used for in sliding the driver and if we go here within our this particular method which is in driver manager class so here first of all we are reading our environmental variable which are being passed from command line in case of remote execution we are passing it as remote in case of local we are passing it as local so as we are discussing about Docker so let us focus on the remote one only so we are going to use this one and as the environmental variable is the remote then this particular flow will come into the picture and the browser value will be passed in here now from here we are just inside initializing the remote web driver we are passing our URL of the Hub and then we are getting the remote browser capabilities as per the browser that we have passed so using switch case here in case of Firefox we are using Firefox Firefox options and then in case of chrome chrome option and in case of Edge Edge options so this is the basic setup so what we can do now is let us try to execute it and we'll also follow our grid link to see how the things are working so we need to keep an eye on the Assassins here like we have as of now zero assassins and here we can track the Assassins as well so we shall see one session for Chrome one four Firefox and one for Edge let us go here so see Chrome has started there is one session for Chrome and as this is sequential run because we haven't used in our test NG the parallel execution so this test will be triggered one by one so let us see once the Chrome one so we have the session here and here you have the the quotes as well let me refresh this yeah so you can see there is a one Chrome session and if you click here you need not to go to some particular URL you can just click on this particular video to see uh video icon to see how the things are working just okay the execution was completed we didn't get the proper time to see it but we'll try to do the same thing in our next rest execution which will be for now the Firefox is coming into the picture so in some time we will have a record here and the default password for every session that will be created here is secret all in lower case so let me do it and I click there s e c r e t Secret connected successfully so you can see the execution is happening here so execution is completed we can go okay the control is automatically came here so we have seen one session from chrome one for Firefox and now the session 4 Edge will also be here we can go to overview succession has started it will take some time to be here you will be able to see the concurrency and record count getting incremented here you can see and then this is the video icon click on secret enter the password as Secret just to show you and click on accept and here your execution is completed and flow automatically comes here and here you can see three test cases has passed so now let us try to execute the these test cases in parallel as well and for parallel execution we just need to mention here at the suit level parallel equal to test and thread count equal to let us take a thread count of five and we'll have five test cases what we can do is we can repeat our Firefox related test case again you will need to change the test name otherwise our there will be a error in the destiny side and then let us do the same thing for this particular test as well and here we will have Chrome 2. now we have five test and we have taken the thread count of five now the main concept here is we need to keep an eye on what are the concurrent session maximum concurrence as under node can have so Firefox can have 5 Edge can have one Chrome can have one so even when we have like passed here the thread count of two uh threat count of five and we have two tests uh for Chrome at a time only one Chrome test can be executed so let us see this in demo as well uh for that I think we also selling uh increase our time here so that we can observe the test execution in parallel so what I'll do I'll have a static weight here in form of thread.sleep and let's have a sleep time of 20 seconds and we can use sneaky throws from lombok to avoid try catch okay and we are all set so we can see the Assassins have started here and if you go to sessions as of now the Chrome uh the browser windows wouldn't have opened that's why we are not seeing any assassins here but initialization of sessions here you can see it occurred parallelly as you can see session one here session one here and session one here in case of a case of our sequential run um like one first one of the session got completed then the second comes into the picture and then the third now here we can see uh like there is a concurrency of 14 so once uh out of seven one session has started why it is sync 7 because uh our Firefox can have five sessions at the same time where Edge and chrome can have just one session at a time so here we will also see like though we have taken two tests for Chrome two for fire folks uh one four Edge so and we have we have also kept a thread count of five but our Chrome execution will not happen in the parallel because for Chrome we have taken the Assassin count as one only our Firefox execution it can start in parallel because uh there we have the concurrency of five so here you can see both the Firefox Essence I have started at the same time but the Chrome one will start once this particular session is completed so if we go here we can just keep an eye on this particular session and see okay I think that particular assassin got completed so that's why we were not able to log in there and now we will have our Chrome session as well you can see test is being executed and that's it here you can see like how five sessions got executed now the next thing would be like till now we executed our Docker commands one by one right idly uh like this will not be a feasible thing to do because if you have multiple nodes you sell not try to you know execute those commands one by one so there is a concept in Docker known as Docker compose like where you create a yaml file you include every uh every like node that you want to configure within that particular ml file basically it is a Docker concept to run multiple images at the same time in the ml file will keep our node um segregated at the service level and like one service is equivalent to uh one container that you want to execute right let me show you a quick Glimpse from the site from the selenium grid 4 site what it is saying that it is the simplest way to start a grid use the link resources below and save them locally and check results so let me open this one so this particular file I have tried um and there was some changes required from my site to execute the Hub node configuration so I'll I'll discuss about that change as well so the first step is again we need to create the network uh that will not be part of toker compose and Docker compose what we are starting is we are starting our all the containers like this is our the very first one is our if you see here uh it depends on selenium Hub and the image name is Chrome so this is our Chrome related node and each container that you want to execute is acting as one single service then you have your Edge service and after this you have your Firefox service and each of this service will depend upon selenium Hub service which you have defined here okay so the first this will set up and then these will come into the picture now the changes that I had to made is like the network that I had created I had to put that Network within each of these services like I created one network a grid by executing the same command which we executed previously then we like in yaml file we need to Define our Network and then once this is defined you can use it in your services by using this networks so I have defined this in every service and then I was able to use it now after doing this instead of executing all of these commands one by one that we executed previously we just need to execute our of course Network creation command and then we can just use this command to so once we execute this command all the containers which are within our yaml file local compose ml file those will be up and running so the uh like this particular command will take care of everything every container which is defined in our Docker compose so let me give you a brief demo for this so what I'll do I'm going to stop my containers from Docker desktop or for that matter I can also delete them let me delete them all so here I'm removing the containers the images are still there so our execution will not take that much time right so what I'm going to do now is we are within the project only so I am going to use this command now oh I think uh for my case the file name is different yeah so I haven't used any hyphen so I just changed my command name and as I just change my command as per my file name and once I do up I can see all the containers are created back if you see here just do a refresh so it is showing you it has four processes running in between it so let us wait for some time so here you can see started selenium hub right so this message started selenium Hub here node has been added node has been added three nodes has been added here right and here we can just see all of these in this way like if you see uh it has all the four services uh running in between it like the docker compose file so what we can do now is now we can go back to our URL here and we can just check whether we have the same setup as we had earlier we have the maximum concurrency of five here one here and one here so the remaining execution will remain the same what we can do quickly is like to demo this part because previously if say you need to increase the Assassins you would have executed these commands again and again but now you just need to change make change in this particular file and you are all set so what I'm going to do is I'm going to say I need these sessions for I say for Chrome I need two sessions for Edge I need three session and four five folks I'll keep that as five and now I save this file I go here to terminate the docker compose command you need to press Ctrl c as soon as you process press Ctrl C you will see all the containers will get stopped and you can check the status from Docker PS command as well or you can come here and you can see the status is exited and if you say do docker push down so all of these containers will be removed as well so here you can see there is no container you can try dockerps as well you will not see anything and now if we do Docker compose up we shall see the Assassins that we have mentioned right in our Docker compose file so again we need to wait for our nodes to get added to the herb and herbs to get started so we can track these through these messages as well so started selenium node sending registration event node has been added node has been added so let us quickly check here so here you can see at Edge level we have a concurrency of 3 a chrome at two and five Folks at five okay so this is how Docker compose file works we have reduced the number of commands to one single command and then we can include this in our CI CD pipelines and once the docker is established we can trigger our test cases right so this was it for today's video guys and in case you're liking the content that I'm making please do like and subscribe and share it with your Q friends thank you [Music] foreign [Music]
Info
Channel: Test Automation with Atul Sharma
Views: 1,466
Rating: undefined out of 5
Keywords: Selenium Grid, Selenium Grid 4, Selenium with Docker, Docker, Docker compose, Selenium Grid with Docker Compose, Hub and Node in Docker
Id: 5Iaa7lpyCGo
Channel Id: undefined
Length: 24min 23sec (1463 seconds)
Published: Sun Jul 30 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.