Selenium Framework - Part 48 - Run Selenium Tests in Standalone Chrome Container

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hi friends welcome back to my channel testing mini bites i am your friend amazon satival and today we will see another interesting topic about how we can execute our test cases in selenium standalone chrome container good so before going this going to this particular video i also want to just do a recap of the previous sessions okay so one among them uh is the key points that we need to understand from the previous video is whatever the docker image that we see in the docker hub is all built using some docker files right so and all these docker files or you know they have all the application dependencies suppose if i am running a chrome container okay this particular chrome image okay will have all all the things necessary to run the chrome image it will not depend on anybody else that's the important thing and docker container is is an instance of a particular docker image okay suppose in in java or your oops programming languages we have class you know based on the you know class we create objects right the class remains as a template for your objects the same way the image is going to remains a template for your containers okay so you can create multiple containers from the same image like the way how we can create multiple objects from the same class right in in object-oriented programming so we can just do a correlated comparison so that we can understand it better and next we have lot of docker commands right i try to you know just paste almost nine commands here and we will try to cover this in this particular video itself okay so this is just a heads up again so coming back to the agenda so we will try to do um so we will try to uh pull the stadium standalone chrome image because we need to pull those images into our local so that we can use it right so in in terms of bom.xml what we do we we add the dependencies so that it downloads all the all the necessary jar files right so same way what you know we have to pull this particular image then we need to start the container for this particular image and we'll also see how we can run the test in this particular image and we'll also understand what is spot mapping uh in detail right so and then we also see uh how we can do the parallel execution with the help of the standalone chrome container what is the problem with this particular approach we will see at the end and without wasting much time you know i'll go back to my eclipse workspace okay so good so this is a test right this is a normal test that we have written right so and this is very simple test you know what we are going to run this particular test not in our local we are going to execute in a in the docker containers okay to run this we need the containers right so we need the containers to build the container we need image right so if i go to go back here okay and this is the particular image that we are interested now right so if i want to pull this particular image okay i can directly go uh to the command prompt and write docker pull and then give this particular name okay it's selenium the author is selenium and stand alone hyphen chrome is the image again if you want to mention the tag specifically you can do that if not it will by default take the latest stack good now in this you can also mention what you're going to pull okay normally all the you know uh docker commands will start with docker and you can also mention image right so if you don't mention it can implicitly understand that you you can only pull the image right so you cannot pull a container so docker can implicitly understand that you are trying to pull an image even if you mention this or if you don't mention this that's absolutely fine but i would suggest please you know i try to use this darker image pull something like that so that it's more meaningful right so maybe docker will get rid of uh using something like this in the future so get yourself adapted to this right so good now i'm just trying to pull this particular image from this particular docker hub right so from this particular place i am just trying to pull this particular image that's what we are going to do in my case i already have this in my local okay if i you know if i remove that again and then if i if i pull it back okay it will take some time for the download okay so what if i type this all right let's see what's happening in your case it will do lot of downloads like for 600 mb or 500 mb whatever the image size will do the download in my case it it it altered you i already have this particular image so it's telling it's already available so it's already took this right so now i have this particular image in my you know local now i have to create a container i have to create an object for this particular class right the same way you i have to create a container for this particular image so to do that you can just type docker container created okay and then create is a command right so i am going to work with the container that's why i have given container in previous case we used image here we are using container so create and what i want to create i want to create a container from which particular image okay using this particular image right so you can copy this and then paste it here good now let's see what's happening so it should spin up you know it should create a container for you if you notice this is the container id that it has created okay this is the long container id it has created let's see uh you know it didn't do anything because we are just created the container we didn't used it okay so you can imagine that you have just initialized this particular object you haven't you know assigned some value to this something like that right so it is just created now i need to start this particular container okay to use this okay so i can drill docker container and start okay and then use this particular you again this this is the whole idea right so if you are not interested in giving the whole thing you can also give only half of this right so this is just to just for the darker demon to understand what is the container it needs to start now okay you can give like this if it is if you can understand okay then it is fine so it will try to start this particular container for you yes whenever it is printing you back the container id or some part of it it means that your content you know the command that you ran you know is success good now we have a container created right so let's check whether it is created or not to check that you have to type docker container and then ps okay good now it is telling yes it has it was up yeah docker docker this particular docker container was up and it has exposed the port okay um to understand this in detail maybe i will open up page so that i can give a diagrammatic representation how it looks okay suppose consider this is your uh docker all right so this is your docker okay now what we have done we have created a container okay in this we have created one standalone container okay this is your selenium standalone chrome okay selenium standalone chrome okay we have created this particular container and what it has done it has also exposed you some put okay you notice okay it has exposed to some port here this is four four four four that's what they have telling area right so if i go to this particular place it is telling it has exposed a port even you can understand this from from there this is their image right this is the details about their image this is the docker file they used to create this particular image if you notice they are exposing a port on this container okay again guys container is assume it is a machine so so what happens okay you have a machine now okay you have a machine that is exposing a port 444 because okay you if you want to run your test you need a port to delegate the test right this is the port that we are interested in so it has you know uh exposed this particular port okay now everything looks fine hey if i run this test will that will this run okay let's check friend and stingy obviously the tester will fail i will tell you the reason why okay so we are running one simple test everything looks fine right so hopefully it should work but it will not let's wait for the failure see it's telling it's it's not able to reach this particular okay you could not create a session because there may be an invalid address right it could not find the particular you know anything here okay so what is the problem okay one of the local hosts that i have mentioned here is is my machine ip right so this is my machine port 444 so i need to do a link so what happens consider this is your physical infra so this is your physical infra that is you know you can consider this your my laptop okay my laptop machine is having a port so what i am doing i am i am delegating all the selenium tests to this particular port but this is nowhere related to this okay this is this is a separate entity here okay this is a separate entity and this is a separate entity these two have no relation between them so what i need to do whatever that is coming to this port i need to delegate to this particular port okay whatever the request that is coming i need to delegate to this container port 444 so while creating the container itself we need to do this okay so it is just exposed and it is not linked to anything so now i have done something wrong now i want to stop and remove this container again guys in terms of docker world we will not try to do a lot of stuffs okay we will not try to edit it we will not know until containers like you know use and throw glass okay you use it you throw it that's it if you if you don't like it throw it back that's a you know beauty about container it's not a virtual machine where you go and fix all the errors if you don't like it just stop and remove it and then you know get rid of that particular container and use a new one so now what that's what i'm going to do i'm going to stop this particular container again guys if you notice this is a particular container that is running right so and this is the name of this particular container if you are not naming your category anything it will have its own default name all right so now i want to stop the container which container i need to stop i need to stop this particular container again if it can identify this uniquely with just this many variable letters then it's fine so it can still stop it okay it doesn't matter you know how how much length you are giving for the container id but now we stopped whenever it's printing you back the container thing so it means uh you know it's the command is success now it is stopped but it is not removed suppose if i type docker ps it will not be displayed okay again guys you can type darker ps or darker container ps both are same right so okay so now it is not displayed but it is not completely removed suppose if i say docker ps hyphen a hyphen a indicates all it will also show you all the containers even in the stop state okay this darker container ps will only tell what is the container that is in running state this is stopped okay so it is listing me all the containers in the stopped state okay guys in your case you will not see all these things because my docker is a little clumsy i have a lot of things doing so it will have all these things but you are interested in only this this is still there so i want to even remove this okay so to remove this i have to type docker container rm or you can you can mention docker container arm okay or you can simply mention docker arm okay and then you can mention the container id but once you do this it will be get removed okay now we have get we will get rid of this particular container and let me do a docker ps now you will not have anything and let me do a clear screen so that we'll have so we'll start afresh again there is i mean i don't have to pull it because it's already there even if i pull it it's okay again i need to i'm doing two step right we are creating the container okay again you can use docker container create or just vl okay so you are creating the container and then you are starting it instead you can directly use a command called run so last time we did a pull and then we first pulled the image then we created the container then we started the container okay instead of these three steps you can directly mention docker run or docker container run right so if you if you're okay you can type docker container in it is the best practice okay so that you can understand what it is but while running it okay you need to tell okay previously we had a problem okay we could not we didn't link with these two things okay now we are linking our localhost 444 to the container port four four four four it doesn't mandatory these two ports needs to be same again you can link a four four four five port four four four four that's okay okay four four four five two four four four four that's absolutely fine but the thing is you cannot change this because this is how the darker guys have you know the selenium guys are exposed to the airport okay so you cannot change this but you can still change this particular guy okay so this one you can link a four four four five two four four four four that's possible good now let's go here docker container run this time i am doing a port mapping to do the port mapping from your local to the container you just type hyphen p and then mention okay what is the local host port i am going to link my four four four four two four four four five okay once you do this you know you just need to mention what is the container that you know using which image you want to create this particular container so again the container name sorry the image name is standalone hyphen chrome this time when you type docker ps it will clearly tell us okay this time it has started and this particular selenium server went down to listening mode and if you notice i cannot type something here because this cmd you know went to a listening mode this container went to a listening board so i have to obviously create a new command prompt okay go here okay and let's just type docker ps okay this time it is printing me okay see there is support 444 uh from your local is now linked to no it's four four four five sorry guys i think we did something wrong okay let me okay i think i have created a container incorrectly so i need to map it to four four four four so there is a wrong again again i have committed a mistake let's quickly build this okay docker stop okay and then again guys if you notice this container id is something that is very dynamic so it is it is very hard for me to remove this you know remember this copy it and then paste it like this okay this is very hard for me so maybe next time when i create i can create it with the help of a name i can name a particular container okay you can either use a name also to remove the container okay suppose instead of this container id i can give the random name that it generated okay see the name it's very weird right angry napier okay good so now let's wait for that to stop once it is stopped okay you can also remove and then you using for remove also you can use the same name instead of naming it like this you can give your own name okay that's what we're going to do now so sorry guys for the error now again we'll type docker container okay instead of start and create and start i'm using run and then i'm doing a put mapping from four four four four two four four four four okay once we do this we can also name okay hyphen hyphen hyphen name give the name suppose i want to name it as rajini so you can name it as rajinikant but here i can just naming it as um maybe cell grid something like this okay and then i'm just telling what is the image selenium slash standalone hyphen chrome and again i'm trying to cover a lot of concepts here guys so previously we have a problem that it's generating random id and random name which is very hard for me to imagine so that's why i'm this time i'm naming it as selenium grid and the reason why i'm doing the mapping is that because we need to make a link between my local because my test is local right i need to my test is in local i have to delegate the particular test you know which which i am pointing here to this particular port that's why i'm doing that okay good once you do these two things okay previously you notice it went to listening mode so i cannot use that command prompt anymore so to avoid that i can also add hyphen d in the front so that it it will be you know running in the background all the process that happened that goes in the background and you can still use this command prompt for for for the for the uh you know operations good it's try to run this particular test sorry particular command now if you notice it you know the all the locks that it generated it went to the background suppose if you want to see the logs previously what it displayed you can just type docker container locks i want to see the locks right it's more easy again if you note if you don't know what to do just type hyphen hyphen help device so what and all the command that i can perform with container okay if you want to do know about that you can also do docker container iphone iphone called see it is telling if you want to attach to the container yes you can do this you want to commit if you want to do copy pies and stuff you can do that and use inspect to know about the container status and other stuff okay if you want to see the logs switch the locks for the containers okay so if you want to kill the container you can also use again the difference between kill and stop is you know stop is more gracefully killing it and killing is something you know it it doesn't look for anything and it will go and suddenly it will kill okay not wait for all the process to complete another stuff good now if you if you want to rename it you can if you want to restart it you can do that all these things you can do but for now i am interested in fetching the container logs container logs okay what is what is the contemporary that you are interested this time i don't have to give the id at all because i have named the container cell grid okay so i actually this is not a grid but somehow i named this as grid it's okay if you notice this is the one that generated before right so so it's it's doing it's telling this particular cell name server is up under running on 444. now let's try to run this test and before that let's also check uh how this whole thing you know um it's there okay now local local host for four okay you notice this is the local host for for this time i i'm seeing something here okay which is which means that there is something you know that is running this particular selenium standalone server is running in docker which i am seeing it in local because i have done the port mapping click on this console if you notice there is no sessions now okay when we try to run our test from eclipse okay let's see whether it is executing or not run this testing test again i'm voluntarily waiting for five seconds so that we can do we can see the changes okay okay just reload this see there is a new chrome container okay this is having some capabilities so this is running my test on 88 version of the chrome because this is the latest version the latest tag version this is the platform platform is linux right all these things other properties so page load time over the script amount all these things are displayed here okay so i think the whole thing is let me refresh the session i think the session is complete the chrome is done i think the test should have been passed if you notice it printed the title of the google and then the test card passed everything is working fine guys now if i want to again run two tests okay this is two tests right so first let's try to run two tests in sequence again guys most importantly quit put your driver okay so otherwise your operation will take a lot of time right at least the default time mode will take some two i think 60 seconds maybe to free up the browser so it's always good practice to quit the driver right so now let's try to run the same you know this time you should run the test twice okay i can find the video later so please change the playback settings to one point five or two good now let me reload it and if you notice there is one chrome here okay it got done and then the next chrome okay i think the second test is running now i think good good yeah i think both the tests are completed but if you go to the locks you can also see that first test this is the second test both got passed and your test almost took you know 16 point uh you know 16 seconds right so almost the first two nine and this one's took six again if you want to run these things in parallel okay see if you notice i have created this particular class that count as 2 let's try to run the 2 test in parallel okay it will still work guys so it will create 2 chrome you know for you at the same time okay you notice there are two chrome here one is this one is this okay this is these two will take care of both the things and both of them are running on 88 version of the chrome good now let's go to the eclipse and then check what's happening okay i think both the tests got passed and this time the test got executed in parallel you notice the total time is now 10 seconds right so almost five seconds we are doing the waiting right so so yeah that's fine so the the execution speed is almost same as your in a local browser it can be fast but it definitely cannot be slow okay so this is what we are actually right so without any use of our physical infra for chrome with just a simple command just this is the only one command that we wrote you know just make sure that you understand this particular command again this mentioning container is not mandatory but other things are magnitude good now we have achieved this right we are running test in parallel but if you notice we didn't run our test in firefox now i have a new requirement that i have to run this particular test in firefox okay let's try to run it now okay obviously it will not run because the image itself is telling it's selenium standalone chrome right this is selenium standalone chrome which which will only help you to run test in chrome so obviously i'm trying to run it on um you know uh firefox but it should pay once one test will pass because yeah so the second test is failing because it it cannot create the gecko driver service so what is the problem then what i can do i can still pull a new image called the selenium standalone firefox okay but there is a problem because that selenium standalone firefox will also expose 444 right so so what i have to do okay you will see all those things what is the problem with this approach you know all those things and why we need to have something kind of a selenium grid in our next session but for now just to understand what are the infra that we have now you know cannot run the firefox test to run the firefox test we need to do some other change right so we will understand more about it in the next video until then tata bye bye
Info
Channel: Testing Mini Bytes
Views: 5,687
Rating: undefined out of 5
Keywords: running selenium tests in docker, run selenium test in standalone chrome container
Id: daILiXCLom8
Channel Id: undefined
Length: 23min 24sec (1404 seconds)
Published: Thu Feb 04 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.