How to run Selenium C# Automation Testing in Docker

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
in today's video we're going to talk about selenium testing in Docker so first let me introduce Docker Docker is a platform designed to make easier to create deploy and run applications using containers containers are these things that allow developers to package an application and its dependencies into a standardized unit for software development and this can include everything needed to run the software for example the code the runtime the system tools library and Etc so here are some things that Docker allows you to do so the first thing is that Docker allows a consistent testing environment Docker ensures its consistency across environments by capsulating the testing setup dependencies and configurations within containers this consistency minimizes issues related to differences between development staging and production environments Docker also allows for isolation and reproducibility each test can run within its own isolated container ensuring that the test environment is reproducible and separate from the other test runs this isolation prevents interference between tests and enhances reproducibility some other things that dock allows is scalability Docker enables easy scaling of test automation by allowing the quick deployment of containers tests can run in parallel across multiple containers facilitating faster execution and enabling efficient use of resources Docker is also easy to set up and configure Docker simplifies the setup process for selenium automation testing with pre-built Docker images containing selenium and the browser configurations setting up the testing environment becomes straightforward reducing setup time and complexity Docker also ensures resource efficiency Docker containers have a minimal footprint and consume fewer resources compared to Virtual machines this efficiency allows for running multiple tests simultaneously on a single host without a significant overhead now let me talk about some advantages of using selenium testing in docker so the first thing is portability and reusability Docker containers are portable allowing the easy transfer test environments across different machines or cloud services this portability enhances the reusability of the testing environments making it convenient for sharing among team members the second is Version Control and image management Docker provides Version Control for images ening enabling easy roll back to previous versions if needed it also allows for the creation of custom images providing flexibility to tailor this testing environment as required finally integration with continuous integration pipelines dockerized selenium tests integrate well with the ci- CD pipelines the container-based approach allows seamless integration of tests into the build pipeline automating test execution and enabling faster feedback on code changes so next I will tell you uh and give you a brief introduction on how you can install Docker on your own computer the first thing you have to do is you have to go to this website and once you get to this website you can just download for your uh computer so I have uh downloaded already so you can just go ahead and download it and follow the link and instructions after that what you can do is you can go to your command line and the first thing you have to do in your command line is you have to pull the images so what you should type is Docker pull selenium Das Standalone Chrome and so this is where Standalone Chrome this is for Firefox and this is for Edge and so you run all three of these lines so Standalone Chrome Standalone Firefox and stand alone Edge you can also run these as well um but you can just run this after you pull the images now you're going to start the standal that we just pulled and so you just run Docker run and then you uh have some specifications on the port uh as well as the shm size and then the stat alone that you want to run so we have stand alone Chrome here but you can also use Standalone Firefox or Edge now the next thing you can do is you can pull some more images and so Docker pull you can do uh node Firefox dbug and you can get all the notes for Firefox Chrome uh and uh and then you have another fire firef Fox and you have a hub and after that you can start your Hub and your nodes and so what you do is you use Docker Network create grid and this creates your Hub node grid for selenium and after that you can start your Hub and node uh using this Command right here and then using these commands below you can connect your hubs with your nodes and you can go ahead and begin with your own selenium project in docker so now I will show you the code implementation for Docker using C and so I've already done all the pulling of the images and starting the Stalone and nodes and hubs so if you haven't done that already go ahead and pause the video right now and follow the instructions previously to pull the different images and download the different stal loon and hubs and nodes and start your own standal so after you've done that uh now I'm going to show you the selenium C code that I have so the first thing that's different about this project is that we have to use this dependency so using open qa. selenium remote and other than that really the only thing that differs using uh Docker is the setup process the different test that we have is very similar to the also uh to the other test that we've done previously so I'm really going to focus on this setup method that we have right here and and so um we see that there's a few of the same different uh Global variables that here we have iweb driver which we had before extend test which we had before as well and now we have a different thing and this is grid URL and this is something new and so if we go to our setup right here we see that we specify our grid URL to some local URL and in this one we have the port as 9999 for the Standalone the next thing we specify is the options right here and we say that we're going to use Chrome options and after that together we're going to come to here and we're going to specify a driver and this time instead of saying Chrome web driver we use remote web driver and in the remote web driver the first parameter we have right here is grid URL and this is what we specified up here so the Local Host 9999 and then the second is the options which is what we specified as Chrome options in the second line and together what this does is this creates a remote web driver using uh at the web URL so the the port 9999 and then using Chrome options so it uses Chrome so after we finish that setup process everything else pretty much remains very similar so for example in our search test right here uh we go to uh the golf URL that we specified and uh what it'll do is it will search for this golf course and down here it'll also select for other things inside the web page so I'm just going to run one of these tests so I'm going to go ahead and run search test here so right click go ahead and run test right here and we'll see what happens so first allow it to build and we see that it's running golf Standalone right here so this is for a standalone and it finishes running and it's successful now if I close this right here now I can show you something else so now I'll show you how we can use node and basically what we have is we have two different nodes so we have the docker node for Chrome and Docker node for Firefox first let me show you Chrome and then Firefox so again right here we use the uh open qa. slam. remote right here and then we specify the port that we're using Chrome options and then we use remote web driver to specify the web driver in the setup now what this does is this basically sets up our Hub at 4444 and I'll just show you what it looks like right there so this is our Hub and we see that it's at 4444 and after that basically all the different nodes and stuff they'll automatically connect to this Hub because of how we specified when we started our darker environment and so now if you want to run the same test right here you can go ahead and just right click this run test and it's running the Chrome node right here and if I open this for example we can see that there's a node running right here but it's still running it doesn't give any popups this time but if we look over here we see that it's running uh this node is running on our Hub and it finishes running that so that's complete now that's for Chrome now let me show you Firefox so Docker node Firefox everything's the exact same except right here we use new Firefox options as the web driver so when we do remote web drivers and our options is Firefox options this gives us um our test in Firefox instead and so if I go ahead and run this first method again so it's running this method uh give it a sec now it's running so now if I go to Firefox right here um and I go to uh right here we see that there's a Firefox one that just started right now and it's running in Firefox and we see the previous one it was running a node in Chrome so we'll give it some time to run and now we see that it's complete and so yeah this is just a very simple introduction on how you can uh run using St alone which we have here or you can use the no and hub architecture that we discussed previously and um so you can have nodes with Firefox nodes with chrome and so on and uh you can run your own test well I hope this uh video was helpful uh in uh introducing a little bit of Docker and how you can do selenium testing with Docker if you found this video helpful please give this video a like and follow our our channel uh thank you for listening and we look forward to see you next time
Info
Channel: Test Automation 101
Views: 1,747
Rating: undefined out of 5
Keywords: Docker, SeleniumTesting, DockerContainers, DockerizedTesting, Test Automation, C# Automation
Id: sPVXEBPK_kI
Channel Id: undefined
Length: 11min 41sec (701 seconds)
Published: Mon Apr 01 2024
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.