Run selenium automation testing in Docker

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
Welcome to our ADM Lucid automation testing Channel we will have a series of talk about selenium automation testing which will help you understand the basics of selenium and also guide you to build your own selenium automation project you may access our test project and guide in the description below feel free to subscribe to our channel for any new videos and updates in today's video we will talk about selenium testing in Docker so first what are the advantages first I'll give a introduction of Docker and I'll talk about some advantages of using Docker so first Docker is a platform designed to make it easier to create deploy and run applications using containers containers allow developers to package an application and its dependencies into a standardized unit for software development which includes everything you need to run it so it's code the runtime environment the system tools and libraries and Etc and so some advantages of using Docker first is a consistent testing environment Docker ensures consistency across environments by encapsulating the testing setup dependencies and configurations within containers this consistency minimizes issues related to differences between development staging and production environments the next is isolation and reproductivity uh uh and the ability to reproduce it so each test can run within its own isolated container ensuring that the test environment is uh reproducible and separate from other T test runs so this isolation that you have it prevents interference between tests and enhances uh the reproducibility so some other advantages is the SC scalability of Docker so using Docker enables easy scaling of test automation by allowing quick deployment of containers tests can run in parallel across multiple containers facilitating faster execution and enabling efficient use of resources furthermore there's easy setup and configuration so Docker simplifies the setup process for selenium automation testing with uh pre-built Docker images containing selenium and browser configurations um setting up the test environment becomes very straightforward and it reduces the setup time and the complexity also there's resource efficiency so Docker containers they have minimal footprint and consume fewer resources compared to uh virtual machines and this efficiency uh allows for running multiple tests simultaneously on a single host without insignificant overhead cost uh and there's also some other r anes such as portability and reusability so Docker containers they're portable and they allow the easy transfer of test environments across different machines or cloud services uh this portability enhances the reusability of the testing environment uh and it makes it convenient for sharing among team members there's also Version Control and image management so Docker provides Version Control for images enabling easy roll back to previous versions if needed it also allows for the creation of custom images uh providing flexibility to tailor the testing environment as required and finally uh using Docker allows integration with continuous integration pipelines so dockerized selenium tests integrate well with these continuous integration pipelines uh the container based approach allows seamless integration of tests into the build Pipeline and automating test execution and enabling faster uh feedback on the code changes so those were some advantages of Docker uh I'm sure you can find many more online uh but how do we run uh Docker so first you have to download and install so you just follow this link and you can just download and install and follow the uh follow the steps on their website uh once you download uh and installed Docker you can go ahead and run these commands uh for the purpose of time we're not going to run it in this tutorial but you can pause the video right now uh before you move on and try to download Docker first and after you run these Docker pull commands there's also um another command you should run called start stand alone and this basically starts your Docker session so so you just uh you can run uh this depending on which web browser you want to use it on so this one is for Chrome this one's for Firefox and this one is for Edge okay so now that we installed Docker I'm just going to show you how we can uh start running this so remember in the previous slides there was a bunch of commands I'm just going to use a few of those commands to show you how we can start a stand alone and how we can uh start using docker uh right away with our test so first let's just check that our Docker is installed so what you can do is you can use Docker D- version to check that and we see here we've installed Docker version 24.02 so after we do that another thing we can check is we can use Docker PS to see what kind of processes we have running on Docker already and we see it's empty and that makes sense because we haven't added any processes yet so let's let us add a first process so I'm going to paste over this code and basically what this does is it adds a uh stand it creates a standard loone on Firefox uh on this port 4446 I'm going to go ahead and I'm going to run this and now when I use Docker PS it shows us that we've created a standard loan for Firefox uh right here and that Port was 4446 uh and so yeah so if we go to our uh Firefox we refresh uh we see that we have a Firefox stand alone right here uh in our what as one of our uh as one of our properties in the slum grid so now we can use this Standalone so I'm going to go ahead and go to our IDE and I'm going to show you this simple class that we have to basically uh use Docker so first in this class I'm just going to go to the method that uses Firefox so this homecore for Firefox and in this method basically the the first important thing we do is we create a Firefox uh options uh instance and then we add some arguments to basically just configure the options after that we do a remote web driver so we start this instance driver as remote web driver and we feed this remote URL Firefox and this URL we have right here is basically the URL we used uh right here to um access that so everything we do comes here after that we've send in our options and then uh we have that part next we also use this command called synchronized this and this basically makes it so our web driver uh the driver we uh declare up here is synchronized with the driver down here that we use in the method and essentially what we do is uh we're testing to see that we're able to go go to this URL website and uh on this website the title is what we expect it to be and so on but the important thing is we're doing this through Docker okay so once we have that uh that's the class uh that's the method in this class we'll be running uh we can go to our uh Java Docker class here and this one basically um shows right here we're running homeor Firefox and it's just very simple so I'm going to go ahead I'm going to right click and I'm going to run Docker so we'll give it some time to run uh and now it's done running uh once it's done running we made it so that it creates an extent report in our output folder and I'm going to show you what that extent report looks like and basically in this extent report we basically went to um we basically opened a Docker web driver we went to the first website that we declared to go to and then on that website we basically checked that we are on that website and we also checked that the title of the website is what we expected to and this was all done through Docker uh through right here uh uh right here as we see now the next thing we need to do is we need to download and install something else called real VNC viewer and basically this allows us to see what's happening inside Docker on our system and so you can go ahead and you can click this link uh I'll go ahead and show you what it looks like on their website uh this is what their website is all you have to do is just download right here and follow the steps for installation so after you do that um first thing you have to do is you have to pull images and these are some basic Docker commands so you do Docker pull um this is uh first it's for debugging uh so actually okay yeah so first you got to do Docker pull slum Hub and next you have to do um Docker pull these other commands for Chrome debug and Firefox debug and then you uh pull the images for node uh for Chrome and Firefox as well after you pull images now you have to start the Hub and the nodes and so to do that first you use this command Docker Network create grid so you create your grid and then you run it using that grid that you just created uh and um you see that you're using your Hub you're using your grip uh and so on uh finally after that you use this command uh and this basically just um it just creates your uh the configurations for your whole uh grid system so again uh when you start your Hub in your nodes you can use this command um and basically this is Docker run and then you have the the flag D and then you have your grid um you have some configurations here and you have your port number and your your nodes as well and this basically just connects everything together and right here we just have um basically the same command and it's just repeated again uh but this time we're using uh node Firefox debug instead of um this node that we have here and and here we have it for Chrome as well and we're using the Chrome node debug and yeah okay so now that we have everything installed I just want to show you some things that we can do to see if we have our nodes and our hubs and everything uh there properly so one command you can use is you can use Docker PS and this will basically show you all your images so your nodes for Edge your nodes for Chrome your nodes for fire Firefox as well as your hubs as well another way you can see what all the images you have is you can go to your Docker application and you can go to images right here click it and it'll basically show you everything you have and its status so we have our nodes for Chrome nodes for Firefox we have our Hub as well and we have some other nodes here as well now once you have that and you've seen everything you have you can actually go to um so for us we have this Firefox browser here so your celium grid and we see that we have our different nodes here so we have our nodes for Edge nodes for Firefox and nodes for Chrome as well so you can check those three things to see and make sure that your environment is set up properly after that I'm going to go to the IDE and I'm going to go to the class that we created called youtube. Java and in this class we basically have uh right here test grid uh and we have here remote string which specifies this URL and that was the URL that we used to see the selenium grid right here um and basically in here uh we create an instance for Chrome options we also create an instance for Firefox options Edge options Safari options and we basically set those right there uh what's different here is in our test right here test one we basically connected our uh test right here to the grid that we had by using this browser uh which is this string right here which we eventually feed in uh this remote URL we use that to connect whatever we're running here uh with that grid and basically what we're doing in these tests like test one test two and so on is we're basically opening up up these YouTube links and we're letting it run for a little bit of time so that's the code and we have a few more tests for that and what we want to do using this code is we want to run this inside in a Docker environment uh in a parallel fashion so what we can do to do that is we can actually create uh recall that we go here we go to edit configurations and we basically we can run the three different uh things we have so let me just open up these for you uh these are just basically um classes to run the test of YouTube on Chrome Edge and Firefox and we see it calls each test and so on so we can basically run these in parallel by using the uh uh the configurations right here so we go to edit configurations and this is using the the add-on for um ID uh for the IDE and basically uh uh multiun add-on by the way um and uh if you don't recall using multiun I suggest you go back to our previous video to see uh more information about multiun but yeah you basically go here you create your parallel test so right here we have these three tests here and you basically create that you click okay um and when you're running you can just run the configuration so I run all three parallel tests right here uh give us some time to load up right here and once this is done loading up we can go back to our grid and we see that these are three nodes we'll just go ahead and go to our session and it shows that it's running all three of them at once and so we can give it some time to run okay so now that we gave it a little bit of time to run we can actually we can view each of uh these nodes because we installed real VNC so how you do that is all you have to do is you have to go to the session you have here you can click on that you can enter the password so I'm going to go ahead and enter the password and you accept uh and it basically shows you what's happening inside each node so that one's that let me go to this node here uh that one ended because the node just finished running uh we see here and it basically shows you what's happening inside each node so opens up these URLs it opens up the YouTube site and it basically runs it and so on and so this is a nice way you can run uh parallel test inside Docker as well as see what's actually happening inside your parallel test next I'm going to show you how we can use um the command dock compose and a yml file to create all the different nodes and all the different hubs that you need in one command and so the first requirement to run this is we need a yml file which we have right here in the file that we have here we have three different blocks of text the first block creates The Hub and then the next two blocks create the node for Chrome and the node for Firefox within each block we have the the command that we would run uh in directly in our command line uh to create either the Hub or the node and we have this all in the yml file now in order to uh create all of this through one command we're going to use the docker-compose command and I have it right here so docker-compose DF and then we have our yml file and we're going to use up so I'm go ahead and press enter and we see that it's creating all the different things that we need now I can show you that this worked by using Docker PS and we see it created The Hub that we wanted and yeah so with that we're able to use a yml file to create all the different things that we want uh I hope you enjoyed this video and I hope this video was a little bit helpful in understanding how Docker works and how you can use it with selenium uh if you found this video helpful and if you want to see more videos from us please like And subscribe and uh we hope to see you again thank you
Info
Channel: Test Automation 101
Views: 4,436
Rating: undefined out of 5
Keywords: Docker, SeleniumTesting, DockerContainers, DockerizedTesting, Parallel Testing
Id: O3DwM6hLsQI
Channel Id: undefined
Length: 18min 39sec (1119 seconds)
Published: Fri Nov 03 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.