Docker Selenium Grid - Full Tutorial for Test Automation | Setup Docker Selenium Grid from Scratch

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello uh my name is AJ and welcome to my channel so as a part of this series we are going to see a very important Concept in automation testing uh that is selenium G with the docker so I'm going to cover some basic idea about the selenium grid what exactly it is what are the advantages of selenium grid why you use it and we also required some uh basic knowledge about the docker okay so I'll be covering some important concept about the docker so doesn't matter if you are at a beginner level watching this video you are going to understand everything from this series okay so once you understand syum G what EXA it is what is docker then we are going to practically implement this selenium grid architecture with the help of Docker okay so we are going to set up our selenium grid with the docker practically and once it is done we are going to run our selenium test cases on this grid whatever selenium grid architecture we have created with the docker we will be running our multiple selenium test cases on that grid so we'll be running in a parallel on different browsers Chrome Firefox age we will see how we can run the test case one by one or we can run the test cases simultaneously in parallel mode also and at the end we will see how we can figure how we can set up this selenium grid architecture with the help of Docker compos ml file okay so let's get started so first thing we we are going to see is what is selenium grid so let's see some basic idea about the selenium grid so selenium grid is the selenium component which allows you to run your test cases on the remote machine so we normally create web driver reference right web driver driver equal to new Chrome driver right for Chrome browser so that test case you are running on your local machine right but what if I want to run my test cases on some remote machine in real time in the company we have 100 500 thousands of test cases so what we want uh we want to reduce the test case execution time so for that purpose what we do whatever 100 test case we have so let me show you this through the pain for better understanding so let's say I have 100 test cases so if I run all these 100 test case on a single machine on your local machine let's say it takes around 3 hours okay it takes 3 hours so what if if there is some configuration I can do some setting I can do so that I can run all these 100 test cases within 10 or 20 minutes my ultimate goal is to reduce the test test case execution time and I will get the result as soon as possible and I can work on the bugs whatever bugs we will get by running this test cases we will get more time to fix it and more time to test it okay so our ultimate goal is to run all this 100 test case within less time as possible okay maybe 20 15 minutes half hour right so normally it is going to take three hours so what I'm going to do I will have some configuration I will uh create some setup so that I can run all this 100 test case on the different machine at the same time in parallel mode right so there will be different machines connected uh in that setup and they will run uh 100 test case means I will distribute some of this test case to one machine so one machine is going to run 10 then another machine is going to run the 10 test cases right likewise I can divide this 100 test case so whatever result I was getting in 3 hours I'm going to get it within the 15 minutes right so isn't that amazing by by doing this kind of setup we are reducing our test case execution time to 10% only so whatever 3 hours it is going to take it will directly reduce to the 15 or 20 minutes right so that is the main advantage why we use this selenium grid concept selenium grid so it will allow you to run your selenium test case on the remote machine in parallel mode so we can run our test case on the different browsers as well right in testing we need to test our application on different browsers different OS right so there can be our windows so we run our test case or application on Windows machine then we can have Linux also we can use the ubu right we can run our test case on the Mac and we will have some different browsers like we want to run the test case on the Chrome then we will use the Firefox so then age like there are different browsers on which we can perform the testing right and manual testing also we used to perform on different o different platform different browsers a safari and all these browsers right so in automation also what if I will have some setup with the help of the selum grid so that whatever test case I have in my project I can run on all these browsers simultaneously in parallel mode and I will get the result as early as possible so so that whatever issues I will find I will get more time to fix it in a development and I will get more time to test it again right that is the main advantage of this selum GED it reduces the test case execution time by running the test case on the different platform different browser simultaneously right so now next thing is to see how the selenium grid is allowing uh the conect connecting this multiple remote machines and running some test cases in parallel what exactly there in the grid okay so let me show you that so this is the basic architecture of the selenium grid so in selenium grid what we have we will have a hub okay so this is you can consider as a machine or or host machine which will act as a hub okay so this Hub is going to accept all my selenium test case request so what I will do I will provide my 100 test case to this Hub now Hub is not going to run our test case Okay Hub is just a host machine consider it as a server and it will have some client machines connected okay so this is my one machine this is my second virtual machine okay so consider this Machin as a virtual machine as of now okay so these machines are connected to this Hub okay there can be different Machin so one machine you can consider this this machine is running some Chrome so consider this machine is running let's say windows then browser is running is Chrome then I will have a second virtual machine running same let's say ubu I'm going to run test on Firebox okay then it will it can be your Mac machine okay so you can connect any kind of machine okay any platform machine and you can have different browsers okay whatever browsers you want to run the test case you need to install that browser on that virtual machine so these machines are called as nodes okay so you can also called it call them as client also so this is my Hub or you can say it as a host and these machines are called as clients okay so these are the clients so you can have multiple nodes connected to this common Hub okay common host okay so you can have this multiple machines so all these machines are connected to the common host okay so they are ready to serve this host so whatever request uh this host will send it will perform the exactly same work whatever host is asking okay so what I will do I will provide my 100 test case to this Hub okay and according to the request type like I send the request that I want to run my test case on the Chrome so this Hub will send that request to this machine node one and this node one will perform your testing on the opening the Chrome browser then second request I want to run on the Firefox it will run on the Firefox then Safari and then KB test case we are running on the multiple browsers at the same time Chrome multiple CHR at the same time multiple Firefox at the same time okay so uh consider in this architecture we have let's say I have created five machines running Chrome browser okay so we have five Chrome machines then we have five Firefox and five Microsoft age browser okay so what will Hub will do Hub have 100 T to run okay so H what we do Hub will provide five test case five test case to be run on Chrome it will send to this five nodes running five Chrome then it will send other five test case to this Firefox then it can uh send other five test case to this age browser that means at the same time 15 test case are running in the parallel mode so test case execution time when you are running on the local a single machine which is around 3 hours is reduced to again half hour let's say only half hour you got the result so all the 100 test sces got executed within the half hour right so this is the biggest advantage of the using the serium grid it reduces the test execution time by running uh your test case in parallel on different machines at the same time on the different browsers okay so how you create this Hub and node architecture is completely up to you you can use the physical machines to connect to each other or you can use the virtual machines also okay so main uh Advantage we have here is by running our test cases on the different machine in parallel mode so you can have physical machine or you can have virtual machine but in terms of virtual physical machine it's going to cost you a lot right or physical machine so we use the virtual machine so creating this Hub and node architecture selum GD architecture with the help of virtual machine is also not a cost effective okay that much cost effect it is it is going to cost you a lot so that's why we come to this concept Docker concept okay so what is Docker so let me give you an basic idea about the docker and then you will understand why most of the companies are nowadays they are using uh the docker containers for creating this Hub and node architecture sing grid architecture for running the test case in parall so Docker is an open source platform or technology by which we can develop test ship or deploy our application as a containers okay so by using the docker we can devop any application and we can ship that application into a container and we can deploy that anywhere okay so main advantage of Docker and why we use Docker is let's say in a software company we developer create the application in the de environment right okay they perform some unit testing after completing some functionality or feature then they provide that application and deploy that application to the QA environment let's say so this is my de environment okay the environment and this is my QA environment okay so QA will perform testing in this QA environment so these environments are different right so there is always a fight between development and keyway that some feature or functionality which is working in the development machine so developers environment which is not working in the QA environment okay so normally this fight happens so this scenario is very common between developer and QA so by using the docker we completely remove this scenario we completely remove this fight between developer and Q environment so using the docker containers what developers are going to do is they will create the application that they will develop the application and whatever files code files or supporting configuration files there will be some jar files required dependencies right so whatever files are required they they will keep all the libraries files so all the things to run the application and run that feature will be available in this form of container okay so all the things are there so what developer will do once application is done development is done same container will be provided to the testing team right so same container is there for the testing purpose so whatever supporting libraries uh supporting configuration files required to run that application or run that feature are there in this uh cont coner okay so same container or Docker Stacks will be given for the testing team to perform the testing so testing can be performed the same Docker stack okay so you can consider this uh containers as a virtual machine as of now okay so this is nothing but a container so virtual machine and container only uh the big difference between these two is virtual machines have the OS running okay so they will have their own OS but these containers will not have any OS okay they will share the host machine resources that can be your OS that can be your RAM hard space so coner will not have their own operating system okay so o is not available here and they are going to consume the memory or Ram is whatever required from the host machine only okay so another big advantage of the docker containers as compared to Virtual machines are uh these containers are very lightweight you can create and run these containers whenever you are required uh with the help of very simple Docker commands Okay so in case of virtual machines you need to do all the setup configuration on the virtual machines whatever software applications you require you need to install it it will going to take the time and whenever we require in virtual machine you need to uh start that machine okay so that starting time for the virtual machine is very high as compared to Docker container and once our work is done we need to shut that virtual machine so whenever you require that virtual machine again you need to start that machine again it is going to take the time okay so that process is time consuming and complex as well so in case of Docker container whenever we require any container we can very very quickly we can create the container and take it up and when our work is done we can take that container down very easily okay so this process is very fast in case of Docker container that is the important Advantage by by using this Docker container so in casee of application development as well there can be multi containers okay one container running your website one container the product services or different Services required to run that application okay so this can be a multicontainer application and you can very much easily take this containers up uh you can uh very easily link this container to each other so that it will uh works properly AS application and whenever you are required you can uh you just have to use the doer compos file where you can mention whatever Services you are required uh in which container you need to run that services in which container you need to run the website and you are going to link this containers to each other what on also you can mention the ports and volumes required so everything can be done in a single Docker compos file and your application will be run up within L time okay in case of application development but in automation testing we require these containers for the testing purpose we will require to create the Hub these nodes and we will run our test case on these containers okay so coming back to our Point how Docker is going to help us for creating this CM grid architecture Hub and node architecture effectively so with the help of Docker what you have to do you just have to inst the docker in the system and top of that Docker or Docker engine we will be able to create multiple containers okay so for this selenium Hub we will create and Docker container so this will be our one Docker container okay so this is our selenium Hub selenium Hub and this is our container number one container one so this is our one container and same for creating these nodes we can create multiple containers so this is my container number two okay so this container will be running Chrome browser so this is my Docker container okay this is my Docker container 2 then I will create another container running Firefox browser then another container running Mac or Safari browser another container running another Chrome browser okay so I can create multiple containers with the help of the docker okay so you can create multiple number of containers here so all these are our containers which will be connected to a single host or single Hub right so this is my selenium Hub which will accept the test case request okay and it is going to forward this request depending upon the browser type okay so it will whatever test case you want to run on the browsers Chrome browsers it will send to the Chrome running containers okay so let's say these containers are running Chrome it will send the request to the Chrome then for Firefox we can have a multiple containers so it will send that request to this containers running for Firefox browser for H will have some different containers so all these test case are going to run in a parallel mode okay and our test case execution will be completed in very less time as compared to the running uh web driver on the single machine right so let's start with our session number two in this selum grid Docker Series so in this session we are going to set up our selum grid by using Docker practically so in last session we have seen some theoretical part about the selum grid what exactly it is why it is useful in the automation testing and we have seen why Docker plays a very important role in this selenium grid architecture okay so let's start so this is a basic architecture of a selum grid configuration where we will have a selenium Hub okay this one and we will have some nodes connected to this quamon hub okay so these are our nodes so as we are going to use the docker for creating this s grid architecture each component in this architecture will be a Docker container so this Hub machine will be a Docker container and I will expose any port for external connectivities so that we can run our selenium test cases on multiple browser simultaneously using this structure so I will expose let's say port number 4445 for the selenium Hub okay and these nodes will be also my red Docker container so I will create create separate container for each node so this is my Docker container to and we are going to see what exactly happening on this browser using VNC by using VNC application we will be able to connect to this each node okay and we will be able to see what exactly happening on the browser how our test cases are running so here you can expose any available Port so here I will let's say port number 4446 okay so VNC service always run on this port number 590 okay so if you want to see what happening on these particular noes on the browsers we need to expose Port so it will keep listening to the same port 59 so we are going to expose this 4446 so for each and every node I will be required to create a Docker container okay so similar to this Docker container 2 and we have exposed this port we will create a Docker container three and we will export some Port 4447 and for this machine we will expose 4448 okay so for every component in this architecture we will have to create the docker container so once these Docker containers are ready we need to link them to each other okay this means that means we need to link this nodes node containers to this Hub container so that they will be able to communicate each other okay so this will be a b directional flow created once you link to the hub and whenever you give any test case to this Hub Hub will check whatever node available as for the browser type and it will just forward that request to that particular node and that node will execute our test case on that particular browser and that's why we need to link this together okay and another important point is while linking uh you need to make sure that all these containers should be run in the same network okay it is a different network then you won't be able to Linkin okay so all these containers should be in the same network that is very important point point should be in same network right then only we will be able to create a bidirectional flow between these nodes and hub if they are on the different network we won't be able to link them and we won't be able to run our test case because we need to link these nodes to this single Hub okay common Hub so if they are in different network we won't be able to link these nodes to this common Hub okay so you need to make sure they are running in the same network that I will show you so let's go and see how we can create this Docker selum grid by using the simple Docker commands so let me start the power okay so before you start running the docker command you need to make sure that you have Docker installed your system okay so that you can check using this Docker conv verion okay that means I have Docker install on my system so if it is not install your system what you have to do is just go to this Dockers docs. do.com and there you will find this install Docker desktop on Windows okay so this Docker desktop is just an application which will provide you the UI to start any container the container or delete the containers okay so it is very user friendly so you just have to install this on your system so just click on this link and it will download and exe file and complete the installation so before you start running the docker commands in the windows Powershell what you have to do you need to start that Docker desktop once it is installed so once you start this Docker desktop application it will look like this okay so it will contain different things here containers images volumes so if you see this green that means Docker is running okay so now we can run our different Docker commands Okay and just we have seen that we need to create the docker container for each and every component so Docker containers are created from the docker images okay so if you want to create a Docker container you requir a corresponding Docker image for that so if you want to create a container for the selenium Hub we will require the selenium Hub image okay so from that selenium Hub image we will be able to create this selenium Hub container okay so it is required to pull the image selenium Hub Image First and we will require the images for this node browsers also okay so let's go step wise so first step is to pull images okay so this is your first step so we required images for s Hub then node Chrome debug then another is node Firefox debu and this is the node Opera okay so currently I do not find the debug image for this node Opera but you will find the debu image for both Chrome and Firebox so using this image we will be able to create container and once you expose any port and we will connect through the VNC we will be able to see what exactly happening on this chrome and Firefox so let's go and pull this four images okay so let me show you how we can pull the images so for that purpose you just have to go to this hub. do.com so here this is an report where all the images available publicly okay so you can uh download any image from this so just click on this explore and in this search you just have to type what image you want So currently I want selenium Hub image okay so if I search this you will find okay this is from the selenium you just have to click it and they have given the instruction that how we are going to pull this image by using this Docker command so this is very simple Docker command Docker then pull and what we are going to pull I want to pull this image so this is the image name okay so we just have to copy this image go to windows power shell and we will taste here okay so once you press enter it will download The selum Hub image so as I have already downloaded all these images it will show you the status that images up to date for this selenium Hub latest so this latest is nothing but a tag so every image will have some tag associated with them okay there will be different versions so this tag represent the uh different versions if you want a particular version of the image you just have to mention it here so we have not mentioned any tag here that's why it has taken the latest by default so it will pull the latest image so where this image will be available if you open the docker desktop application if you go to this images so in this tab you will find all the images I have downloaded so I have selenium Hub then selenium node Chrome debug then node age Firefox debug all these images I have already pulled okay so what we have done now is we have pulled this selum image so what we have done is we just use this command so for node Chrome debu you just have to use the same command you just have to use this image name so I to pull this image so instead of Hub I will write like this and similarly for Firefox as well so for pulling all these images you just have to run this Docker commands Okay so let me show you one of it so let's see I already downloaded it but let's run it again right so it is going to use the by default lest tag so it will check if this image is available locally or not if it is available then it will show you the status that it is up to date and if it is not there then it will go to that Hub repository and it will pull that image corresponding image okay so you just have to uh run these commands in your case so once you got all these four images on your local machine next step is to start the network first okay so as I said we need to have all these uh containers running in the same network so that we will be able to link them to each other okay so here you need to start a network okay so for that uh purpose we need to run this command Docker Network create and here you can provide the network name so I will provide like grid Network let's say G network so this is my network name so same name I need to use while running uh creating these containers okay so this is going to our second command we just run this in power Shale okay so this is the ID so our network is ready so next step is to start these containers so this is the thir step create and run the containers and the containers and Link them so first let's start the container for our selenium Hub so what we have to do is for that purpose you just have to use this command so this is for Hub Docker hypon d means it will run in background then hypon P that I'm going to expose any port for external connectivity so we have seen that we are going to expose 4445 so 4445 by default Port is 4444 okay then uh Network so here you need to provide the in which network you need to start the container so we just created this grid Network so you have to give this same name here then happen happen name so what should be your this container name so I will give name as my selenium uh Hub okay so this is my uh container name then which image you are going to use okay so container are created from the image that we have seen so which image we are going to create for this selenium Hub container so I'm going to use this image so this image is already available on my local machine so if it is not then it will check the locally first it is available or not and if it is not available it will go and download the corresponding image from the docker Hub okay so you can directly run this command also if you don't want to pull this images separately you can directly run this command and it will go and pull this image first and then it will start the container out of it on this and it will start running on this 444 Pi Okay so so everything can be done in this single command but we are going to stepwise just in beginner level we should not use the shortcuts you need to understand this concept so first you need to pull the images okay make them available locally and then we will start our containers so this is for the selenium Hub and I think I miss the important part here Docker run okay so you to the docker run and it is going to run the container out of this selenium Hub image so let's run this command now okay so this is the container ID that is generated and uh if you go to the Local Host so we have Expos this port port number 4445 so just go to your browser Local Host 4445 you'll be able to see that grade is up and running at this port okay and if you want to see the console just click on this and here you will be able to see all the nodes connected to this common Hub So currently we do not have any node container link to this Hub that's why is blank okay so let's go and create our node containers so for creating the node containers you have to use similar kind of command so this is for node for node you have to use the same Docker run open d means it will run in background P so here I'm going to expose any port so I am going to expose 4446 for Chrome node okay so the port I to expose is 590 here the VNC service always run so this is the 59 VNC Service Port mapped to 4446 so that will able to see what are happening on that Chrome browser while connecting to the VNC and here I need to run this node containers in the same network as that of Hub okay so selenium Hub is running in this network so I need to run all the node containers in the same network so grid Network okay so here I will provide some name so this should be my container name so let's say Chrome node and image from which I need to run this container is this image selenium node Chrome debug we just copy that here okay so if you run this command it will just start the container the Chrome node container so it will not link to this selenium Hub okay so for linking this note to this selenium Hub container we need to provide the environment here so after Network I will provide some environment environment uh here is the hubor host so which host container you need to link this container the node container you just have to provide the name of that container so this is my Hub container name selenium Hub so equal to this so what this command will do Docker run it will run in background and this port will be export for external connectivity so that we will be able to see in the vmc and this is the same network as that of the Hub and we have given here the Hub host equal to selenium Hub that means this node Chrome container will be linked to this selenium Hub okay so that we will be able to run our test case because selenium is not going to run any test case it will just forward the request to the corresponding noes whatever available so we have linked this selenium uh Chrome node to this selenium Hub and the name of the container should be Chrome node and what image we going to use for creating this chrome node container is this node Chrome debug so this image is already available locally right we already downloaded it but Docker will always check if it is available or not locally and if it is not available it will go to the docker Hub and pull that image so now let's go and run this command this is our second command for Chrome node okay so container has created and this is the container ID and same you can see in the browser now if you refresh the page so you can see one node running the Chrome browser has been linked to this uh selenium Hub running at 4445 okay so you can see the browser details configuration details also browser time out and all these things okay so these are the default capabilities set for the browsers okay so we will see more in detail uh later so currently we just have to link our containers we need to create the node containers and link to this common Hub so our Chrome node is ready so let's go and create our other containers for the other nodes so same command you need to use for Firefox so Firefox you need to use the same we will just change the name so this is my Firefox Firefox node this is should be my node name and what image I'm going to use is node Firefox debug so from this image our Firefox node will be created and we just have to change the port also so Firefox should start at this 4447 okay so at 4445 we have selenium hub at 4446 we have one of the node the Chrome node and at 4447 we have the Firefox node so this Firefox container will be created and it will be linked to the common Hub Hub house equal to selenium Hub okay in the same grid Network okay so you need to remember these two points so let's run this as well okay so within a few seconds we got this container up and running and this is the container ID and if you go and check in the browser now we have this another container uh running and link to this selenium Hub okay so this is our Firefox browser this is our Chrome and let's start the third one as well so some small changes I will change the port 4448 then I should start in the same grid Network same selenium Hub and I will give the node name as Opera Opera node and what image we are going to use is Opera node Opera D Opa okay so this should start our third container okay so let's go and see the console now okay so you can see now we have the Opera driver also here okay so now we can able to run our test case on this multiple browser simultaneously in parallel mode okay so all these node containers are linked to the common Hub that what we want so this is the grid architecture the basic architecture and we have configured this selum grid architecture using the docker containers using the very simple Docker commands so these Docker commands are very easy to remember okay and if you want to see all these containers are running or not that you can see in the docker desktop application so just go to this containers Tab and here you will be able to see this selenium Hub this is my container name running at 4445 this is Chrome node running at 4446 uh Firefox node container 4447 and Opera node at 4448 so all these are the running containers you will be able to see the status also okay they are up and running so using this uh buttons you'll be able to stop the container or you can restart it or delete it for each and every running containers okay so this is the UI provided by this Docker desktop application and through the command if you want to see what are the containers or what are the services are running you just have to use this command Docker PS means running services and e means all the all the services which are running or not running so you'll be able to see that okay so you will be able to see this is the container ID node Opera so you can see here 271c is my Opera node Opera container so same container ID is here the image name that we are used for creating this container is selenium node Opera this is the command and created 2 minutes ago and it is up and running from 2 minutes and this is the port we have exposed 4448 Opera node this is the container names Opera node Firefox node Chrome node and selenium Hub so here first we just created the selenium Hub and then we created this node containers and we link this node containers to this common Hub in the same network and that's why we are able to see in this console also so if they are not in the same network you won't be a to see this structure here you'll be able to create the container that will be up and running but you won't be able to link this containers to this selenium Hub if it is not in the same network okay so you just have to use this command for creating this structure first pull the images and then start the network so give this network name and same network name you need to use while creating these containers okay so very simple and whatever Port you need to use you can provide the number here and here one more thing I want to show you that if you don't want to provide user defined Port here to expose uh you can ask Docker to run or expose any port available okay so you just have to make a small change in our Command so let's create another Chrome node with that command so here what we have to do is instead of this what we will do we will just have to give here capital P so what this command will do is it will open uh create an container with the name equal to let's say Chrome node 2 in the same network and link to this common Hub selenium Hub and it is going to expose any port available so we have not provided any particular port number here so we have given the capital P here so whatever Port available at that time it is going to expose okay so let me run this also and we will see okay so name should be different because we have already created a one container with chrome node so I have changed the name and here is the capital P so another container has been created and that is linkhub so now if you check the services do PS space i a now we will be able to see Docker has Expos this port 49153 so this is the port was available at the time so Docker itself exposed this port and we can use this port number while connecting this node through the VNC okay and for other nodes we need to use this port number 4448 for Opera for Firefox we will use 4447 and for Chrome first node we will use 4446 in the VNC app and if you refresh the page now we will have two nodes okay two nodes with the Chrome browsers and I can show you through the VNC also let me open the vncr so all you have to do is just download and install this VNC from the Google it is very simple and once you open it you just have to type the IP here the machine you want to connect to so our IP will be the local machine IP so 127 do 0.0 dot 1 and here we need to give the port number you want to connect to so let's connect to this first node the second Chrome node so it IP is 49153 49153 okay if you hit enter it will ask for the password also so yes here you just have to the secret secret in lower case okay and click on okay so this is the container running this is the Linux container running our Chrome browser so when we run our test case you will be able to see that browser is opening and whatever test scenario you are testing that will be able to see visibly here okay so that will help you in the debugging process also so this is our Chrome node 2 and if you want to connect to other nodes so other nodes are 4448 op node 4447 Firefox so you can easily connect to those also so just have to change the number here so 44 46 continue again here you need to do the secret okay so this is our second right we have two windows now and the third one we will open 444 7 so these windows will show you what exactly happening inside that container uh what are the actions that we are performing on the browsers on the application you'll be able to see all those here so I think uh that is all for this session we have created our own selenium grid architecture by using the docker containers by using simple Docker commands and let me create some sample test cases so that we will be able to run those test cases parall on these different noes that we have created so I will create few sample test cases and that we will run in the next session so this is the third session in the selum grid with Docker series and in this third session we are going to see how you can run selenium test cases in parallel mode on the selenium Grid in the docker so so we have set up our selenium Grid in Docker in last session so we have created the docker containers for the selenium hub using this command okay and we have created the node containers for Chrome Firefox and Opera using these Docker commands so we have published some port for external connectivity so 4446 for Chrome then 4447 for the Firefox and for Opera we have published this 4448 so when we run our test case we will be able to see what happening on that browser okay so this is already done in the last session and if you check on the browser our all the containers are up and running okay and same we can check with the docker command Docker PS all the running services so you'll be able to see all these containers are created six or 7 minutes ago and they are up and running okay everything is here and also in the desktop application you'll be able to see all the status of the containers okay so one more important point so normally when our work is done for this all the containers and Dockers we close this application right so once you close this application whatever running services or whatever running containers are there that will be taken down automatically okay so all the running services will be taken down for desktop application and if you want to use these containers all these containers will be in an existed State okay so all you have to do is you just have to start this containers you don't require to create containers again you just have to start it okay so let me uh show you that so I will just quit this do desktop so you can do it from here so Docker is stopped now and if you check this grid conso you won't be able to see anything here because services are not running right now on this port number okay so you can see this message so now I'm going to start the doer desktop application again okay it is starting the docker engine now so within a few second it will be started okay so now you can see in the containers all these containers are taken down automatically and the status is exited so all you have to do is you just have to start this containers again from this menu okay so that you will be able to use this containers for running our selenium test cases so you can start this containers from this uh Docker desktop UI okay just you have to click on this start button and within a second it will be started okay so this selenium Hub is up and running so if you check here the grid console so now you can see that selenium Hub is up and running so now you just have to start the node containers as well okay so you can start from here and let me show you through the docker commands also you can start the containers so starting or stopping any running container it is very easy from this Docker desktop application but you should know from the commands as well so how we start the container using Docker commands uh first let's see what are the services are running so oh sorry it is ster PS Ty a okay so you can see only Hub is running and all other containers services are down so to start this containers you just have to use this command dock or start and you just have to give the container ID okay so if I want to start this container node Chrome debug so I have to give this container ID so you can give only initials because this containers IDE are unique one okay so if I give F7 only it will start this container okay y someone is up and running now so if I refresh here so you can see that node running this Chrome browser is up and uh if you want and if you want all the containers should start in a single command so rather than starting one after another you can use this command Docker start your dollar here in the bracket you just have to use this Docker PS hypon a hypon hypon Q and bracket close so this command will bring all the running or all the services and this command is going to start the services again okay so whatever Services which are running it will restarted and the containers which are in exited state will be started okay so you can use this single command so you hit the enter so in the single command all the containers will be up okay so this is starting one after another so all containers are up now s and other four node containers so let me refresh the page so yeah so you can see that all the node contenders are up and they are link to this common Hub at 4445 and same we can see in the docker desktop okay all are in running State now so now coming back to our point that we need to run our selenium test cases in parallel mode on this uh Chrome browser then Firefox Opera okay so test case execution should start simultaneously on all these browsers so let me show you the test cases that we are going to run so I have created four test okay so let me help you to understand that so these are very simple so we are going to use the test NG for running our test case and and I have created four atate test methods so first one is Google on Chrome test so in this first test case what we are going to do is we are going to go to this google.com and using test and assertion we are going to assert the page title so we will get the title using this D.G title and this is the expected title value okay so if these two matches then our test case will pass and if it doesn't matches then it will show you the uh this message in the console and our test case will be failed okay so this is very simple test case and before closing browser just we need to see in the VNC if it is working working fine or not I have given the thread do sleep of 8 second so you need to add this code in the try and cash block so that exception will be cached in this and that exception we will be able to see in the console okay so in this second test case we will go to this uh linkedin.com and then again we are going to assert the title of the page okay and in third test case we are going to perform the same action only we will go to the gmail.com and then we will Acer the title okay and last test case we have the Facebook and there also we are going to do the same for demonstration purpose I just created this sample very simple test case okay so I have this four atate test method and I have one atate before test method okay so whatever code available in this atate before test method is going to execute first before it start the execution of adate test method so before each and every adate test method this code is going to execute so this is just in setup method and here I'm going to check what browser I want to run the test case right so before we open any page we need to open the browser so in the setup method only I'm going to decide that so how you are going to decide in this setup method that what is the browser and which browser I need to open okay how you are going to send the values to this method so for that purpose you just have to use this atate parameters annotation from the test NG so this value we are going to send from the test.xml file so that value I will send from the test XML it will be cached here and same value will be given to this setup method here browser type so if I send Chrome from the test XML that will be cached here and then we just have to check the browser type now if this browser type equal to Chrome that means I need to run my test case on the Chrome so I will set the capabilities as capabilities. set browser browser type. Chrome Okay so using this capability selum will come to understand that this test case has to be run on the Chrome so it will forward that request to the Chrome node okay so whatever node available at that time which is running the Chrome browser it will send this test case request to that particular node okay so this is for the Chrome so if I send the Firebox from the test gxml then that will be cast here so that value will be compared in this block so it is false then it will come here browser type equal Firefox okay right so then here we will set the capabilities for the Firefox browser so you have to use the same here browser type. Firefox and for Opera it will not execute this first two blocks it will execute this final else block so capabilities. set browser name browser type. Opera blink okay so this is the capability for the Opera and after setting the browser capability we are just printing the statement that test case execution started on and here we are going to print the browser type means if test case execution is started on the Chrome it will show you that test case execution started on the Chrome for Firefox it will show test case execution started on the Firefox so from console itself you will be able to understand our test case is rning on what browser okay so this is for the at theate before test method so before we start our test case ucation we need to open the browser and first we need to check which browser we need to open so that's why we have to add this code in the ad the before test method so once our browser is confirmed in this setup method then this ad test case methods execution will be started so all this test case will be executed and once test case execution is done I have used this at theate after test annotation in from the test NG and here we are just going to print that test case execution ended so once our test case execution is done we just have to close that browser so I have added this. TW in the at the rate after test annotation because it is going to run after each and every atate test case execution so now let's understand that which test case I'm going to run on what browser how I'm going to decide it that this Google on Chrome test should run on Chrome browser then second test should run on Firefox or third test on the Opera how I'm going to do that so all this configuration all this setting you can do through the test NG XML file okay so let me show you the test XML now so in this test in XML I have created four test so this is the test one then I have test number two then I have test three and then test four so we have this four test in this test and the XML file that we want to run and in each test I have used this parameter the browser parameter okay so how you are going to use this parameter you just have to use the parameter name so that is the browser and what should be its value you just have to pass from here okay so this parameter name we have used in the atate before test okay just I have shown you that this before test method is going to use this parameter so whatever value I'm going to send from here for this parameter will be catched here and that same value will be catched in this setup method okay so this is how you can send any parameter any value from the test NG XML to the test NG methods in the test case so we have sent the browser we want to open now we need to decide which test Cas you want to run on this Chrome browser so that you need to do from this class okay so classes then class so class I'm going to run is the test. doer selenium grid test so this is my class name and from this class I want to run this test method so all you have to do is add this methods tag and inside methods you need to use this include include name equal to and name of the method you want to run so this is the method name Google on Chrome test okay so this test case I want to run Okay Google on Chrome test so as a part of this test one I want to run this Google on Chrome test on the Chrome browser then for second test I want to run on that Firefox browser and which test case I want to run as a part of this test two that is LinkedIn on Firefox test okay so that means second test case I want to run on the Firefox and in the same way you can configure for the other test for test three we will open the Opera and this test case should be run on Opera and for the last test test four again we will open the Chrome browser and this test case should run on that Chrome browser Facebook on Chrome test okay so you can see that we have four nodes we have two Chrome nodes and one Firefox and Opera so we can run all these four test cases simultaneously now we have four noes and we can run this in parallel so how we are going to run this in parallel so until now we have decided that which browser should open and which test case you want to run on that particular browser okay using this test and methods and parameters tag so now we need to decide how we are going to run this test in parallel okay so that configuration you can do at the suit levels so what is suit in test NG suit is just an collection of the multiple test so we have four test here right so this suit will represent this collection of this four test so you can provide the suit name here we can say like grid grid suit so this grid suit have four test Cas to run right we have four test case to run so now how to decide this how we are going to run this four test case we can run in the sequential man one after another or you can run in the parallel mode also or you can run two test case at a time then again two are done again two test case next time like that so that can be decided using this parallel value okay so for this parallel it is going to help you how you are going to run this test cases if you want to run in sequential manner you can give here methods okay so all the methods will be run one after another or if you want to run all this test case in parallel just set this value to test so by doing this we are telling test that whatever test cases available in this grid suit I want to run all those test cases in parallel so please run in parallel mode so if you have the node available for Chrome Firefox Opera please run the test case in parallel and next thing is thread. count so if you want to run the parallel mode you just have to increase this count so all the four test case will be executed in parallel on these different browsers so until now we have decided about the browser which test case we want to run on that particular browser and the parallel mode also but want to run this test case on the selum grid running at 4445 not on my local machine right I want to run it on the doer s that we have configured so I want to run on this uh browsers on the docker containers so to run our selenium test case on the selenium Grid in the docker containers we just have to point our test case to the selenium Hub okay so we just have to give our test case to the serum Hub and then Hub will decide whatever node is available depending upon the browser type it is going to run our test case on that particular node running that particular browser okay so first important thing is we need to point our test Cas to the selenium Hub running at this 444 Pi so how we are going to do there so same you need to do in the ad before test right so before opening any browser we need to decide where we want to run our test case so we want to run our testc on remote driver right not on the uh local driver local Chrome driver or Firefox driver so it should be a remote web driver so for that purpose once our browser type is decided okay so I want to run on the Chrome then at the end what we are going to do is we are going to create the web driver reference so driver equal to new remote web driver so we need to use this remote web driver class and in the bracket you just have to give the URL new url url object sdtp colon Local Host 4445 WD Hub so that means our selenium grade is raining on the local machine at 4 4 445 so this is the URL you to give Local Host 4445 WD Hub so in case if you are running on some remote machine using Amazon instance or any any remote machine you just have to give the IP of that machine and then upend this WD and hub at the end so by doing this we are just forwarding our selenium test case to this selenium Grid or selenium Hub running at this 4445 okay and next parameter you need to give in this wee web D is capabilities okay so we have set the capability for the browser type so you need to provide that as a argument and depending upon this capability type means browser type selenium Hub is going to decide that which node I want to send this or forward thism TS request to so browser is Chrome it will forward the request to the Chrome then if it is fir Fox it will forward the request to the node running the Firefox browser and for Opera it will send for the Opera node okay so I hope this is clear so everything is done now I hope you have understood how you have created the test case and how you have done the configuration so just keep in mind if you want to run your s test case on the different browsers right so usually we run our test on the different browser so same application we want to run on the Firefox MOA Opera Safari right it is scenario so for that purpose you need to use the parameterization so we are using this atate parameters annotation that means we are doing the parameterization through the XML file so this is just any way how we can do the parameterization there are different ways by which we can do the parameterization so we can run our test case using the different parameters using the uh let's say data provider is there then we can run through the me one also so for those I will create a separate sessions how we can run using the data provider or running a test case in parallel mode on this Docker grid using the May one so I will create a separate session on that so as of now we are sending this par using the test n XML file and using this parameter value we are going to decide the browser type okay this is the browser capability and depending upon the browser type selum is going to decide which node you need to Pro that request okay so let me open the VNC as well to monitor the test case execution okay so last session we already connected to this selum grid node with this VNC so we just have to open it again so this is the 4446 that means this is our Chrome node at 44 47 we have Firefox and for this this is the another Chrome node okay so let's go and start our execution so as we are going to use this parallel equal to test our test case are going to run in parallel mode so just right click on that run as sng suit okay so you can see all these test case are running this is the Firefox this is the second Chrome node and this is the first Chrome node so all this execution are starting in parallel mode and we are able to monitor it using this VNC even you can interact with these browsers also okay so I can click here or I can close the browser manually so I can manually interact with it also so that is the use of pncr okay so all test case execution is done so just only we do not have the op Deb mode that's why we could not see in the v view but you can see that test extion started on Firefox Opa the Chrome and second Chrome simultaneously okay so execution started simultaneously and once it is done it has ended that means our test case has passed all the titles are correct right so what we are asserting is just an title of the page so all the titles are correct and that's why you got the pass result and same you can see in the result of the test suit here also you will see all the test case are executed so let us run one more time uh this time we will see from the G console so once test case execution started all these notes will be in a b State okay so after refresh you can see this is in uh running some session right so some test case are running so if you send some more test case to these nodes uh this test case request going to wait for test case execution to be completed on this particular notes okay so once test case EX is done on this noes then this next test case execution will start so our test case is running on op Al you can see that so I think okay so all are free now so all the nodes are free now and if we check the result all are passed so this is how you can use the test and XML file for configuring all these test cases and running all these test case in a parallel mode okay using this parallel property and this thread count equal to four so let me show you how the T case will executed in sequential manner so for that purpose you just have to set this parallel equal to methods so if you run first it will execute this uh Chrome test on the Chrome browser then on the Firefox then then Opera will start and then second Chrome test so let's go and see that as well and once test case execution started only one test case is running at a time so it has open the Chrome browser so next next test case has to wait until this test completed so Firefox will will start now and this is the second Chrome node so after Firefox it will run the Opera test case and after that this test case will run the last test case 4 on this chrome second node okay so fir Fox test case execution is done now Opa will be completed and then this chrome will start okay so you can see that this is the test case number four facebook.com so this is how you can run the test case in sequential manner just set par equal to methods and running test case in paraller you just have to set this parallel equal to tests so another scenario can be what if I want to run the same test on the different browser simultaneously that means I want to perform login scenario on the Chrome Mozilla and Opera simultaneously right that is a normal scenario so for that purpose you just have to do some changes here so for Chrome we are running this goog on Chrome test that is correct for Firefox also I'm going to set the method name equal to this Google on Chrome test and for Opera browser also we are going to run the same test case so by doing this what will happen test will see okay this is the test method I want to run so on the Chrome it will run the same test case on the Firefox also same method and for op also the same method and we have set this parallel equal to test that means all three browsers will execute this test Google on Chrome test simultaneously okay so let's see this scenario also I will just uh just don't want to run this test now okay so at 4446 we have no running Chrome browser and at 4447 we have the Firefox so both the test has started simultaneously you can see that so this is the google.com and some issues there on the Chrome okay so you can see both the test case are running in parallel on Chrome Firefox and here you can see I guess is also busy okay so this is how you can run the same method same test case on the multiple browsers and multaneously in parallel mode so you just have to configure the same method name in each and every test case Okay so very simple so in this session number four in the selum grid with Docker series we are going to see how we can set up the selum grid with Docker using Windows badge file okay so in last session we have run our selenium test cases in parallel mode on the selum grid that we created in the second session in the docker so for creating selum Grid in the docker basically we just have to create the containers for each and every component of the selenium grid so for selenium Hub we need to create a separate container and for different browser node we created the separate containers okay so for creating this Docker containers we just ran this few simple Docker commands so there can be a problem that where when you type this command in the power shell there can be problem that you miss any important part or there or you did some spelling mistake while writing the command Okay so this can happen when you are running multiple Docker commands Okay one after another so instead of that what we'll do there is another way by which you can run these Docker commands Through the Windows badge file so what we will do we will add all these Docker commands in the windows batch file and then we will run this batch file for creating this a Docker containers okay so let me show you that so what we have to do is just create a new text file here and just add all the commands in this file so first step is we need to create the network right so we just have to write this command here and then we need to create and run the container for this selenium Hub so this is the command the next command and then once selum Hub is ready we just have to create the node containers for Chrome Firefox and Opera so just copy this Docker commands and paste in this text file okay so we are going to run the six commands so here we don't require to write the pool commands for this S hub image and chrome node image all these okay so we are directly writing this Docker run command so basically Docker is going to check if this image is available locally or not if that image is not available locally then it is going to download that corresponding image from the docker Hub okay so you don't need to write the separate command for fing the images so we will create the docker Network and then we will create the docker container for the senum Hub and then we will create and Link the docker containers for the node browsers to this common selum Hub and we are publishing the same port as that of second session okay so all that I have done is only copied this Docker command that we ran in the second session for creating the S Grid in the docker okay so we run this command one after another in that session but here we have just added all those commands that we need to run in the this text file and you have to save this file as a b so while saving this file you can save it any folder and you can do any name here let's say create selenium grid okay so this is my file name and extension you need to add as bat okay and select here all files b means Windows batch file and save that file so now all I have to do is we just have to run that batch file okay so go to that folder where you have save this batch file that is in my Docker folder so this is the batch file we created so you just have to run this badge file so just open command prom from this location okay and you just have to type the file name here okay so are going to run this selenium create selenium grid badge file so if you hit enter all the docker commands will be run one after another so first it will create the docker uh Network then inside that Network we have created the container for selenium Hub and all these are the node containers for the browsers okay so you can see that all these Docker commands ran one after another in sequential manner so by doing this you don't require to write this commands manually every time run from the power Shale okay so just collect all the commands you want to run and add those in the text file and save that file as a Windows batch file okay and then with the help of command prompt you can run that batch file so within a few seconds our cium grid architecture is ready on the docker so all the containers have been created and they are up and running so that you can verify using this Docker PS hypen a so you can see all these five blocker containers the selenium Hub and this node containers for the browsers are up and running so from the browser if you see our selenium Hub is up and running and these are the four nodes connected to that common Hub Okay so can directly run your test case from the eclipse Now using this TPI so if you are watching this session uh directly I will suggest go and watch previous two sessions uh you will understand how we created this configuration selum configuration and how we designed this test case to run in parallel okay so you just have to use this test NG XL file and if you run this file all the four test case means in this XML I have four test cases so all these four test case are going to run on different browsers Chrome Firefox Opera and another container running the Chrome browser simultaneously okay so let's quickly run this and we will check from the browser So currently our notes are free but as soon as the test will start they will be busy so all four notes are busy now so we can Mouse on that and can check that session is executing so once test case execution is done all these four noes are ready to accept the another uh test case execution request from the selenium Hub hello guys welcome to the next session in selenium G Docker Series so this is session number five and in the session we are going to see how we can set up selum grade using the docker compos file okay so in second session we have already created our selum grid architecture by running some Docker commands Okay so in that session we run this command for creating Hub container then we run few more Docker commands for creating this node containers and these node containers nothing but the browsers will link with the Hub container okay container so there can be some issues or problem you may face while creating the containers or selum grid architecture with with this approach so this approach means you need to write these Docker commands in the power shell or command prompt and you need to run this command to create and start the containers for different components of the celum grid right so in this first important thing is you need to remember all these commands right for creating Network you need to remember this command for creating container for Hub you need to remember this command for syntax and everything right so first challenge uh in this approach is to remember all the docker commands for creating the containers and another thing is it is going to take more time for creating and running this containers right because first we create the network then we create the container for Hub then we write this commands for creating the containers for the different browsers right then again it is going to take the time because here in this we need to write these commands one by one in the power shell and then you need to run it right and if you do some type of mistake or spelling mistake while writing this command again you need to fix it and again you need to run that command so this proess is going to take more time right and it is not limited to this only in realtime project we work in a team right so in team there are multiple members working on the same project let's say 10 15 people are working so all these peop will also have to remember all these commands for creating this architecture or any container so again there can be issue if they do some spelling mistake or type of mistake again it is going to take the time and one more thing is if any new member join your company or join your team and probably if they don't know about this command Docker commands or concept then you need to provide this command to that member again they you need to explain them how you can run this and how containers are creating and all those things so this process is bit time consuming and if you remember when we create the container for the nodes we created the container for Chrome let's say and if I want to create another container running the Chrome browser again I have to run this command okay you can provide any container name and you need to run that command again means for each and every container you need to run separate commands so if I run this command I get the first container running Chrome browser for another container if I want again have to run the command and I will get the another container running the Chrome browser so likewise you need to run this Docker commands again and again every time you need to add separate Docker container so by running a single Docker command we cannot create multiple containers out of the same Docker image each doer command can only create one container at a time that means you need to go run this Docker commands multiple times right not only all the team members if they require these containers they will require to run these commands again and again so to overcome all these problems we use Docker compos file to create run any container or starting any service or scaling the containers right so we can provide how many containers we want so according to our Command we will create that much uh containers at a time so the best way that we can do is to use the docker compose file for creating and running this containers so here what I will do is I will create this Docker compos yl file so yml stands for eight another markup language so if you know about test XML pom.xml these are the XML language so similar to this XML files we can use this yml files to store and transport the data easily and what whatever data or whatever statement you write in this file are equally understandable to human and equally understandable to machine okay so it is very easy to write and easy to understand so here I created this Docker compose file Docker compose do yml so in this file I will mention what are the different Services I want what are the different containers I want for example I will write that I want to create this selenium Hub service then I can mention for creating this uh selum Hub container uh what Docker image it should use then after creating the image I can mention the ports also what are the ports we need to publish right I can give the volumes also for the memory purpose right I can provide everything like environment that I want to uh use for creating this container okay so you don't need to remember this command and this command just in this Docker compos yl file provide the list of services or list of containers you want to create and provide the docker image name in that file from which this containers will be created so this statement I written for the uh for creating the Hub container right selum hub container so same kind of statement I can write for creating this node containers also here also just have to mention the service I want to create the service name then Docker image from this container should be created so while creating this uh container what ports it should publish then I can mention about the volumes also so whatever configuration you require for creating this multiple containers you just have to mention in this Docker compos yl file so as for your need just provide different configuration like what Docker image you are going to use what different ports you are going to publish what are the different volumes what are the different environments so all I have to do is just create this Docker compos WL file provide all the configuration and when once it is done so we will provide this Docker compose file to all team members and they just have to run this Docker compose file okay so they don't require to remember all this command they just have to remember single command for running this Docker compos yl file so all of us we just have to remember this command for running this Docker compos yl file locker roer compose up okay that's it so as you can see this command is very much easy to remember as compared to this command so here you need to remember this lengthy command for creating the separate containers right so once our file is ready is ready we will share with all the team members and using this command Docker compose up we will run this file so when you run this file Docker will see what are the different containers you need to create what are the different images the user have mentioned and from that images it will create the container and as for the Port Entry volume entry what are the different environments the user has written in this Docker compos it will provide that environment and that configuration to that particular Docker container So within a very short period of time all our containers will be created and ready to use and as I already said another great Advantage we get with this Docker compos file is we can uh do the container scaling so while running this doer compos file itself I can do the scaling of the containers so I will provide while creating the containers for Chrome browser please create three containers for the Chrome then I can provide please create two containers for the Firefox like that so creating this multiple containers from the same images at the same time will be taken care by the docker compose file and another Point here is you don't require to create the docker Network on your own so here while creating and running container through Docker commands we need to create the docker Network first and we need to make sure these containers are running in the same network so that we can link them and they can work together but in case of Docker compos file we don't require to create the network so here what it happens is whatever services and containers are created as a part of this Docker compos yl file will be created in the same network only that will be taken care by this Docker compos so it will create a Docker default Network so all these containers will be created and run in the same default Docker Network okay so you don't have to worry about this network thing also so this is also another advantage of this using this Docker compos ml file and once your work is done you not requir to take this containers down one by one you just have to remember this command for that purpose Docker compose down so both these commands you can see are very easy to remember so to create an run the docker containers using this Docker compose file just run this command Docker compose up and once you are ready to take all these containers down just use this Docker compose down command so now let's go and see how we can create this Docker compos WL file so that we will be able to create the same grid architecture as that of the second session but this time we are not going to run any of these Docker commands so we'll just create this Docker compos WL file and we will run this Docker compose up command so let's create that file now so I hope both notepad file and visual studio screen are visible to you so first of all let us create a new file here and save that file as Docker compose Docker Dash compos and file type should be yl okay so you can see in any folder in your directory okay so Docker compos y so you can save this file using different name as well so if you created this file and save this file name as Docker D compos yl then you can use this command to run this file so first one you can use Docker compos up or second one is Docker Das compos up okay and if you want to save this file with some another name you can do that for example you save that file as setup selenium grid. yml so if you want to run this Docker compos yl file then you need to use this command Locker compose okay it is same then you need to use this F flag okay here you can provide the file name want to run so here you need to provide this file name whatever you have given to the file and this is the up command so this command will create and start all the services whatever we are going to add in this Docker compos file okay so we will see both the examples so for creating GD in the docker we are going to create mainly four Services through this Docker compos ml file so first service will be for creating this Hub container the selenium Hub container and then another three services we will create for this node browser containers so one container will be for Chrome browser then another one is for Firefox and next one will be for open node and as a already discussed we don't need to create the network in case of Docker compose file doer compose will create it own default Network and all the services that we mention here will be created inside that Network only okay so let's start so how do we add data in this Docker compos WL file is you just have to add data in form of key and value pair so first key is version colon and its value is three okay so in case of Y file you need to take care of indentation okay so press enter after the version and here you need to provide services key yes so this is my second key press enter Then after pressing enter just press T key once so under this Services we are going to add all the services you want to create means we will mention all the four services for this Hub and node containers okay so once you press enter press T ke once and here we will add our name of the first service so first service I need to create for this Hub container so let me give name as Hub service colon enter so again you need to provide one tab so from this position whatever configuration you need add for this Hub service will be added okay so after pressing enter just press one Tab and here we will provide what image it should use to create this Hub service container so for that I will add this selenium Hub okay so we need to use this image for creating this selenium Hub container enter so next thing is we need to provide the container name right so same here we need to provide only here we need to use this container keyword container uncore Name colon space and I will provide name the same name I will give okay and next thing we want to uh publish the ports as well right so for that you need to provide ports so this key will accept the list of uh entries me list of data so that's why you need to mention on next line enter and press Tab Key first Dash and in double quote you can mention multiple entries here so I will publish the same as that of second session okay so what does this mean it means whatever service that will run on port number 4444 inside this uh Hub container will be mapped to the port number 4445 of the host machine so that whatever service it is running inside this Docker container I will be able to access from the host machine Itself by using this 4445 Port okay so our first service entry is done H service image container name and post that's it so now let us create services for our node containers what I will do I will just come here we'll just change the values so this service name should be let's say Chrome service so this is my Chrome service and for creating the Chrome container it should use this Locker image so that I will mention here and container name should be uh here we have provided the Chrome node okay so same I will do here and ports we publish is 4446 with 590 4446 590 okay so whatever VNC service running at this port number 59 inside this Docker container will be accessed through this 4446 port number from the host machine so that we will be able to connect to this port through the VC and we will be able to see what exactly happening on the browser when we run our selum test case on the selum grd sof Port we need to add means we need to link this uh Docker container to the hub container okay so this is the node container and we need to add it to the hub container so that there will be a BAL Pro between these two containers so selum Hub can forward whatever request selum test request coming it will just follow to this chrome node so for that purpose at this port level you need to provide the environment environment colon enter so press one t key so here we will add this Hub equal to selenium Hub and here you can mention the Hub Port as well so hubor ports equal to 4444 okay so Port is 4444 and after the environment another thing is this chrome service is completely depend upon this Hub service so if Hub service is down there is no need of creating this chrome service because it is not of any use so we are going to create dependency between these two service means node services to the hub service so how can you create it you need to use this key depends score on colon then provide T key hypen you need to provide this H service name so this is the service name on which this chrome service is depend upon okay so this is for creating this chrome service container uh whatever configuration we are required we have added this in form of key and value so it looks very easy as compared to this lengthy command you just have to add it only once and using same configuration we can create another Firefox and oper Services okay so you just have to change some values from this and another point is here we have provided this container name for Chrome node and under this port you can see we have specified a specific Port but when we are going to scale this containers using this Docker compos file we may face issues because we have provided the specific Port so if one container is already using this port it won't be able to map same port to the 59 Z for another container so for now let it be there a container name and ports and we will run this Docker compose file without scaling and once it is run uh then we will scale the containers and then we will see what error we will get and accordingly we will make the changes so let me copy this and add the service for Firefox and Opera so I have added service for Firefox service and Opera service so this uh two things is going to same for each service environment and depends upon so this will be same only we need to change the port we want to publish and the container name okay so other things are same and this is the node Firefox debug image will be used to create this container for this Firefox service and for Opera service it is going to create container out of this selenium SL node Opera image so this image are already available on my local machines so as compared to this Docker commands so you can see it is very easy to add this Services inside this Docker compos file so just looking at the key name you'll be able to understand what exactly it is going to do so this image means image which image it is going to use what ports you need to publish what should be the container name okay so it is very easy to understand so once this file is ready you just have to share this file with all your team members so that they don't require to uh remember all these commands and run this command again and again okay so let's go and run this Docker compos ml file so as we have saved this file as do- compos we are going to use this two commands so just go to the directory where you have created this file so from here I will open Powershell okay so first let's see if any container or any Services running or not already doer PS okay so there is no container no Services running so we need to use this command Locker compose up okay so as we have saved our file doer hypen comp. you can use this command directly to run that file so doer compos of hit enter so we are getting some error here additional property environment is oh we did the spelling mistake so we need to make sure not to do any spelling mistake here environment so copy this side here so you need to make sure you are following proper indentation uh the key name should be correct otherwise it will give error like this okay so I hope others are correctly spelled okay so let's go and run this again loer compos up so this time it is starting these containers so you can see it has started Network Docker default first and it is starting the different containers for different Services now so node Firefox node so at the same time all these containers are getting created and started so all these are the logs you can see so the op node this node is registered to the hub and ready to use okay so op is ready and it is already connected to the hub then the Chrome node is also registered and somewhere we have Firefox as well okay so from this logs you'll be able to see what exactly happening when we run the docker compos up command so you can easily cross verify this the network is created or not so for that let me open another window of power shell okay so here I will check Docker Network LS so these are the different networks already available and created in my Docker so Docker default is if it is there yeah you can see here we have this Docker default Network so this network is created by the docker compose and whatever Services we have created as a part of this Docker compose are already linked to each other and they are available in the same network so our Hub is up and running and all these three containers are up and running so we can verify that as well here let me doer PS okay so you can see we have total four containers so one container is for selenium Hub another one is Chrome node then Opera node and Firefox node and whatever entries we have provided for this ports part they are correctly configured by this Docker compos so this 4447 Port map with 590 and this 4444 for selenium Hub is mapped with 4445 of the host machine okay so let us go and see if we are able to access this service on this port number 4445 from the browser okay so if you open Local Host SC on 4445 you can see that selum grid Hub 3 3.14 1.59 so this s is up and running here and if you go to the console you can see all these three nodes running Chrome browser Firefox and Opera are connected to this common Hub okay so now we will be able to run our test case in parallel on sequential man as for your wish and if we go to the docker desktop application there also you'll be able to see this is the grid created and inside this same we have four containers up and running so same logs you will be able to see just click on that Docker and you will be able to see same logs here and you can also check the logs for this individual containers as well okay so this node is registered to the hub Android to use like that and you can even inspect as well okay so we can see what is the Hub host here this selum Hub what is the Hub Port that is mapped is 4444 then we have published the port as well so that entry also be available here so here it is for 59 PCP is ma with 4448 so now we have successfully run this doer compos AML file so all the services that have mentioned in this Docker compos yl file all these Services got created and started by the docker compost with the whatever configuration we have provided so for this we just run a single command orer compos up and all our selum grid architecture is ready within the few second so now let us take this containers down so press control C it will stop these containers so let us save that file as some different name we will give some different name to that file and let us try to uh run that file as well so first let me remove all the containers Docker compose down okay so all containers are taken down you can see that there is no container running that means all the services are have been taken down so let us save this file with some another name so we have taken an example here we will give this name to this file selum g.l let me rename this okay so this is our file name now and now if you try to run this Docker compos file with this two s it is not going to work okay so let us see that as well so we will use this command do compos up so you can see you can't find a suitable configuration file in this directory or parent means there is no file with the name Docker hypen compose DOL and another command is Docker happen compose up so for this command as well we got the error so how we can run if you have given some any other name so you just have to use this command very easy to understand Docker compos this is the file plag and provide your file name here and then up command so I think let me check the file name so here we don't need to give this yml okay let it be just set up G and if you try now okay so now it is working so this is how this Docker compose works it will works in step by step process it will create the docker default Network then create the services and then link the services to the common Hub according to the configuration we have provided in the docker compos ml file right whatever Port we have mentioned it will publish those ports so everything is done step by step so all these services and containers will be up and running within few seconds okay so it saves a lot of your time compared to running the docker commands for creating these containers okay so next thing only remaining is scaling of the containers while creating or running this Docker compos up file so let us see how to do that but before that let me show you how we can run this uh selum test cases on the grid that we have created so we have three nodes now and three different browsers so we refresh this so now we can run our selum test case on one test case on Chrome one on POA and one on Firefox in parallel so in session number three I think I have created few sample test cases so let's try to run the same on this the selum grid create with the docker compos so if you want to see how those test cases are created and how we configured it to run on different browsers in parallel you need to see the session number three in this playlist so you will find detailed information about that in that in that third session we have added four different test cases in this test NG gxml file okay so we will as of now we will run this three so one test case will run on the Chrome browser the next one will run on Firefox and another one is going to run on the Opera browser and this is the class in which we we have configured everything so we have used before test annotation and parameterization using this test and XML so we have provided the browser value from that test and XML and according to the browser name we have set the capability so browser name and same capability you need to provide to this driver equal to new remote web driver okay so in this URL we have provided where our selenium Hub is running this is running at Local Host 4445 right we have exposed this code 4445 wd/ Hub and need to provide another thing capability as argument as well so now H is going to decide if he get a capability Chrome it is going to open the Chrome browser and run your test case if you get the capability related to the Firefox or Opera so it will forward those request to that particular node running that particular browsers and these are the sample test cases I have created just opening the Google Chrome and we will going toer the titles then another test we are going to open the LinkedIn and then check the title and same for the another one the Gmail okay so all these three test cases are going to run on different browsers Chrome Firefox and Opera in parallel so for that we have provided this parallel equal to test as well and thread count 4 okay so you will find detailed information in in the third session so you can watch that so as up now I will just right click on that and run as test NG suit so test execution should start on these three browser simultaneously so you can see once test execution started it will show you so start on Firefox op Chrome so it should start the session now okay so it has created the session and you can see here all the notes will be busy now okay so all all three noes are busy now means our test case is being executed on this particular browsers okay so first execution is done okay so Chrome is free now we are still busy okay so all three nodes are free now so we'll be able to run our another test case on these nodes now so last thing we need to see is how we can scale the containers that means so currently we have created only one container for each browser so you can see one container for Chrome one container for Opera and one for Firefox but if I want to create multiple containers that means if I want to create and start three nodes running the Chrome browser so you should be able to see similar entries three entries here one after another okay for the Chrome and similarly I can scale for other nodes also so I can have multiple Chrome multiple Firefox browser nodes and multiple Opera nodes containers so let us see how we can do that so to scale containers what we have to do is you need to use the same command so we are going to use the same only at the end we are going to use this happen happen scale flag okay then provide the service name you want to scale so let's say I want to scale my uh Chrome service so copy this name and add it here Chrome service equal to how many Chrome service you want to create means how many nodes you want to create and start this service so let's say I want to create three nodes okay so three nodes for the Chrome so let's go and see if it works or not just copy this Locker compose hyph F selenium set up selenium g.l up and here scale Chrome service equal to three so now as I already mentioned previously that we have provided this chrome node to The Container name so while scaling it is going to create multiple containers so this container name should be unique one so more than one container cannot have the same name so that's why it has given the error this container name Chrome node is already there so that's why it is providing the warning also here that the Chrome service is using custom container name means custom name means user has provided the container name not the doer compon deciding so Docker requires each container to have a unique name so remove the custom name to scale the service so if you want to scale the service you need to remove this key so let me remove this quickly okay so let us run that command now [Music] so it is going to create separate containers for separate service so three services three containers for the Chrome and one container for Firefox and one container for the Opera so if you scroll up you will be able to see this three different containers for the chrome chrome service 1 2 and three and another container for op and Firefox are link with the same selenium Hub container so now if you go to the browser you'll be able to see three nodes Chrome browser so you can see this is one this is second container running Chrome and this is the third container running Chrome browser okay so what we have done here we just scale this chrome containers so while creating and starting containers from this doer compos ml file we have used this scale and we have provided which service we want to scale so I want to scale this chrome service and you just have to provide the value so very simple command for scaling purpose as well so it is very easy to remember Docker compose hyp F the file name you want to run up and this scale flag and provide the service name and the counter okay so similarly let us uh Run for the Firefox and Opera so let us see this Opera service 2 is there then Firefox service 2 also got created so everything is happening very quickly right this is very useful this doer compos file and if you check the browser now let us just refresh this and you can see now we have uh Opera node one then this is the second Opera two operas are there and three nodes running the Firefox okay and one is there for Chrome browser okay so this is how you can keep scaling these containers as for your need so if you want more test case to be run on multiple browsers specific Chrome or Firefox just scale those containers while running your doer compos file and then you will be able to run all those test cases in parallel mode very easily so let me just quickly see the details of this running containers PS I a so here I just wanted to see what port it has published so you can see Docker has itself published this port 57623 for this chrome service 3 and for Firefox different Services it has published this different port so whatever Port it is available at that time it has published to the 59 of the docker container and same if you go to the desktop application you can see here as well so all containers are up and run now on the different ports so when you create a selum grid inside the docker we can create multiple instances for the nodes and we can Define or we can create multiple sessions for that particular node as well so this will help you to run your selenium test cases in parallel on multiple instances and by creating the multiple sessions on the Node containers so I'm going to show you all these things practically okay so for demonstration purpose we are going to use the same doer compos yl file that we created in the last session session number five so in that fifth session I have covered everything in detail okay so we have provided the Hub service that is the selenium grid uh selenium Hub then we have defined three services one is for Chrome browser then second container will be for Firefox and third container will be for Opera so let's go and run this Docker compos file to create our selenium grid so first let's see the list of services which are currently running in my Docker Docker PS okay so there is no service no container is running so let's go and run this our Docker compos yl file so to run our Docker compos file you need to use this command orer compos hyp F then provide the file name so my file name is this yml and up and hyp D okay so hypen D is for detach mod so all the process that is going to happen will happen in background okay so within a few seconds our s will be ready and now again if we check the list of services you can see we have uh this four containers one is Hub and three are the node containers so we can see we have the selum Hub container running at 4445 so we can access this service from the port number 4445 from the host machine from the browser so if you go to this Local Host 4445 you can see this grid Hub Services running and if you go to the grid console you will be able to see three nodes running Opera Chrome and Firefox browser So currently we have only one node for each browser so now if I want to create multiple nodes running this Chrome browser for example I will have to scale this chrome service so how I am going to do this is you just have to use the same command for this purpose copy that command so you will require to run the same command only you need to use the scale flag for scaling the service so now we are going to scale our Chrome service right so you need to copy this service name scale Chrome service equal to how many nodes you want to create let's say three so if you run this it is going to create three nodes running Chrome browser so now we'll be able to see Chrome service 3 Chrome service 1 and two that means there will be three containers and if you check the list now you will be able to see we have more containers now so we have total five containers now one container for the Hub next one is for Firefox then Opera and we have three containers running this Chrome browser and Docker compos have published this random Port whatever I available at the time to the 59 of Docker container and from browser if you refresh now you'll be able to see that we have three nodes now running the Chrome browser right so now you'll be able to run your parall test case on this multiple Chrome browsers okay so next thing we are going to see is defining this node Max instances so that means currently we are able to see only one instance in each node or each container right so we have only one instance of Chrome browser in each container then one instance of the Firefox in this container okay so we do not have the multiple instances so what if I want to create multiple instances in the same container that means I should be able to see multiple Chrome browsers in this container So currently have one so if I Define three then it should show me three Chrome browsers in each container running the Chrome browser okay so Chrome is running in three containers so in all three containers I should be able to see three uh Chrome browsers here okay so how you are going to do that just have to use the docker compos yl file for that purpose so just go to Docker compos WL file and you uh need to Define one key under the environment so that is nodecore Max instances so this key you need to Define in the docker compos file for that particular service so for example we are going to create multiple instances for this chrome service so what we'll have to do is just go to this chrome service and under this environment key you need to add one more key here so that is nodecore Max instances equal to let's say three so we have scale this chrome service already equal to three and we have defined this node Max instances equal to also three that means we are going to see three instances of the Chrome in each node container running this Chrome browser so let me save this and we will use the same command now okay so let it finish the process okay everything is started now so now if we refresh this browser so now you can see that we have three instances of chrome in each container running this Chrome browser So currently we have three node containers running Chrome browser and in each container we have this three instances of the Chrome browser so next property is defining the maximum sessions that means here we have created the maximum instances so by using this node Max sessions we are going to Define how many sessions should start in particular node okay so by using this node Max session we can can limit uh the number of or maximum number of session can be started at the same time for the particular node container so how you are going to do that we will have to do the same again go to your Docker compos file and you need to add this under the environment node Max session okay so let me go here one more property here we are adding nodecore maxcore session equal to let's say two so we'll have to run our Command again to get our changes reflected for the selum GED okay so from Chrome browser if you refresh you won't be able to see from uh this P browser but if you go to the configuration then you will find the maximum station value here okay so maximum station is limited to the two and under capabilities you will be able to see uh maximum instances so maximum instances are equal to three and maximum sessions are equal to two Okay so this information you will get from this configuration tab for your Chrome browser node container so now let's go and run our selum test cases multiple test cases in parallel so we will see what will happen if he provided three selum test cases to the hub to run on the Chrome browser in parallel okay so the test cases have already created in the previous session in session two so I'm going to run three test on the same Chrome browser so that you'll be able to see the use of Max node Max session and node Max instances okay so all these three test are going to run on the Chrome browser only okay so we have provided three test case to be to the selenium Hub now Hub is going to decide depending upon the capability that uh it has to open the Chrome browser now we'll see which node will be activated first so refresh the page you can see one instance from this container and one instance from this and one instance from this is started running our test case Okay so it has used one instance from the each node container so now what we'll do we will remove this multiple node containers from the Chrome browser we will keep only one running three instances of the Chrome browser and then we will uh run our test case and let's see what will happen so for that purpose what I will have to do is I have to scale this two one okay so now you can see we have only one more running our Chrome browser and we have three instances of the Chrome browser in that node so let's go and run our three test case again on three Chrome browser so this time we need to verify it should not uh start all these three instances because we have defined maximum instances equal to two so you can see only two instances are busy now even though one is free it is going to wait for one of this instance will be free and then next test Cas exucation will start okay so all are free now and if you check the result three run three passes okay no failures that means all our three test cases have run on on Chrome browser in par so they started on the Chrome at the same time but only two sessions started at the same time because we have defined this maximum session equal to two so that is why one test has to wait so that one of these instance will be free from the test execution so once that test execution is done the next test case will start executing so this Max session property you can use to limit the number of sessions started at the same time for the particular node if that node has multiple uh instances of the same Chrome browser or Firefox we can limit maximum sessions to be started at the same time by this Max session okay so now let's quickly see if I make this Max session equal to three whether this all three instances will start simultaneously or not so we will just change the value from this Docker compose so we have three instances of the Chrome browser and we have set this Max session equal to three so we need to run the command again so it is going to recreate this container because we have made the changes for this service only and other are already running so there is no need to start it again so first verify from the browser so if you refresh let's go to the configuration and you can see here maximum session is set to three now again maximum instances are three so let's quickly run our test case so you can see all the three instances are busy now right okay so all three are free now so all these three are very important in your realtime projects and in your entry point of view also so don't forget to prepare this well before you go for the interview you just have to remember this command for running our Docker compos WL file how we can scale it by using the scale flag provide the service name and the value for this node Max instances and node Max session you just have to make changes in the particular service in your Docker compos file so under this environment you need to add this two node Max instances and node Max session and depending upon this value this configuration our test case will start executing on this chrome service running container so in this playlist in previous six videos we have configured celium be 3 by using Docker commands by using the docker compose also and the badge file okay so we have seen all these things in detail in the previous session so let me copy the doer commands that we have used for configuring the selum grd 3 so as you can see we have used this command for creating the container for our selenium Hub and different commands for creating the containers for the node browsers or the node container coners okay so let's try to write the docker command for creating the grid 4 now with reference to these commands Okay so first let's write the docker command for creating the container for selum Hub Docker run hypon d means this process should run in background then hypon P so here what we are doing is Port mapping okay so there is a separate video on Port mapping why it is required and how it is beneficial in case of Docker container and host machine so you can watch that video also available in the playlist so here I'm just going to map the same port this one so port number 4445 from the host machine is mapped with the 4444 from the docker container so next thing is we need to start this container in a network so for that purpose we will have to create network first so for example G for Network okay this is my network name so we will create this network so for creating Network command will be same for grade three and grade four so first of all you need to create the network okay so all the containers that are H containers and your node containers should be in the same network so that they can communicate with each other and that will create a bidirectional connection between selum Hub and node containers so this command will be same Docker create network and uh give your network name so I am going to create network with this name so this is grid for Network so for creating Network command is same for grade three and grade four so here we are using this network flag this is the network name and then hypen hypen name so what should be my container name so I will use the same okay so as you can see we have almost same command as that of grade three so only difference here will be image okay so here we have used this latest image from the selum slub so here we are going to use the separate image that is the fourth version of the selenium Hub so selenium Hub colon and here we need to specify the tag okay so let's give the tag okay make sure you are giving the correct tag here otherwise you will face the error 4.0.0 d rc-2 d 2021 09 and 30 okay so this particular selenium Hub image we are going to use for creating our selenium grid 4 okay so make sure you give the correct tag here okay so according to this tag our Docker will first check this image is available on your local machine or not okay so if it is available locally then it will use that image for creating the container out of that image and it will create and start that container if image is not available locally then it will go to the docker Hub and it will check if this image is available or not with this tag name and if it is available then it will pull that image okay so that image will be available locally and then it will create the container out of it okay so as you can see selenium grid 3 command and selenium grid 4 command is almost same only we have changed our image name so now let's write the docker command for creating the node containers so first let's create container for our Chrome browser Docker run i d running background then hypen P okay so here I'm going to specify the uh specific Port that I want to publish so here I'm going to map the same port here and we have created our Hub container in this network so we need to create our uh node containers for browsers in the same network okay and next thing we had specified the environment that is Hub host equal to selum HUB that means this container should be linked to this Hub host that is the selum Hub container so same we are going to do here only slight difference is there so here we are not using this key here H host here instead of that key we need to use S eore eventcore Bus uncore host equal to your host name that is the Hub name so this is my Hub then next parameter next environment b s eore eventcore bus underscore publish underscore Port equal to 4442 okay so these parameters we are adding for creating the correct connection between our node containers and selenium Hub okay so these ports are already export in our container so we are just using it so next environment e score eventcore bus underscore subscribe _ Port so we need to subscribe to the port and that port number is 4443 so these three keys we need to specify in our Docker command as a environment SE event bus for that is your Hub name then event bus publish code 4442 and event bu subscrip Cod 4443 okay so that is our environment is done and then we need to give the container name okay so you can give any name to your container Chrome node one okay and here we need to specify the docker image name from which this container should be created okay so here you need to use this image selenium SL nor Chrome and here we will specify our tag so our tag should be this one okay so this we have used for this Lum Hub the same we need to use for node containers okay so this is the complete Command for creating our first node container running Chrome browser so one more point in case of selenium grid 4 is we can access both VNC service and no VNC service so VNC service means whatever service it is running at 59 inside Docker container we'll be able to uh see using this code number 4446 using the VNC client so in previous sessions we have used VNC viewer as a VNC client so when we start our execution selum test case execution on the these node containers we will be able to see how our test case are running on that particular browser Chrome or Firefox right so that is for the VNC service for which VNC client is required but here selum grid 4 supports no VNC also so no VNC means you do not require any VNC client such as VNC viewer you will be able to access that service from the host machine from the browser itself so we will see both the example our VNC service from VNC client VNC and no VNC service from the browser itself so one more Point here you can specify uh your host memory also so whatever doer containers we are going to create uh these containers are going to use the memory from The Host okay that is the host shared memory so for that purpose we just need to use the shm flag so that we can specify here okay before name shm right so this is this flag is for sharing the host memory for the doer containers right shm dash size equal to so here you can specify the size here let's say and it should be double Cod okay so this is the complete Command for creating our first uh Chrome node container from this image so you can see 50% portion is very much similar to our selum grade 3 Docker command so here we have just mentioned some different Keys here event bus host event bus publish Port And subscribe Port okay so this command should create our first container andc service we will access through this 4446 so let me copy this command and this command we will map a no VNC Port so that we can access that no VNC service from the uh browser from the host machine so only one change we will do here instead of mapping find I'm going to map 790 so this is the default P for NOC service okay so inside our Docker container when we create the new service will run at this port number okay 790 so if you want to access the same service from the host machine then you need to map this port to the any other Port so 4446 will be already used by Docker container so we need to use any other so I will use here 4447 okay so by using this 4447 port number we will be access this service from the host machine browser itself okay so that we will see practically we we run our selum test case in parallel on this selum grade 4 okay so it's time to run this command so let's move to the power shell now so as I already said first we need to create the network and then we will create our Hub and node containers so for creating Network this command is a little wrong it should be Docker Network create grid for Network okay so use this command for creating the network [Music] okay our network is ready so let's get our selum H container ready okay next one will be the container for our first node Chrome browser okay and the next one will be the container running Chrome browser only but but we have exposed this no VNC client okay for accessing no VNC service from the host machine browser itself so here we just have to change our container name which should be Chrome node 2 okay so as two containers cannot have the same name at the same [Music] time so let's check the list now okay so we have three containers up and running on different ports okay so let's try to access this selenium h service on port number 4445 from the host machine so if you go to your browser on Local Host col 4445 you will see that selenium grid 4 is up and running here so you can see as compared to selenium 3 we have a very good look and feel UI here so you can see here we have two uh node containers running Chrome browser okay uh linked with our selenium Hub and in this session tab you will be able to see whatever session that are running or whatever the session that are in the queue so we'll understand this when we our test case in parallel so first let's go and create two more containers one will be for Firefox and another one for the Microsoft age browser so for that purpose copy these commands and paste just have to change the port 4448 and I will just change my node here so this should be Firefox node one should two great and the image we are going to use is node Dash just change the name here so now I do not have this node Firefox fourth version image on my local so so it will go to the docker Hub and it will pull that image and for this chrome chrome node and CM Hub these images are already there on my local so these containers got created immediately so in your case when images are not available locally it will take some time depending upon the image size and your network speed so if I hit enter it will show that un aable to find this image locally and another I think I got disconnected from my internet connection so we need to make sure we are connected to the network while running this Docker command so that it can download this images from the remote Docker Hub so let me run the same come on now okay so we could not find this image locally so it will go and check on the docker Hub with this tag 4.0.0 and this is the image s/ node Firefox so let's it will take some time so so what I will do I will just pause the video until it get completed okay so we have created two more containers one is for this node Firefox and another one is for the uh selum node age and on the browser you will see two chromes one Firefox and one is Microsoft age so first let's try to access the NOC service for these containers so first let's check the list so VNC service will be accessible at these ports 4447 4448 and 4449 for this respective browsers you just have to add this Local Host 4447 4448 and 4449 okay so this is a no service so just click on this connect and this password will be secret let me Ed it for all okay so this is the no service running inide the doer container and that we are accessing from the host machine using the different ports and same if you want to verify inside the docker container just run this command exact hon it do the container ID you want to go inside so let's go to the Chrome container to It's 22 okay I forgot the B Bash here okay so we are inside the container now you can see sale user atate this is the container ID so now if you want to see what is happening on the port number 790 inside this Docker container we just have to call this call local host 790 so in response you will see we have got this uh the content of the HTML page actually this is the body so this is just an content of the HTML page for the no VC service okay title NOC so let's get exit from this container now we can even un check the docker logs for this container or you can inspect as well so we will see more details in this so whatever the port you have published 790 TCP Port is mapped with the host Port 4447 okay and here you will find this SE event bus subscri Port 4443 the host name selum Hub and SE event bus publish Port is equal to 4442 okay so you can easily check do log or you can inspect the containers also and if you want to check the memory CPU utilization you can check using this command Docker stats so if you run that command you will see whatever the containers are up and running and your name what is the CPU utilization memory utilization all these details so currently we are not running any test case that's why this utilization is low is around 10 5 to 10 so let's go and run our selum test cases in parallel on these containers now so for demonstration purpose I'm going to use the same project that we created uh in the session number two so please watch session number two to understand how we have designed this test cases how we have configured this to run our test cases in parallel on different browsers so we will go and run our test case on the Chrome then Firefox and instead of opa this time I will use the age okay and we will run our test case on the age browser let's say this is our age test okay so just go to your test and gxml parall equal to test is already set and thread account is four so first test should be run on Chrome browser okay then second test should run on Firefox and let's run this third one on the edge and the last one also we can do on any browser let's keep it on the Chrome so now all we have to do is to point our test case to the selum grid running at this 4445 right so that you can do from this Docker s grid test class and at theate before test method so that is already set here driver equal to new remote web driver and this is the URL you need to give sttp colon Local Host 4445 WD Hub so in case of selenium 3 grid 3 we are giving this WD Hub but in case of grid four we don't require to give it okay so there won't be any issue if he provide a wdub but it is not mandatory to give for this grid four so let me remove this so let's run this test NG XML as test NG SU okay so you'll be able to see test case here it is for Mo Firebox and this container is for Microsoft age okay so this is the S which is running okay so all are done now so our four test cases got executed in parallel on this selum G four and all four got passed okay so let me rerun this one more time to show you this uh memory status so you can see this is normal now so once we run it it will increase the utilization for the memory and CPU so now let's check so you can see 95 76 and it is utilizing the more memory also okay and uh we can run our test case serly as well so just set this to so at a time only one test case will start executing So currently it is executing on this Chrome browser so we have here in Q we have one so these values are getting changed as in when test case ucation is starting on the different browsers so we have total four one is executing so concurrency is 25% so another one for the Microsoft age has started now and this should be the last one now can see here the capability set for this particular browser okay so all tests got executed now and no sessions are running now okay cool and if you want to access this VNC service to the VNC Cent on 4446 uh just download and install wec viewer application and open that application and just add IP here 127.0.0.1 colon and the port number so we have uh given this 4446 for this chrome chrome node one container 44 6 okay so it will also ask you for the password so here also we need to enter secret in lower case Okay so this is the uh L container running our first Chrome browser okay so we can monitor our test case through this VNC service or you can use this no VNC Service as well so instead of running these commands one by one uh we can use this Docker compos VL file okay so it's a configuration file where you can mention what are the different Services you want and with the help of single Docker command this selum grid four will be up and ready for use okay so what happen with this case when you are running these Docker commands one by one first thing is you need to remember all these commands by your own or you are working the team right in real time project so all the team members will have to remember these commands and they need to run these commands one by one so this process is going to take the time and we are the humans we do the spelling mistake right so due to that also you will face the err to fix it and again run that command so instead of this approach I will show you how you can uh create and configure this Docker compos VL file so that we will get the same s grid for architecture in the docker that we got in the previous session by running this Docker commands Okay so for reference purpose we will use the docker commands and the docker compos v file that we used for creating the grid three in the previous session so that we have created in the session number five right okay so I have explained uh in detail everything about how we can create the doer compos file what are the things you need to remember while adding the services in the docker compos file okay so this is the docker compos file that we use for creating the selum GD 3 so we will use this file so let me make a copy of this file first set up selum grid 4 we will say and extension should be y AML okay okay so we'll make change in this so let's do the version as four services so in case of this swl file you need to take care of indentation and spaces okay if you miss any space or if you do any extra space that will create an error so you need to make sure you follow a proper indentation and proper spacing while adding these services so under this service we are going to add all the services that we want so we want Hub service we want Chrome service AG service and Firefox service so first service is Hub service so for creating our selum Hub we need to use the different image so for selenium grid 4 we have used this image right so we will add this and then this container name uh Let It Be selenium Hub then ports you want to publish so here I will publish uh two more ports so for creating a link between our selenium Hub and node containers uh we need different ports right so here I'm going to publish 4442 and 4442 from doer container and next thing which we need to subscribe right so this is 4443 4 4 43 from the docker container okay so this port uh Port is the key and this key will accept the array of values okay so that's why we have added it on the separate lines okay so for this key you can see I have added on the same line okay because it is accepting only single value but this key P key accept the multiple values that's why you need to add it on the separate line then next service is Chrome service so this shouldn't be here should be after the environment so for this creating this chrome service we will require a different image for selum grade 4 so this is the image that we need to use for creating node container running Chrome browser right so this is my image name and next thing we need to add is for sharing the host memory this doer containers we need to add this shm flag shmore size colon and let's give as 2GB okay so now we need to uh publish some ports so 590 is for VNC service and 790 is for no VNC service so let's publish both the ports now okay so in previous session we have published a specific Cod because we are just creating a single container okay but using the docker Compass v file we are going to scale this containers that means we can create multiple containers from the same image at the same time so it is better not to give a specific Port like this in the docker compos file just give which Port you want to publish from this Docker container and for the host machine uh Docker will publish whatever Port available at that time okay so we will use that port to access this two uh two service VNC service and 790 is no VNC service so let it be like this then under environment we need to add the different environment so we need to add our SC event bus host and then one port we need to publish and one port we need to subscribe so for this value there will be two Chrome browsers will be running at this chrome service node container so I will show you that and this is the node Max session so how many sessions you want to start in a particular uh node container how many Max session you can start so by using this value you can uh Li the number of session can be started in the single container so I will put it as one as of now so maximum only one session should start in each node container of this Chrome browser so let me copy this chrome service to create Firefox service and Microsoft a service so I have created these two service Firefox service and Microsoft a service so we just need to change the image that me use and all other keys and values will be remain same for each service right the ports and environment is same so you can see that uh it is very easy to create this Docker compos file you just have to add the different Services you want to create and different configuration from from which this Services should be created and started and this process you need to perform only once so once this Docker compos ml file is ready you just have to share it with your all team members so that they don't require to remember all these Docker commands for creating the CM GD 4 right so that is the great advantage of this Docker compos file and we are able to scale our containers as well okay so it's very easy to scale this container so time to run this Docker compos file now so for that purpose just go to the folder where you have created this file and open power shell from that location okay so let me check if any container or any service is already running or not Docker PS ipon a okay so there is no service no container running so to run that Docker compos file you can simply use this command Docker compose and up so you just have to create the doer compos file all add all the services configuration information in that and and once that file is ready you just have to remember this single command doer composer okay so it is very easy to remember as compared to this lendy commands right and you can use this command only if if you given your file name like this Docker Dash compose but our file name is setup selum grid 4 right so we need to use f flag here F and here need to provide the file name so our file name is set up selenium grid 4 so provide that name here do yml so this is our extension and then up okay so let's run this without Rach mode so here I'm not using this hyp D so let's see the logs and everything here so it will just uh as a first step it will create a by default Network and inside that Network all these services will be created so we don't require to create network on ourself so in previous session we have created Network first and then we uh started our containers right Docker Network create but in case of Docker compos file uh Docker compose will create its own network by default Network first and all the services will be created inside that Network so we can see that network uh Docker default that is created and then it has created these containers and services okay so let me open another window of power shell so that we can see the list of service now Dr PS I so here we can see that there are four containers now one is for selum and three node containers and according to our configuration it has mapped uh the port 4445 for the selum Hub with the 4444 of the docker container and it has map a random ports for 59 for each node container for the VNC service and no VNC service port number 790 has been mapped with this uh different ports for the host machine okay so we can access this VNC service and no VNC service from the host machine itself only difference is for VNC you need to use the VNC and for this no VNC service we can access from the browser itself okay so we will see both the things so first uh go and try to access this CM Hub at Port number 4445 from the host uh browser so just go to Local Host 4445 and here you will see uh three noes one is Firefox one age and one Chrome but uh for some reason it is not showing the multiple sessions here let me check okay so in case of s grid 4 I don't think we need to give this maximum instances so node Max session so similar to this SC event we need to provide SC at the beginning score node Max sessions this is the small difference you have to remember and maximum session I can start is let's say two okay so this is the only difference is there in grade three and grade four so I will copy this thing for other two service okay so let's run this again so this time we can see that we are able to see only one session here means maximum concurrency is one so maximum one session can be run at a time so we want multiple sessions so let me first take this down so so instead of up I will use this down okay so just have to run this command up and Hy so this time I will use the detach mode so everything will run in background only we w't be able to see this long this time so Network created started starting this three service now so let's uh go to the browser okay after refresh you can see it is showing two instead of one so maximum two sessions we can start on this each node okay and it is showing maximum concurrency is two means maximum two test cases can be run in parallel on this chrome node or this Firefox and H node okay and the same we can verify from the docker desktop application so just expand this and let's check the Chrome service so you'll be able to see all the logs so max session is equal to two okay and if you inspect this you'll be able to see all the environment we have set from the docker compos file so publish Port subscribe Port Max session is two bus host is C Hub okay so all these values you will be able to see in the doer desktop application so there is some issue it is not showing value for this okay but still we'll be able to access it no problem so you can see uh inspect and logs for every service from this application Okay cool so now let's try to run our test case in parallel on this grid 4 so we will send four test cases to selum HUB uh let's try to run on all the four on this Chrome browser and let's see what happens so I'm going to use the same project that we have created in the session to so I will suggest if you want to understand how we have created this test cases how we have configured this to run in parallel uh you can go and watch this session number two okay so here I have pointed my uh test cases on this running on this Local Host 4445 okay using the remote web driver and using this test n XML file we just have to set this par equal to test and if I want to run any test case on particular browser I just have to provide the value here so first test case I want to run on Chrome then second also I want to run on Chrome browser third on Chrome and fourth will also Chrome so four test cases I'm going to give to the selenium Hub so selenium Hub will check that okay capabilities Chrome browser so it will go and send forward the request to the Chrome node okay so maximum two session can be started at the same time so so let's run this and let's see how it is running at thism GED so you'll be able to see something here okay so it has started two sessions at the same time okay so even though we have provided the four test case uh we have limited two sessions at the same time so it is running two test cases at the same time okay so another two test cases okay so all the test case has been completed now and similarly you can run all these four test case on the Firefox and age okay you can try that your own so let's try to run all these four test cases on different browsers now so instead of chrome I will use Firefox here so one test case on Chrome one on Firefox and next should be on let's say age and four let it be on Chrome so this time it should start all the four test cases because two session can be started at Chrome and one is running at one Firefox and one is at age okay so this is how you can use this grid concept to run your test case in parallel on different browsers at the same time so that will help you to reduce your test signification time and if you want to see the memory usage you can see it from the this TX tab okay so currently it is using 0 point or 4% around 4% and memory usage is around 300 MB so once you start your test case it will going to increase so let's quickly see that as well so you see once test case execution will start you can see these values are increasing now so it is using more CPU and more m and the network so once the test case execution is done it will come to the normal level so this is for Firefox service okay so I think test case execution is done on the Firefox and for Chrome also we can check the same so on Chrome we are running two sessions at the same time so it is going to use more CPU and more memory okay and it is using the more Network as well okay so this help you uh if you face any issue while running in a test case you can check the logs okay you can check the different values of the environment you have provided you can check the memory usage also so now uh let me cover the last Point how to uh scale the containers So currently we have only one container for each browser so you can create multiple containers means you can scale this containers while creating and running this uh Docker compos file so you just have to use the same command here okay only here you need to provide this scale flag scale and which service you want to scale so service name you need to provide so I want to scale this chrome service for example Chrome service equal to two so it is going to recreate this this chrome service only as we have made change into this other services are still running so we not made any change into that so if you go to the browser now okay so you can see there are two nodes containers running the Chrome browser now and we can run two test cases means two sessions in each node running this Chrome browser okay so this is how you can scale the container it is very easy you just have to use this scale flag and provide the service name you need to scale okay so you can provide multiple service also here okay so if you want to scale this Firefox Service as well can do is you can just give it here happen scale equal to Firefox service equal to two so it is going to recreate this Firefox Service as well this time so let's wait for a few second till the changes reflected in this selum grid so now I can see there are two node containers running the Firefox browser okay so this is how we can easily scale these containers using this Docker compos VL file so in case of this running the docker commands we we cannot scale the containers okay that is the big disadvantage creating the S using this Docker Docker commands so better option the best option is to use the docker compos file just add the services save that file and run that file using the simple Docker command and once your work is done you can easily take all these Services down using this same command you just have to use the down here so all the services will be stock first okay and all the containers will be removed then okay so you can see if you refresh here okay so there is no r at this local 4445 now right okay and last point I need to show you the new service how we can access it from the browser so let's try to access uh no VNC service for this chrome node at 5322 so if you go to local 53022 you can see here no no VC service is running so click on this connect and Entre password as secret okay so let me quickly run our test case okay so execution has started on the Chrome okay we have two browsers here right so you can see one and this is the second okay so this is how we can access this no NC service right from the host machine browser because you have published this port okay and for accessing the VNC service you just have to use the uh VNC application so here also we just need to add this IP 12 7 Local Host IP 0.0 do1 colon and just provide the port so this time let's access Firefox VC service at 53026 5326 so same password we need to add here secret okay so this is the Firefox uh Linux container so let's see if we start the execution here it has started now Okay cool so I think that's all for this session guys try to create thisum GD for in Docker using this Docker compos file try to create this Docker compos file on your own and you don't require to remember this command just create this file and run this file and you can uh use different uh values here for this Max sessions you can set to any different values and for practice purpose you can create multiple test cases okay so as of now I just created four so you can try creating 10 20 test cases and try to run in parallel on the selum grid hi guys welcome to the session n in the selum grid with Docker Series so in this session we are going to see how we can run the selum test cases on the Dr selum grid on the remote AWS ec2 instance okay so in previous sessions in the playlist we have already seen how we can uh do the setup for the doer grid 3 grid four on the local machine and we have accessed uh the VNC and no VNC services from the local machine itself okay I have already shown you that how you can do that on the local machine okay this setup so basically a doer will contain one Hub and hub will contain Hub will connected to the one or more multiple nodes means Chrome browser Firefox age Opera like that so we created this configuration on the local machine on the top of Docker okay we install the docker and then we created the setup and then we have run our selum test cases in sequential or in parallel mode as well and we have access VNC and NOC Services as well on the local machine so same type of configuration do grid we are going to set up on the remote machine on the AWS Cloud on the AWS E2 instance okay and once that setup is ready then we will run our selum test cases on remote machine and for the live monitoring of the selenium test we are going to access this VNC Port 590 and no VNC 790 first of all we will require AWS credentials means you need to sign up for AWS account and with the help of that we will log into the AWS console then we will create an ec2 instance on the AWS Cloud okay we'll start that machine and after starting we need to connect to that remote machine okay so for that purpose we need to create the Pam file okay pem file and we can connect to that ec2 instance with SH by using that Pam file so once we connect to that machine okay then we will install the necessary things we will require to run our selum test cases if it is not there for example we will require Java Docker Docker compos right so we will install if it is not there on the machine some machine will already have that software installed okay so we will see that and once it is done then we will set up our doer selum grid on that E2 instance and once it is ready we will run our selum test cases sequentially or in parallel mode and then we will access the L monitoring through the VNC and no VNC services so just go to the AWS amazon.com and if you are not sign up for the this you can create an account AWS account from here okay so I have already created that account so I will directly log into the console so once you logged into the AWS console uh just select uh the region from here Asia Pacific Mumbai region okay if it is not selected there and then from search we can search ec2 here click on [Music] ec2 okay so this is the E2 dashboard so from here just click on the instance from the left menu where you will be able to see if you have created any instance for the ec2 So currently I have not created any instance so let's go and create it so click on lach instance then from the here we will select this checkbox okay free tire select it so I can go with uh the more CPU let's say T2 medium where I will get two CPUs and 4 GI memory so that is enough for demonstration purpose so click on this next configuration instant details so here we don't need to change anything okay number of instance I'm going to create is one right so let's directly click on the ad storage so on this ad storage uh it should be four minimum four okay so by default it is giving eight okay let it be eight then next is ADD tags so from here I can tag my machine so let's say AWS [Music] ec2 my AWS ec2 okay okay so from configuration Security Group you can create the different Security Group here so by default they have already added this rule SSH because we we are going to access this remote E2 instance uh through the SSH okay so port number 22 is for SSH service okay so from here we are going to access so from Source we can select my IP only because I'm going to access this machine from my laptop right so this is my ip6 2110 25289 okay so from this IP I'm going to access my remote machine okay so this is local machine IP okay so after adding public IP click on review and launch so we need to connect to this remote machine from our laptop right so for that purpose you can use existing key that I have already created or if you want to create a new one uh I can create from this option create a new key PA so let me give some name my AWS key click on download so it will download this file uh file name pem extension okay so once it is done we need to click on launch instance okay so it will launch it will start our AWS instance so we can go here using this view instances so once our machine is up and running then we will uh connect to this E2 instance okay so now our E2 instance is ready so now we can connect to this E2 instance so for that purpose just go to the download folder where you have downloaded your key so from here I will open power shell so just run this command SSH space hypen I then give your file name so my file name is okay with the extension not only file name my aw key.pem space ec2 d user okay so this is the by default user uh that will be created for our aw2 instance atate uh here you need to give the public IP of your E2 instance okay so that you can get from here just click on this instance ID and this is your public IP uh vort address okay so this IP will require so I will copy that IP here paste it and hit enter okay so it is SK so click yes so permanently added this IP to the list of known host okay that means I am connected to my remote AWS instance now so you can become uh root user here sud sudo Su okay now I am root user so first thing after you connect to the AWS instance it is always good idea to update your y okay so sud Y update so with the help of thism we will be able to download and install different software or different things on this aw installs okay so first let's go and update DM okay so there is uh no package for update okay no problem so we will requir Java Docker Docker compos so let me check if it is available or not okay jav command is not found means Java is not available on this aw2 okay so let's go and install the Java so just use this command to install Java sudo M install Java Das 1.8.0 Z okay D open jdk hit enter So within a few second it will install the Java Okay click yes so it will download necessary packages okay it's done now so we can verify install okay now we have Java on our e instance so next thing we will require the docker okay so for that purpose use this sudo y install Docker okay Docker is installed so we can check the docker version now Docker space ion V so Docker version is 20. 10.7 okay so we will require doer compos as well maybe let's check if it is available Docker compose and B okay doer compose command not found that means doer compos is not available here so we require doer compose also when we are going to create the doer selum grade on this machine so first uh run this command so this will install the docker compose okay so once it is installed we need to move the docker compose from local bin folder to the user bin folder on the aw cc2 so we'll run this command so move MV user local bin do compose move to the user bin do compose okay user /bin so now we need to provide uh the permission to that file okay so now if you check the doer compos version okay now it will show you the version 1.2 26.0 so until now we have done uh with the steps whatever things we will required we have already installed on our aw C2 so now it is time to set up doer selum grid okay so for that purpose I will use the same command that we have used in the previous sessions so for selum grid 4 uh first we will create the Hub okay so before creating Hub and nodes you need to create the network right so for network uh we need to use this command okay I use this command Okay Docker Network create and this is my network name so we need to start the docker Service First okay we have installed the docker but we need to start the docker right Docker service let me increase the size so that you can see that okay sudo Docker service and start okay it is not sudo Docker it is sud sudo Service First sudo service and which service you need to start Docker Serv so Docker start let me clear this okay so our Docker service has started now so let us create the network first okay so this is my network B for Network okay so once our network is ready we need to create the containers for Hub and nodes okay so Hub and node container should be in the same network then only they will be able to communicate okay so this is the command for creating the Hub container so Docker run hyp D hypen p and this is the port 4445 of the remote AWS ec2 that I'm going to map with the 4444 for inside the doer container so the selum service which is running at this port 4444 inside the docker container will be accessible through this port okay and this is the network grid for Network that we have created this is my container name okay and this is the image selum image from which this container will be created okay so first it will check the locally if it is uh this image is available or not if it is not available it will download that image and then it will create the container out of it and this will be my container name so just let me copy this so we are going to create this grade four and this is the image version 4.0.0 okay hit enter okay so one container is ready okay so can check that Dr PS Happ whatever running services so this is the container ID okay one container is running and it name is selenium Hub okay so it has mapped this port number 4445 to 44 44 okay as per our configuration so our Hub is ready okay so we need to create the containers for different nodes okay for Chrome browser Firefox opera on which we can run our selum test cases okay so let us create a few containers okay so for no containers I need to use this command Okay okay so this is for Chrome node one okay so for grid four we need to use some extra things here okay so publishing or mapping Port is same your network will be the same right so only few things are different this SE event bus host so this is my Hub name okay so this is for creating the relation or connecting nodes with the Hub container okay then SE event bus publish port 4442 and SC event bus subscribe Port 4443 okay and this will be my container name okay and this is the node Chrome 4.0.0 image okay so out of this image our Chrome node container will be created okay so again it will go and get that image and it will create the container out of it so it will take few seconds okay our container is ready Chrome container so first let's create the container for Firefox so this will create the container for Firefox so we will have one Hub container connected to the two node container one is uh Chrome container and one will be Firefox container okay so let's check the running services Dr pson a so you can see we have three containers up and running one is selum Hub one is Chrome and one is Firefox okay so now we can uh see uh we can access the Hub Service uh on the port number 4445 so 590 is your VNC service running at the 59 and no VNC service will be running at 79 inside the doer container okay so we have mapped that port to the 4448 okay this is the no VNC port and DNC service 59 is mapped to the 4446 so I think I have not published or mapped any port for 59 for first container and for second container I have just published uh the BNC Service Port okay so what I can do is I can publish some port for both the services so what I can do is I can publish uh any other Port let's say 4447 uh mapped with 790 okay just give Hy p and for this note i p 4449 ma with 90 so let me first remove the running containers and we will create the container again okay so I will go and create these containers again okay so this time it uh did not download any image right so image is already available locally so it will directly create the container out of it okay okay so now we will see uh it has mapped this 590 port to the 4449 and 4446 okay and 790 port to the 4448 and 4447 so for for accessing VNC service you will require VNC and for accessing no V service you can directly access it from the browser itself so first of all let's try to access access our selum Hub service at 4445 right so to access all these Services we need to use this public IP of our machine okay so this is my public IP V4 address so I will copy that IP and you can paste it here colon 4445 okay so currently I'm not able to access that service because I have not added any Security Group so if you remember in under security group we have already added a single rule that is by default added by thews for the accessing the service s service to double double2 port number okay so we need to add one more security uh rule here inbound rule so that we'll be able to access uh this uh H service or no service from the different ports okay so what I can do is I will click on the security group ID okay and uh I'll go here edit inbound rules I will click on this add rule okay so from this drop down type drop down you can create a custom TCP rule or you can select this all TCP so if you select all TCP it will give you all the TCP Port range from 0 to 65535 okay so maybe uh I can create a custom TCP rule here because I don't require all the ports okay so whatever Port I am mapping or publishing are only around 4446 is and last one is 4449 okay so I can give the range okay I can give some range here 02 let's say 4 4 5 maybe I can change this also 444 4 2 4450 okay and from The Source I'm going to taes from this from my machine right my IP so I will select that IP and click on Save rules okay so new rule uh added in the inbound rules okay ipv4 custom TCP and this is the port range so only the port from this range will be accessible okay so I have published only the ports between this range right my last port is 4449 and from this uh machine this is my local machine IP from where I'm going to access different Services right so now if you refresh the page you'll be able to see this s service we are able to access from this 44454 right and this is the IP of our AWS ec2 instance okay so IP of AWS E2 instance col 4445 whatever Port you have published so let's go and run some selum test cases on this selum grid so we have already created uh this project okay in the previous session we already seen that so from this test in XML file I'm going to run two test okay so from here I'm sending this parameter browser equal to Chrome so one test I'm going to run on the Chrome browser and uh the method it is going to run is this okay this is the method name and second test for second test I will use the Firefox browser okay so we have one Chrome on Firefox and let me show you the drum GD test okay so here just we have used the parameterization in the test concept okay so browser parameter I'm going to access from the test x file I will pass the value for this browser and I will use that value from here so if it is Chrome then I will set up the capability for browser set browser name equal to Chrome browser type. Chrome okay and execution will start on the Chrome browser uh if it is Firefox then it will start on the Firefox and then with the help of remote web driver we will be able to uh run our test on the remote machine okay so currently my remote machine is my AWS instance and it will have some IP right okay so what is my IP and where my service is running at Port number 44 45 okay so I will copy this whole thing up to the port number okay so this is where my selenium Hub is running so I will provide my selenium test to the selenium Hub right so what will happen is we will run our selenium test cases so Hub will receive that test cases and depending upon your browser type it will forward those request to the nose Okay so if it is Chrome then it will run selum test on the Chrome browser if it is has to be run on Fir foox then it will run on the firo browser okay so this is my aw instance IP colon 4445 so in the we are just opening the google.com and we are going to assert the title Okay Google title okay so we are going to Simply open Google and Linkedin and we will check the title okay so if your machine is up and running everything is correct it will start running your selum test so one is running on Chrome one is running on the Firefox okay concurrency 100% so you can see session here one is running on the Chrome one is running on the Firefox so this tests are running in the parallel mode because I have said this parallel equal to test right that's why they are running in the parallel mode so we can uh run this test and let's see how we can access do the line monitoring of the test cases through the no VNC and VNC service okay so first let's see through the uh VNC service so for that purpose we will require VNC VI so to access this VNC service I just need to give the IP of remote machine and port number where VN service is running okay so for first container our VNC service is running at 4446 okay we have mapped this port so what I can do is let me copy this whole thing okay and we don't require this sttp here okay so it will ask you for the password so just type secret okay so this is the Linux container grid container and uh 4448 4449 is for box container okay so now I'm able to access uh the VNC service which is running inside the docker container so let's go and run the selum test again okay so yeah so Firefox uh browser has open it has opened the linkedin.com and on the Chrome we have open the google.com and we are checking just the title of the web page okay so this is how we can do the live monitoring through the VNC service by using this VNC VR okay so let's uh run this one more time and we are going to access uh no VNC service now so to access the no VNC service again I will require the IP of dc2 instance so let me copy that again instances okay copy that IP and which board we have published uh the Chrome node no service will be accessed to this 444 right so remote machine IP colon 4447 okay so this is the NOC click on connect here also you need to provide the same password secret okay so we are able to access this service in the browser itself and let me access the another container VNC service so that is the code number 4448 Okay click on connect secret okay so now when we run our selum test cases we will be able to see line monitoring from the browser itself okay so why we are able to access this because we have published or we have added this Security Group so let me run this again so selum Hub has provided or forwarded one request to the Chrome container so it has gone to the go.com and one request on the Firefox container okay so we are able to access it to the no VNC service so you can monitor it you can uh click on any link also okay so that means you can uh interact with the browser also through the service so once our work is done uh we can stop our E2 instance I will select this checkbox and uh go to the instance St and I will terminate it okay so I don't require it so I will click on terminate so as a summary for this session if you want to run your celum test on the do gr on the aws2 that is the remote machine then simply you just have to create the account from AWS okay log into the AWS console then uh launch in E2 instance okay select the E2 instance free tire select a memory and Security Group okay when it is added you need to launch the instance okay so before launching it will ask you to create the P file so with the help of this key we will be able to connect to that remote instance okay with the help of s and once you connected to the that remote machine then you will install the necessary software okay Java dock doer compose and once it is ready then we can set up our Docker selum grid using the docker commands simple Docker commands and once that configuration is up and running then we can run our testes in sequentially or in parallel mode as well and this is important you can access uh live monitoring by accessing the VNC and no VNC service hi guys welcome to the next session in s Docker Series so in this session I'm going to cover how to set up doer G on aws2 instance using doer compos yl file so we are going to follow the same steps as the previous session only difference here will be how we are going to set up Docker selum GD okay so previous session we have used different Docker command for setting up our selum grid architecture in the docker right so for this either you can use the docker commands Okay or you can use this Docker compos VL file okay so there are many advantages if you set up your selum grid with this doer compos VL file so for for S GD architecture we will require the Hub service okay and then we require different node services for Chrome Firefox then Opera and there should be a by directional communication between all the services also we required to map the different ports also for external connectivity for accessing VNC and no VNC services from outside of the container right so all these things you just have to mention in a file okay so that file as a Docker compos file and by running a very simple Docker command you'll be able to start all these services within few second and another big Advantage here will be you can you will be able to scale your services for example if you want to create multi containers for the same service you can do it very easily so only main task here will be you need to create the docker compos file for creating the docker selenium grid okay so that we have already seen uh in detail how you can create it in the previous sessions okay so I am going to directly use that file this time and we are going to set up this selum grid architecture on the AWS ec2 instance so first let's log into our AWS account and get our E2 instance ready okay so once you logged in into your Amazon console you can click this recently visited link or you can search here ec2 then then from this instance we can see there is no instance created so let's click on the launch instance so from here we can use this pre Tire eligible okay this is amaz Linux 2 Ami so maybe uh we can use another machine where all the other thing me Java Docker Docker Compass are already installed so if you use this this machine do not have any Java or Docker or Docker compose so you need to use different commands to install this software first before setting up our Docker selum read okay that we have seen in the previous session so let's try to search other Ami which which have pre-installed Java Docker Docker compos okay so I will simply search here Docker compos so I think this machines already have this uh build key Docker Docker compos already there okay so let's try to use this machine now so let's click on the select okay so let's go for T2 medium configure instant details so number of instance is one right so no need to change anything here okay directly click on ADD tags Security Group so under this Security Group you need to add different inbound rules okay so that you can access VNC and no VNC so I will click on ADD R and from this you can select all TCP or custom TCP and I will give some Port range let's say Z or as I'm going to use the docker compose what I can do is I will select all TCP okay so why I'm selecting this all TCB is because I'm going to get this whole Port range okay 0 to 65 535 so as we are going to use the docker compos file for starting different services for our selum breed uh the whatever Port it is available for that Amazon ec2 instance will be mapped to the docker container Port okay so I'm not sure what port it will be mapped right so that Port will be in between this range 0 to 65 535 okay so you can select this alt TCP and this is the by default range it will provide and from Source I'm going to access it from the my PC only means my laptop so this is my local machine IP and launch so click on the launch so from here I can use any existing key PA or I can create a new key pa okay so I will use the existing one so I have already created this key in the last session my AWS uh key yes I will use it launch instance okay so within a few second our Amazon ec2 instance will be ready to use so click on view instances so instance state is now running okay that means our amazon2 machine is ready to connect so let's click on instance ID and this is the public IP V4 address okay so using this address we can connect to this Amazon e instance that is the remote machine from our own laptop so let's connect to this remote E2 instance from our local machine so just go to the folder where you have downloaded thep file from here I will open the power shell so just run this simple command SSH okay so we are going to connect to that machine using SS and Pam file SS space hyen I then the file name space E2 user so this is the by default user created at the give the IP of your Amazon ec2 instance so my public IP V address so just copy that address and test it here okay so now we are connected to our remote E2 instance now so it is saying run sudo Y update to apply all the updates so once you connect to your remote machine it's always good practice to run this command sud Y update okay so with the help of Y we can install another or different software whatever you required on this amazon2 instance okay so after completing let's try to see if Java Docker doer compos are available or not then let's check the docker version Docker version 70 is already available and let's try to find the docker compos okay so do compos is also available okay so all the things whatever we require to create and run our test cases are already available and pre-installed on this amaz instance if it is not there I have already shown in the previous session how we can install Java Docker and Docker compos if it is not available so let me click this first okay so now we just need to uh run the docker compost file so first let me show you the docker compost file that we are going to use so this is the selum uh selum G doer compos file and in this WL file I have mentioned the different services that I want to create okay under the services so first of all I need a hub service okay so Hub service will be created means the docker container will be created out of this image okay selenium slub 4.0.0 and this are the ports I'm going to publish okay this is the container name then another service I required will be the node services so different noes I'm going to create our Chrome service okay so that container will be created out of this image right and these are the ports we are going to publish so 90 is for VNC and 790 is for accessing the new VNC service which is running inside the docker container and different environment required we need to mention under this environment key okay for connecting this node to the hub service and this service is completely depend upon the Hub service right so similarly we have mentioned the Firefox service and H service so all these three node services are completely depend upon this Hub service okay so this is the simple Docker compos file that we are going to run so this file is currently available on my local machine and I can run this file and create the S grid architecture on my local machine on the docker but I want to create this architecture on the remote machine not on my local machine right so first I need to create this file on my ec2 instance remote machine once this file is available there then I can simply run a Docker command to run this file so first step is to create this Docker compos file on the remote machine so currently if I see what are the different files available on my remote machine okay there is only one directory Docker directory okay so first I need to create this Docker compos ml file and we will uh simply copy and past this content into that file okay so for creating any file on your remote machine use this command touch and for your do compose you this file name Locker compose do yl okay so this will create an file in this current directory see now this file has been created so this file is a empty empty file now okay it do not have anything so what I have to do is I need to open that file in editor okay and we will simply copy all this content and paste into that file okay so once you are done press Escape then call on WQ okay so now our doer compos file is ready on our remote machine so we just need to run this doer compos file for starting all those Services okay so within a few second our selum grid architecture will be ready in our Docker on Amazon e instance so to run this Docker compos file simply run this Docker and compose space up okay so first it will start a default Network okay and then one by one it will start uh creating the services so for starting or for creating the services it will require the images so it will download whatever image you have mentioned in your doer compos file okay so for Hub service it will go and download this image and then after downloading it will create container out of it okay and same for other node services okay so these images will not be available locally at the first place okay we are setting the selum grid architecture for the first time right on the E instance okay so that's why these images are not available locally so it will go and download this images first okay it will pull the images and then create the container so until all the containers are ready let me show you this ports mapping so here we have publish all these ports for the Hub service and for creating the containers for the node Services uh we have mapped 59 and 790 with whatever Port available okay so here I have not hardcoded any port for the host machine okay so I can map like this also but if you map like this that will be hardcoded value and if you want to scale this service okay if you want to scale means if you want to create multiple container for same service it cannot map the same port right for the multiple services so that's why I do not mention any port hardcoded value here it will Docker will map whatever Port available at that time from the host machine to the docker container Port this 59 and 790 so I think all the services and up and running now okay so let me open another window for the power shell so first let's check the running Services PS I so you can see we have this sub service and three node Services Chrome Firefox and age and let's quickly see what are the different ports it has MA so 590 Port mapped with 32773 okay so this is for first container for second container this port has been mapped and this is for third third container okay so it has a randomly selected Port whatever available at that time and same for the no VNC Services okay so to access this sub service I will simply go to the browser then I need this IP right so I will copy this IP for my remote machine so that IP colon 4445 okay so this is the port and this is the IP where my selum G Services running and these are the three nodes connected to our selenium Hub okay so we have Firefox one is Chrome and one is age okay so you can simply run your selum test cases on this browsers now okay just provide your selum test cases to the selum hub running at this address okay and that Hub will uh forward that all the request depending upon your browser type to the Firefox Chrome and age so now let's uh run some selum test cases on this noes so we are going to use the same project that we have created in the previous session so I will simply provide uh the address where my selum Hub is running okay so my selum Hub is running at this IP and this is the port number so we will simply copy it and Ed it here okay and through test n XML file I will provide the browser name so this test should run on the Chrome second on Firefox I will run this third test on the ede another we have on the Chrome okay so currently we have four test so two will run on the Chrome and one on Firefox and one on H browser okay so test are running so we have this two two session for the Chrome so two session will run at the same time so you can monitor all this test also by accessing your no VNC service from the browser or VNC service from the VNC viewer okay so let me show you the no VNC so for that purpose you just required the port number so for no VNC service the 790 is mapped with 32772 okay so we require this port number if you want to access the no service from the browser so I will use the same okay so we require the remote machine IP colon whatever Port uh the docker has mapped so we'll use this 32772 32772 so add here secret and another one is at 32770 32770 3 2 7 6 8 so let us run the uh test again one more time okay execution has started so this is the Microsoft age Firefox and Chrome browser okay so this is the live monitoring you can access and see how your test running you can interact with the browser also okay so with the help of doer compos file I can very easily scale these services so currently I only have one Chrome one Firefox and one age so I can create multiple instance for this chrome fire fox and age by scaling the service okay so what we can do is uh okay let me connect to our machine again okay so I will take this configuration down first so use Docker compos down okay so it will take all the servic it will stop all the services okay and again I will use doer compose space up and then use this black scale and provide the service name you want to scale so from our Docker compos file we have Chrome service we have Firefox service and a service so let's say I want to scale this chrome service I will copy that service name Okay Chrome service and I want to create let's say uh two instance okay we can scale another service also scale let's scale this Firefox service also equal to let's say three so we are using the same command for running the doer compos file but only we are mentioning here the scaling means using this scale flag I want to create two instance for this chrome service and three instance for the Firefox service space I will use the mode this time so within a few second our architecture will be ready okay everything is ready now so you can check that doer PS iphon a so now we can see we have multiple nodes now okay so we have Chrome service one Chrome service 2 and for Firefox we have one two and Firefox 3 right and for age we have only one container and same we can verify from the browser okay so here you can see we have uh two Chrome and uh we have this three Firefox okay so as we will have the multiple instance for this node containers how can directly uh forward this request to the whatever available nodes okay you do not have to wait for current node to get free okay so it has to Chrome it has three Firefox so three test can be run on in parallel mode on these three Firefox browsers so you just need to follow this simple steps okay create account for AWS if you not created and launch the ec2 instance okay so while launching you can create a free tire machine but there you may require to download and install Java Docker Docker compose okay but if you selected an e instant which have all the software pre-installed then you don't requir to install it again you can directly create theer compos file and run it okay so you just need to uh connect to that remote2 instance uh get the uh public IP vort address of that machine okay and connect with the SSH okay so for that purpose first uh download the Pam file and with the help of that Pam file you will be able to connect to that remote machine and once you connected you just have to set up this doer selum grid by using this Docker compos VL file and you can do this live monitoring by using the your remote machine IP and whatever Port you have M for this VNC and no VNC Services okay and for scaling any service from the doer compos file you just need to use this command Okay scale flag Locker compose up and use this scale flag then provide the service name equal to whatever uh number of instances you want to create okay so you can create multiple or you can scale multiple services at the same time so within a few second whole selum G architecture will be ready for use okay and then you can run your celum test cases hello guys welcome to the next session in selum G doer Series so previously we have seen how we can set up the selenium Grid in the docker and how we can run our selenium test cases from local machine or in the AWS is to instance as well okay so now uh we are going to see how we can record the test execution which is happening in the docker container okay that means if you are running your uh test cases selum test cases on the docker on the Chrome browser or Firefox or age browser so I need to record that test execution so that it will help me to debug any issues okay related to the application so normally we run our test Automation in the night only right so when we are in the office we will get the test case execution report okay automation report so in in night we cannot do the live monitoring for each and every test cases right so if any test cases is failing and if we turn on the uh video recording for that s Cas then we can easily able to see what exactly happening uh while watching that recorded video right so this will definitely help you in your realtime project as well so what you have to do is you need to follow the simple steps you need to create a Docker compos ml file and we need to add the required Services okay so we have already created the docker compos file in prev sessions so same you will see how we can use it and uh we need to set up this Docker grid with a Docker compos file okay then we will run our selum test cases and once our test case execution is done we will get the recorded video on our local machine okay so let's start now so this is the doer compos file we are going to use for this demonstration so here I added two service one is for our selenium Hub service okay this is the Hub service and another one is for Chrome service okay so I will show you how you can record the test execution happening on the Chrome browser and same step you need to follow for recording the video on the age browser or Firefox browser okay you just need to add those services in this doer composer file okay so in Hub service what we have for creating the container for our Hub service I have written that use this image okay so on local machine if this image is not available it will go to the docker Hub and it will pull that image and it will create container out of it okay so these are the ports we are exposing so our selenium grid the selenium Hub will run on this 4445 okay so you'll be able to access that service from this local machine 4445 Port okay then we have added the Chrome service for creating our Chrome node container okay so both these services will be created these two containers will be available in the same network okay same Docker Network so that they can communicate so for creating the Chrome node this is the image that it is going to use okay this is the latest Chrome service or Chrome node image available on the dockerhub and these are the ports we are exposing okay so 59 and 79 VNC and no NC ports and these are the environment setting you need to add here okay so this chrome service depend upon the Hub service okay this Hub service so for recording the video on the Chrome you just need to add this service so for this service this is the service name Chrome video and this is the image it is going to use selum video FF MP EG okay this is the latest image for this service okay and these are the volumes okay so here we will get the video in this uh folder only okay do/ test recordings so this folder will be created in our uh local machine where your doer compos ml file is available okay so there it will create this folder automatically and whatever video recording you will get at the end of test education that will be available in this folder in the MP4 format okay so this service depend upon the Chrome service right and these are the environments so our display container name is Chrome service okay so this is this is for Chrome so we need to record the video what is test execution happening on the Chrome browser so you need to provide the Chrome service here and this is the file name so you can give any file name here okay test on Chrome video 1. MP4 so this will be the file name after testation is done okay so this is done for the Chrome browser so if you want to record the video on the age browser or Firefox you can so you need to follow the same approach you just need to add the a service Firefox service and then age video and Firefox video okay in similar fashion so now let's go and create and run this Services okay by running this Docker compos file okay so just go to the location where uh this Docker compos file is available so this is the location so from here I will open my power shell so before running our doer compos file you need to start the docker desktop application on the Windows machine so I have started this Docker desktop application so Docker engine is up and running now so to run the docker compos file we just need to use this command Docker compos space ipon f and just provide the docker compos file name yml and up and hyen D okay so first it will pull all the images first okay so currently all these images for Hub service Chrome service and this Chrome video service are already available on my local machine okay so in your case it will go to the uh Docker Hub and pull all these images okay all these are the latest images okay so it will take some time in your case and when all the images are downloaded then it will create the container out of it and it will start all those containers okay so if you see all the running containers now so these are the containers these are the images out of which these containers are created okay so here you will see different ports that are exposed okay so we can access VNC and NC service from these ports using this port number okay so let's see first our Hub that will be accessible on our local machine so just type 127.0 do1 colon 4445 okay so this is our selum grid up and running and here you can see one Chrome node is connected so if you added the service and Fox service those nodes will also be shown here okay so now let's go and run any one selum test case on this chrome node and we will see how we can record the video now so this is the project we are going to use so same project we have used in our whole playlist right so here what we are going to do is we are sending the browser parameter from the test n gxml file for our test case Okay so depending upon the browser parameter we are going to set the capabilities for the browser type okay so if it is Chrome then we are going to open the Chrome and our test case execution will start on the Chrome okay if it is Firefox then it will open the Firefox and if it is age then it will set up the browser capabilities to the age okay so once it is done we need to set driver equal to new remote driver and here need to provide the IP okay so currently we are running on our local machine so in case if you are running on the AWS instance you need to provide that public IP over here okay so 127.0.0.1 4445 okay so this is the location where our selenium Hub service is running okay so once it is done we will provide our selenium test Cas to the selenium Hub so depending upon the browser type selenium Hub will forward the test case execution request to the particular node so if it is browser then it will send a request to the Chrome node if it is Firefox then it will send the request to the Firefox running node so in the test what we are doing is you just simply opening the google.com we are asserting the title of the page and we will search One String here in the Google search box okay automation testing and we will click on the search box okay so after waiting 5 Second we are going to get the text of the first link okay so whatever result will be shown after you press the Google search then you will get some result and from that result we are going to print the text okay whatever text we are getting at the first link in the console so this is the simple test that will happen or that will run on the Chrome browser and that same execution we need to record so for running this test test you need to use the test ngml file so here I'm sending this parameter browser and Val is Chrome so for this test we are going to run this method Google Chrome test so before running the test case make sure your helenium Hub and all the containers and up and running okay so we have seen that from the power shell and same you can see from the doer desktop application as well okay so you can see the logs as well okay so for the selum video container you will see this is the location where we are going to get the video inside the container okay same video will be available in our local machine so on the local machine if you see inside this folder we have this Docker compos file okay that we have run so you can see this folder is automatically generated and we started that container okay so inside this container you will get this video with this name okay so currently this video is empty okay so let's go and run our selum test case and it will record the video so test execution started on the Chrome so on the grid you can see one session has started and you can do the live monitoring from here also so just add secret here automation testing and it will get this text the first one so after waiting 10 second we are closing the browser so in the console let's see if we get the output okay so here you can see text is automation texting tutorial what is automation testing okay so our test case execution has done and now it is time to see the recorded video so this recorded video is not ready so we need to stop that video recording container so that video will be available on our local machine okay so we'll need to stop the container for this video okay so to stop the container just use Docker stop and use the container ID that is 17 okay container has stopped now so now if you go to the local machine now you will see 4.64 MB file so just open this video in v player so you'll see actual time for this video is 9 minute okay so it has started the recording when we start our containers okay so it has open the Chrome browser it will go to the google.com search the automation testing and it will face this first link okay so this is the test case execution that actually happened on our Chrome node okay so it is very helpful feature from the selum grade of grade four okay so that you can record your test Cas execution which is happening in the night automation okay and using the videos that will definitely help you to debug the issues okay so I have shown you how we can do it for the Chrome so we just need to add the different services for the age and Firefox in the doer compos file and add the a video and Firefox video similar to this okay so that video will be available on your local machine under this whatever folder name you have provided so this folder name will be autogenerated on our local machine and you need to stop the container first first okay so before stopping the container you will not be able to play that video okay so using Docker stop and container ID you need to stop the container and then that video will be available on our local machine
Info
Channel: AJ AUTOMATION
Views: 1,196
Rating: undefined out of 5
Keywords: docker selenium grid, Setup Docker Selenium Grid from Scratch, Setup Docker selenium grid on AWS EC2 instance with docker compose, Run Selenium Tests on AWS EC2, selenium grid, selenium grid tutorial, selenium grid parallel execution, selenium docker, docker selenium grid complete guide, docker selenium grid full tutorial, Complete Guide: Setting Up a Docker Selenium Grid, Step-by-Step Tutorial: Building a Robust Selenium Grid with Docker, Master Docker Selenium Grid
Id: jX2Dmk6ts8A
Channel Id: undefined
Length: 189min 8sec (11348 seconds)
Published: Wed May 01 2024
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.