Solve your Test Automation challenges with Docker

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
today's topic is test automation with docker and we can surely say that uh this topic is a very trending one because docker as a tool is currently very high on demand and popular among among users among those that work in software software development projects and it is very popular for various reasons one of the reason is that it is highly used for reducing costs in those kind of projects [Music] amir my colleague will actually go through this topic step by step he will introduce us with the some some of the basis around the doc around the docker and test automation and he will go through the demo but at the end we will have a q a session which will last around 20 to 30 minutes i would kindly ask you all if you have any questions please add them into the comment section and at the q a section at the q a part we will go through those questions one by one and try to address them as much as possible okay so this session will be recorded [Music] so i hope that's fine with everyone and i think emmett can now start with this interesting topic uh amir good thank you thank you very much for a nice introduction so as i'll already said my name is emil hodgs i'm here at system verification i have four years in experience in test automation and recently i started uh going a little bit into devops and that's that's when i started playing around with docker and found uh how great the tool is and uh how it can be used in test automation so before further ado let's go on with the motivation why uh why i actually started going into devops so uh when you look at the qa career path uh you usually start as a manual tester you you started testing manually for some company finding bugs learning uh software development life cycle how everything works and little by little at least that's my story little by little you start going into one of two possible directions either you go to more business direction where you become requirements engineer and later on you can become business analyst or you go into more technical side where you can become test automation engineer and then what that was my question as well since i found myself that all the paradigms and little and different things you can do with test automation this usual setup of testing uh web applications that most of us do using selenium or different tools for api testing you start questioning where where you can go so one of the ways you can go is to become automation engineers so you are not only automating tests but you are generally automating stuff so one of the paths that i found very interesting is infrastructure automation engineer or sometimes referred as devops engineer which is according to all the documentation and academic material that you can find it's not a valid term so devops is defined as a culture which is uh defined as a superior to current silo culture that we have we will see more in the next slides so we will today we will have a small small theoretical part where we will see where the docker is in uh in the devops we will see what is devops and what are its approach in software developer software development lifecycle we will see some devops tools and techniques and in this part we'll see where the docker fits in all of these we will talk about docker and containerization what is it how it came to be and we will see what role does the docker play in test automation after all of this which will uh i hope not last too much we will have a few different demos where where you will see uh everything in action and i will share with you all the code that i have publicly on my github where you can start playing around from the from some basic test automation project that already has all the things that you need for starting with docker so uh what is devops uh as a lot of you probably know it star it is coined from two words development and operations uh so it came out of agile and frustration with agile because some of the problems that agile tried to solve uh it couldn't solve so uh patrick deboa tried to patch this frustration with devops and the term was coined in 2009 so it's not really something old and a lot of us don't really understand what is it about so in short it is a culture and practice that combines dev and ops to shorten software development lifecycle and in the same time keep the high quality so the problem with this is that there are different goals of developers and operations developers want speed they want to release fast to to release something new as fast as possible while operations uh if something is down the first person you go is probably the person who who is taking care of the servers and it it was seen that these opposing goals are good but in some situations they are not and also for me as a qa i experienced a lot of strain uh because of this where you get the code to test in last two days and you have to go through everything and to sign off as fast as you can and it leads to a lot of frustration so in this traditional silos we have devs that write code they finish it they have time some code freeze and they give it to qa to some test environment we test it find some bugs and they have to redo some stuff again and back and forth back and forth after some time uh the code is nice in our eyes and we say okay we get we give it a sign off after this there is another wall where we have to say okay everything everything's fine this can go to the production then operations takes this code they try to deploy it and suddenly some production issue happens or production completely fails so business then comes in because they come when when something is on fire and they try to find out where's the problem so operations would say it's not top to us everything was working until this last deployment but dev would say it was working on my machine and it was working in test environment what i don't see where's the problem so with this core problem comes the the main benefit of devops so with devops culture uh we it is about uh collaboration between devenops there is no finger-pointing uh date that this uh we did this they it's their fault and so on so speed and stability should go hand in hand and the goal is for everyone to have as fast time to market as possible to have a few production failures because production failures always happen and but the to have immediate recovery from failures when they happen so when we look at the devops practices and devops tools they they include a lot of things devops practices are kind of fine they have a finite number of devops practices when it comes to develop stools there is it's not that there is infinite number of them but there is a huge number of them so for each of these devops practices like continuous integration continuous deployment infrastructure as a code configuration management orchestration monitoring you have different tools some of these tools are mainly for the specific devops practice but they usually they usually cover different devops practices together you can see the docker is in the place of infrastructure as a code and what's interesting about docker is that it's not only infrastructure as a code but it uh it plays a crucial tool in these other different tools so for example you have a great uh you the kubernetes can't work without docker you have a great support on azure devops for docker and and so on so uh docker plays kind of crucial role in the in the explosion of of devops and uh demand for for people who who do devops so one other reason for devops and this explosion is cloud and we can't talk about devops without the cloud and all these major uh cloud providers have a great support for for uh docker at least and they in in some way they they set the standards for how things should be done so at the end in the end we will see the example on microsoft azure and how we can incorporate our tests pack them in the docker and and have them executed on microsoft azure so now when we have a a small overview of the devops we will see what is actually a docker what's the idea behind it so when we come back to the real world and check uh what is a docker it's a contain it's a content containerization tool and when we look in the real world the containers were the main reason for the trade boom in the 20th century so they created standards for sending goods with ships trains and trucks uh they speeded up the delivery of goods increased the amount of goods that can be transported and it they increase the safety of goods as well because you have to pack everything together inside one container before delivering the delivering it to the shipyard where it's going to be transported on the ship so all these reasons you can they take them literally and apply them to the to the virtual world of containers so uh containers in the virtual world are kind of a small revolution in i.t we don't have to manually transport the code from my machine to test environment to some production environment but we pack them in some containers that are trend that are standardized all these different environments know how to work with them and we send them on their way so there's only one standardized way uh they there are more coming uh on these days but docker is still the the king of of all of them uh and it's very fast and intuitive when you when you start using it so now before uh before any further ado let's go to the demo and we will see through the demo uh how we can run the tests inside the container how we can skip the configuration of web drivers so the big thing it's not a very huge hassle uh to configure these web drivers but with docker it's even less and uh i want to point out this last point where we want to make sure to have the same resolution and all the other things on our uh remote machine where we are executing tests and locally because sometimes i i have a personal experience where i spend like two days trying to figure out why my why my test is failing actually few of them are failing on remote machine and passing locally and finally i realized that the resolution was different this is not going to happen with docker because the resolution and everything else is the same so let us go to the visual studio first i want to show you here just a second here you can find on amarite test automation base you can you can find uh this repository that i'm going to to explain upon this and all the code that is going to be presented here is going to be available here so i have it here in in visual studio and if you look at the code it has three different projects demo core which takes which handles selenium webdriver and other extensions elements and stuff uh demo pages with where i mapped the pages and tests where the actual tests are written so the test itself is very simple it takes this site called automationpractice.com which is very nice for practicing your test automation skills so i made use of use of it and the test itself is very simple it uh just goes to home page click on sign in it registers uh with the sim sample email and on the next page i verify that this email is visible on the second page so i don't have to rewrite it so the test itself is very simple and we can run it in multiple ways so let now when it comes to docker we can run here in web execution tool dot cs i instantiated my my driver and i have several ways of instantiating either you can run a local version of chrome driver if you specify chrome in this static configuration i specified docker or you can have docker so for docker i have i need to specify remote web driver and in dotnet if you for the remote web driver you don't have to specify any ports or or urls by i mean you have to if it's out of the usual setup but for me it's very usual setup where i'm using localhost and if you hover over it you can see that it initializes a new instance of remote webdriver and the constructor defaults to proxy uh localhost 444. and uh so now we need to have some local server that will have a driver in it in its own on this port so we can connect to it and run the tests there so if i try to run tests now uh since i don't have anything it will fail and let's not wait until it failed believe me that it's going to fail and in the meantime uh we are going to go and check the powershell so also i want to mention the way to install the docker the docker is installed as any other app at least on windows where you can download docker desktop on mac it is the same you download docker desktop you install it just be aware that you you might need to go to the bios to enable something called hyper-v for intel processors and you have to have windows 10 enterprise and or professional so if you don't have that you will have to have few workarounds where is another tool called docker toolbox which you have to install for linux it's pretty uh straightforward as anything on linux so you just install it from the command line from your repository for any flavor of linux you use so when you have docker desktop when you run it you have this small icon i don't know if you can see it but it says docker desktop is running so docker itself is kind of a virtualization tool that is very efficient and works on all of these different platforms and for any thing that we download it packs it inside of a container so we have something called selene something called docker hub docker hub is like a repository of all different pre-packed applications inside of the containers so these pre-packed applications inside of the containers are called images so you can look uh you can see images as kind of classes while containers are like objects so you instantiate the container out of the predefined image so what we need is to look for selenium and selenium as as organization has its own uh different con images here and it is very easy to start any of these and the way we can do it is we can go to powershell first we can type docker to check if we have docker so oh i mistyped it so it's not the soaker but poker docker and if you don't have anything in red at least in powershell you are fine so the the way we do it we say docker run and then we specify the image we want so i want selenium standalone chrome i copy this go back to powershell i paste it here okay and uh the thing is that i need some way to communicate with my image and the way to do that is to expose the port if you look at the documentation of this one which you can find here on this link on on selenium you will find that by default these images expose port four four four four so as you could see in our code the remote web driver by default goes to port four four four four so we don't need to uh set configure anything else but i want to do something else i want a specific version of of chrome debug version which is not good for production environments but for local and testing environments it's it's fine so debug version exposes two ports it exposed port four four four four and five nine zero zero we will see later why we need that so in order to expose ports we need to say p and then say four four four four maps to four four four four what this means is that uh this container exposes this port and we want to map uh this port to the the same port on our local computer so when i say this what's gonna happen it it's gonna download uh just a second it's going to download uh so failed uh port is already allocated so let me use some different port i want four four four three let's say but i'll need to change here as well this is going to be a little bit complicated so let me okay now i have i have a little bit of problem i have a port that is already allocated so i need to find a way to kill it docker system prone a this way i can clear everything from the docker so probably while i was playing around before this demo i uh i ran something that that took my port so now it's still allocated uh let me go the harder way then let us change the remote web driver and change the port since i don't know how to do that let me google it out change port of remote web driver in selenium in.net core actually i need net core selenium okay or it's maybe easier to clear the port on windows machine clear specific specific port on windows machine so okay in cmd i need four port number i need four four four four so i need to kill probably yes i need to kill this pid so some process took this port and i need to kill it in order to continue okay and now can i run it so it's not this process let's try two two three four zero and let's try two two zero two zero okay let's try this now port is already allocated we have one question perhaps if there is any existing container that is configured to use that specific port no i don't have anything if you look at the docker psa i have these that i started let me try docker stop and then b47 adc and let's stop all of these dockers knocker psa and this last one is running f97 docker stop uh in the meantime these are the containers that are running on my computer and the last one it says it's up for three minutes so this it seems that this is the one let me stop it okay i think now it's okay thanks for the for the guy who who took notice of it so if i say now doc run okay it's there selenium server is up and running on port 444. so i have selenium server now running and for the test that failed if i go right click and run oh i it's gonna fail because i added here comma run as you can see sometimes uh these ports can lead to a little bit of hassle around and probably my doctor dr docker system prune didn't work because it should uh delete everything but it didn't uh so it doesn't matter what this is gonna do it's going to connect to the container that is running we just created it and it's running on port 4444 we expose that port to the local machine and the test is running the problem is we don't see where is the test so that's why we took this debug version which exposes another port through which we can connect another application called vnc viewer and actually see what's going on inside so now instead of doing this let me stop and let me again lock her ps see what's running if if there is anything else yes let me stop it stop a95 and instead of docker run p444 i will say doc run p 5900 column 5900 and now we have uh i made some r p dash p dash p so now i have two ports exposed from this container so now when i run the test first let me connect to the dnc viewer it's a tool that's available for all the possible operating systems you can find it online and here we have to specify localhost 5900 and we can give it a name chromedriver local and if we try to connect it will ask us for password and if you look up the documentation you can see the default password is secret and now we are connected to the container now if we run the test we can see that it will be opened inside the container and we can see what's going on inside the container and we can see the test running so this is the the simplest way of running the docker now you probably are going to say who is going to remember all of these different things so once you remember them believe me you you will always know them but there is easier way which i'm going to show you now so with this approach we had to remember we have to remember this whole line what's going on we had to say docker run then show the ports and then show which image we want downloaded so the other way of doing it is with docker compose files so ideally with docker compose we have docker compose up and everything should be ready we don't have to do anything so we need to write docker compose file i have it written here the first one this docker compose direct when you look at the repository it's the easiest one and the only thing is that you have to specify the version services that we are going to use this is completely up to you how you are going to name your services and the image where it is and the ports that are going to expose to be exposed this is in a yaml file yamal is a special language usually written for these codes infrastructure the code tools you will find the different cloud platforms as well as for docker compose so instead of writing this long line we can just say first let me again clear everything docker ps if it's if it's running and say docker stop so each container has its container id you don't have to specify the whole id just few first letters so it's 21e 1 4 so on i stop it and then since i have to move to the uh to the diff to the folder where my docker compose is so it's easier to write commands so here it is it is docker compose direct so what i need to do i need to say docker dash compose uh and ideally would say just up if you're if the name of your file is just docker compose.yaml if the name of file is different then you have to specify the name of the file which you can do with file and then what's the name of the file so it's docker compose direct yaml and then i say up when i do that it will just read everything from there and do the same thing so just say docker compose specify the file and say up and it will do the same thing selenium server is up and running on port four four four four so basically that's it what why is this good it's good because uh someone who comes to to your office some new team member he he only needs to install docker and he you can have docker compose in your solution he just specified docker compose up and everything is up and running he can run his tests already and also you can have it locally but also if your tests are running inside of the containers which is very good we will see later uh the configuration is the same so you can be sure that this everything is the same in your local machine and on this on the server so let us go back to the presentation and see how this actually looks so we have a operating system underneath we have docker installed on our operating system and inside of the docker we have chrome driver image with x which exposes two ports four four four four which we mapped to four four four four on the operating system and five nine zero zero so we connect to five nine zero zero uh via vnc viewer and two four four four four with from our code with selenium remote driver so uh next thing we can do is we can run our tests in selenium grid so if anyone used selenium grid you know how uh how complicated it can become to to set it up and to connect all the different nodes to it however there is easier way with docker where you just mean where you just bring up your selenium grid connect chrome driver nodes to it and you don't have to specify any eyepiece or different it will be connected just by the name of them to selenium grid we will connect to one of these chrome drivers through the port and we will connect to the selenium grid instead of connecting directly to the nodes through this port 444 we will we will do it through docker compose file again this time docker compose file is a little bit more complicated so we have three different services so uh we have selenium hub which is which is going to take the image from uh from the website here from selenium there is a selenium hub image and exposed port 4444 we will have one chrome image that is going to spin up after this one that's why we set depends on and uh the host that we defined we just defined the same name as we defined here for this service and it will uh it will know where to connect hub port uh is 444 and we are exposing this chrome uh to be to be able to connect to 5900 and also this one to connect on 5901 through vnc viewer so now let's go back to the powershell we need to make sure that we stopped everything so instead of docker compose direct yaml we'll say dockercomposehub because that's the name of our file and i will add another flag called remove orphans which will make sure that nothing else is running so now it's pulling selenium hub from the selenium some of parts of that hobby already exist here it's spinning everything up and in a minute it's registered selenium hub node to the selenium hub and now if we go back and run the test first let us check if everything is working correctly so we can go to localhost 444 slash grid slash console to see if everything's fine so we can see that we have grid selenium grid on this port and we have two different containers connected to it each container is running uh only is capable of running only one test you can have numerous different configurations for this but this is the this is a simple one so if we go right click and run we will see that it so it chooses uh one of these two nodes to run the test on it and we can see it by it will be grayed out okay it's running on this one and we can again we can to connect we can connect to vnc viewer we map to the same port so we can connect with the same viewer and here it is the test is running inside the container so basically that's it when it comes to this part so uh what else here needs to be said uh is that you can connect you can do uh cross browser testing you can connect firefox and opera however as as of time speaking you can't connect edge and safari safari probably not in the future but edge is in development of being being created as a node for selenium grid inside of the container so as we said this is the kind of schema that we have here so we connected to chrome driver and have seen that is running through selenium grid on the inside of container so next thing that that we can do is that uh we can run tests uh in grid in azure pipeline so this is going to be a little bit different now we are we are not going to have a code locally in our computer i'm sorry but we are going to pack our code inside container as well so we will have one container where all the code will be and that container from that container all the tests will be sent to the to the selenium grid which in turn will send a test to each node so the setup is the same you have docker compose where you specify all the services but this time we have something called docker file which we will see in a minute and why is this a good solution in in general it is a cheaper solution because this way you can before when when i started working what we did was we have a physical machine on which uh we run our tests so even if we if we have uh selenium we would have a selenium grid on one one machine and we would connect these different machines to this machine and basically uh selenium grid would run tests on different machines physical machines so we can speed up all the tests i mean you can from from the first from the first uh sentence you can see this is this is not a cheap solution especially if you are renting those machines so these days there is another way a little uh cheaper but still not like docker where you can host your virtual machines in cloud and then connect to them but with docker you can run tests straight from the pipeline so basically you create a pipeline and inside of the pipeline you spin up everything in docker run the test get the results and export those results to the place you like so it's a lot cheaper solution and we will see it now in azure pipeline how it's done so let's get back to the code and see what's in our docker compose pipeline so as you can see some some parts are the same we have two services that we already used we have selenium hub which pulls this image we have chrome which pulls this image but then we have demo tests which doesn't specify any image so but it has a new command called build so what does this build do it actually builds an image out of the docker file and you can basically if we want to be more specific we would specify docker file but by default dockerfiled is named dockerfile as you can see here i don't know if you can see but i have a file called dockerfile and it has this contact content so if i look at the structure of my folder i have in the same folder i have docker file and these docker compose files so this build here and when i say dot it means build it from the current context so current context uh this docker compose is in the same folder as our docker file so it will look for the file name the docker file and build our image from that file so if our docker file is in some different folder we would say slash name the folder and it would specify is if our docker file has different name we would need another argument called docker file and we will just give it a name whatever the name is so that way it can find from where it's going to build the image so far our images were ready made so and all these images if you look them on docker hub they are created by docker files but hosted on docker hub as docker hub is like a repository for all different images so here we have a docker file what does this docker file do it basically starts building our image from some parent image the first line is actually specifying its parent image that's the terminology from docker so the first uh if you want to build like from scratch the first uh docker image that's gonna be your parent is called scratch and if you want to do something from the bare minimum of of linux with the base kernel you will save from scratch and then start writing your your commands so here we are starting from already uh existing image provided by microsoft which is you can find it also as we found for selenium you can find for microsoft all these different images what they do what they have why why any of them we need and start building on them so work directory is the directory inside the image if you go inside of the container check the content uh we with this work directory we specify in which folder inside of this image we want our code to reside so we will so we want this one to be in crc so we copy this cs proj file because we want to restore all the nougat packages and stuff so they can be they can be in the same crc file and then after we do that we copy everything we could uh copy everything and then do dot net restore however whenever you change for example if you change something here when the docker starts running and you already built your image it's not going to re-run these ones it's going only going to rerun the ones after after the change so since this is somewhat expensive uh operation of restoring we don't want it to be run every time so this means if we change some code it's not going to restore every time just go going to copy the the content of the code and the last uh last command is cmd which basically means command it is the command that is going to be default when we instantiate this image when we create the container so when the container is first created it is immediately going to run dot in the test so what is dot in the test in in this specific scenario if we want to run tests from the command line basically when we go here and go right click run we run all the tests uh in the in the same way we can say dotnet test and it will run the test all the tests inside the solution because we are in the root folder of our solution and in this folder is a solution file so without any further talk let us run some commands first let me check if i have anything running docker.net okay i don't have anything but just to be sure i will use another command docker compose down it will make sure that everything that was up is now down so some of them were still up so they are now down and now we can say docker compose we need to specify the file which is now pipeline and we want to say up and let's just be sure and remove orphans so now it's building demo tests it's downloading everything so basically it needs to download this image from microsoft in order to build upon it so there is another command so you can see we have two commands we have docker and docker compose on linux these are two different uh command line tools in windows there they are as well however you install all of them by just installing docker desktop so you have access to docker compose as well so uh when you go docker run as we did before we set docker run and then specified the ports and what image we want to pull it pulls automatically you can also just say docker pull and pull everything you need without running it so i could do it before but i did docker system prune so it cleaned everything when we had that problem with the with the port being being busy so now it's trying to restore all the projects that with dotnet restore as you can see it has the steps and these are the sta same steps it copied everything and as i said dotnet restore is very expensive command and now it's up and running and not only the that everything is in containers now and as you can see since i had the command dotnet test now our container is starting with that command and the command is starting the tests and since we have everything in the code that will connect to the ports and stuff it's going to connect to the selenium grid and then the selenium grid is going to execute to the on the on the chrome driver so we can do the same thing on azure so let's see how we can do that we can go to the visual studio to the chrome and let me go to the azure okay i'm already logged in so just take one one note you have to have a profile on portal.azure.com since you have a free free version of of azure devops for 30 days i made use of that and you can play around with it create the virtual machines you have basically 200 dollars on your expose to to do anything you want so i i did that and uh here i have a code the same as on github and here if i go to pipelines okay let me delete this one just to be sure to start from the beginning okay now i don't have any pipelines and i need to create a pipeline so here uh you have our code is here you can also you don't have to copy code you can uh take it from github you made directly it's here so i'm using this one i need to select it so now uh since i already did this it created for me a specific file that is again yaml file it's called azure pipelines.yaml and it instructs uh azure devops in which way to to run all of these containers in which way to create the pipeline so if you are doing this first time you can either learn the syntax which i which i didn't but i use their assistant which is great and you can just type docker here and find that there is a docker compose so this docker compose if we specified we need to specify what we want so what's the name of docker compose file what is the action that we want to do what what is the command so here i would say it's up uh as we did docker compose up this file i specify up there and also i did one other thing i set abort on container exit in the previous version of docker this was by the default behavior now in this version a newer newer version of docker it's not default so this means that if one container exits everything that was run through this docker compose needs to exit why i did that because uh when when we run uh docker compose up and our test finish uh selenium grid and nodes will still be running so our pipeline will never end and but one container will exit it's a container with our tests and we want since that container will exit we want all the other containers to exit so with this we just need to click run and one more thing i want to mention is that this steps you need to edit this tool will provide you with the task but you need to say steps column and then add the task this will basically generate the code here when you fill up everything on the in this in this helper it will generate the code similar to this this is basically my azure subscription so if i say run it's creating a pipeline and yeah i need to permit it so now it's going to run and what i expect from it is to behave the same way as it behaved locally so now what it's going to do what we have seen locally is that okay this uh test runs successful total tests one past one total time 31 seconds so i want to see everything to be the same even the log should be same so if i look back you can see some basic info on what's being uh done this is i think running on on ubuntu so you can see that it's uh it's cross compatible if you if you are using windows you can run everything you can create these docker files and docker compose files and if your friend doesn't want to use windows for some reason he can do everything the same on linux or mac os so this is running on ubuntu 16 i think by the default there is some information about that somewhere that i've seen yeah but uh so basically it's not only that you are consistent in the cloud and your local machine but you are consistent across multiple different operating systems so this is going to take some time as well it's actually faster than my local machine and it's going to run the tests so uh now with the framework that i provided you can add your own loggers you can add your own reporting system this is not here this is only the skeleton of of the of the project with page object pattern you can run multiple tests parallelly and you can use this in any way you like so you don't have to reference back to to this you can fork you can clone create your own github repository whatever you like let's go back and see if the test is finished just second i have here okay post job let's see what happened there so it it says total test one past one so now we created our pipeline and everything is running inside of the pipeline inside of the of the azure devops we don't have to go and connect our selenium grid to other machines so i hope that this was uh not hard to understand and in case someone didn't let's see the graph how it works the graph is even simpler than the previous one since everything is running in docker now and here we have our test code in one container that is communicating with selenium grid through port 444 and the selenium grid is communicate communicating with other uh chrome driver nodes uh and i exposed this board but we didn't look at it on chrome driver through port 5900 to the operating system so only one port is is exposed to the operating system and the test code is running with the cmd the last cmd that we defined thank you for listening so i hope that that you have questions i hope that i was easy to understand that that you can uh that you can have at least some basic knowledge on why is this helpful and why is this money and time saving thing okay thank you emmett for this uh lovely overview and presentation of yours uh first question that i have for you is can you elaborate more on why you copy the remaining files after you restore i'm not sure i understand the explanation so can you brief us on that part perhaps more okay so i hope it's not corona so basically if you first let me show you one other thing you can do which is probably show me as a little less competent maybe because i didn't write this on my own i did modified on my own however you have an option here to say on any project you have you can go to the project at least in visual studio and you can say add docker support where you can say linux i want my that's my target os because you have uh windows containers as well and it will create docker file for me and this is how it looks since i don't need all of this i deleted some stuff and simplified some stuff but i just want to make make you aware of it that it exists so you can you can build or reduce based on this okay so why i did that is because for anything we change in inside of our code and if we want each time to run everything inside of the containers so we want the code to be inside of container and we want we want everything else to be inside of the containers so if we change some code it's not going to uh it's not going to restore to do restore again because we didn't change cs proj file however if we add a new add new file or class or something uh inevitably cs proj file will be will be changed so since nothing in this file will be changed this uh these files will be changed this command will not be executed since this is expensive command we don't every we don't want to restore every time we want only if something in these is changed this can be further optimized but for me it was enough so if we change something here for example in base page i don't know add some space control s and if i run again docker compose pipeline which is building my tests from docker file it is going to take a look at the docker file see aha here nothing changed here nothing changed here nothing changed so i don't have to run this but here some file changed a little bit so i have to copy everything again except these things and since i restored everything and stuff like that i only have to copy everything in itself it's a little bit uh expensive but not that much it can be further optimized by including some git git tool for comparing files and not to copy files that are not changed and so on but for me this was enough i hope that this answers the question okay uh i hope you can see me all hello there um so do we need to expose port for only web driver images uh so we can expose ports that that have some ports that are exposable so if we have some containers that is not exposing any ports for example my project is not exposing any ports so if it's running uh if it's running inside of this container there is no way for me to access it uh from the operating system when it is running to access this container because i don't in in the code itself i didn't say okay this is available on this port and and so on so i can't really uh attach to this container when it's running i can go through docker and go inside the container and see what's inside but i can't see from the outside world from the operating system so this port for us is for the container to be available to the outside world if you want the port to be only available inside the the docker there is another command that you can use so we could easily instead of saying ports in this not in this one but in pipeline we could easily say uh four four four yeah for selenium hub instead of ports we could say expose and just say which port we want to expose this will do the same thing and this is maybe even more secure because here this this graph will change in a way that this port will not be available to the operating system it will only be available to the other containers inside of the docker so if since selenium grid if you look at the documentation is is giving us inside of the documentation uh docker hub if we look at the documentation of the selenium we can see that the ports that are there are the ones that we that we used so basically i read the documentation scene i've seen which ports i should connect to and did that so for each of these you have every image is created by someone so you have to read how that image can be used i i hope that that answers the question um do you need the license to create more than one node to run multiple tests or you can create all the nodes you want when it when it comes to selenium grid i'm not aware that there is a need for license especially for running everything inside the docker and actually here inside of the second demo i think docker compose hub we had two chrome images just second we had two chrome images so basically we had two nodes running inside of them you could specify on each node more web drivers as well so i don't think that there is a need for license in order to do that if you want to run it inside of a pipeline you have to create account there on azure devops uh when it comes to azure devops i used git club as well they have a free free versions as well uh they you use some shared shared builders which are a little bit slower uh but i didn't use abs and and google cloud so for azure you have to create but you have 30 days trial 200 to play around if you're a student uh there there are special packages that you can use uh i don't know for one year two years and so on and definitely make use of that i did when i was a student um is it possible to do the same setup with the java selenium code as well yeah this is completely uh completely independent of the of the code so that's why we don't have to specify almost anything inside the code we can specify everything inside these docker files even you can even specify environment variables here i don't know if i did did that somewhere yeah here for example for demo tests i specified environment variable selenium grid url and it be inside the docker it behaves the same way it behaves as in uh as in your local machine so this is completely applicable to any operating system the only thing you can you need to take care of is the way you connect to remote web driver inside of dotnet core it has a default constructor uh that connects to the this port four four four four i suppose since selenium is one big organization it did everything the same for all the other bindings for different languages could you run tests in parallel on multiple browsers using selenium grid with docker and do you have any examples of that let me create an example just a second so i have here one test let me create another the same test so i'm sorry for creating the same test actually let's just copy and paste this file and change the name registration test to so the the infrastructure of the code is that if you have in one class you have multiple tests in methods these will run sequentially but for different classes they will run parallel so let me just change the name and change the name i don't know if i have to change this one let me just build again okay now i have two tests here and let me spin up the docker compose hub docker compose down i changed something in the code just second docker compose pipeline everything fine hub everything fine direct everything fine docker compose file i want docker compose hub i want up remove or fence so now we are going to spin everything up again okay and let's go to the here and check if it's on localhost grid console here we have again the same configuration i didn't want to do that uh and now let's run the tests run so yeah i mean it mainly depends on the on the way you create your framework if it's not execute if it doesn't have the option to execute multiple tests it's not going to execute multiple tests in the parallel okay so now they are both running and if i refresh here you can see that both of them are running so we can connect with vnc viewer to both of them i don't know which we did expose to the to the outside environment so 5901 and 5900 let me check on vnc viewer this is five nine zero zero it probably finished right yeah so basically you can run parallelly and you can in this specific framework i specified here number of threads to be three you can do what however you like and the magic of fab execution tool will take care of the rest so the answer the short answer is yes okay thank you for that great example another question is in which cases you would not recommend using docker uh if you if you are just starting with uh with uh test automation and you are just learning things uh take your time and learn test automation first and then go to docker because in my opinion i mean that's my personal story to be honest because i i am i started with uh software developer then go went to qa test automation and then i started becoming interested in in these devops tools so if you want to follow that path you are not going to start with docker uh because you want to learn what is a driver how it works how you connect to it and and so on so this is going to make you a little bit lazy but if you are working on enterprise application uh your stakeholders tell you that they want to save some money they want they don't want to to use multiple machines you can go with the docker thank you how do you combine reports running on various containers any examples of that so even if they are running on different containers i didn't do the reporting here but the way you can do the reporting is that either you can spit out the file with the report that will contain all the report in some json or html file or any way you like and it will be for most of the cloud platforms it will be in something called artifacts so i don't have it here because i didn't set it up that way i just wanted to check the the locks there but for other guys in the company that are working on different projects they they they are able to to connect uh this pipeline and the results in the pipeline to parse them and be to be shown inside of the test plans to actually see which tests have passed which test did not pass i didn't want to to do all of this because it's only last it's this test lens is available there for 30 days after that i will not i'll not be able to see this but also i can't show you the co the setup of my clients so on on this it is possible it is not hard but i i don't think that i can do it right now so uh you will need depending on your needs you will need a different configuration for reporting the reporting in itself is a is like a whole whole level of of doing things and test automation you you have to have good reporting uh which i don't have in this skeleton project um selenium grids is supporting only linux containers uh is there any good way to run selenium driver on windows container to be honest i didn't try that what i've read about windows containers and i i was a little bit frustrated about existence of windows containers because when you read about contentization it has its own standards and then it there is only one type and then suddenly there is windows containers and then i found that these windows containers are used for people that are strictly locked inside of windows that have some software that was written strictly for windows and you can for example if you if you write something in dotnet framework uh there is no way you can you can run it linux since frame.net framework is proprietary and to be honest i i didn't try uh running it on on windows containers for anyone who is starting and doesn't have to use windows containers don't okay is there a limit on running the tests in parallel or i can run as many different tests i want in parallel there is a limit of of a machine physically how much machine can handle so uh i don't know this out of the box machine here on the on the pipelines what is the configuration of that machine but basically if you have you definitely the the only limit is your hardware there is no software limit on the number of nodes and number of uh of machines on which you can run in terms of selenium grid i'm not sure what's the limit i have never uh in my in my experience i have never touched the limit to say okay here's the limit but uh these nodes are not running because of this limit it never happened thank you um would you let us know about some of the challenges you faced when working in docker so the the challenges as you could see in the in the mistake i made are sometimes something happens that you don't know why for example i ran docker compose prune and docker system prone it should delete everything from the docker that i have with this flag a meaning all but it didn't and the even though docker docker desktop and the docker themselves is very easy to to set up it was easy for me sometimes when i was installing on my other machine i encountered some problems that were very hard to solve so you have to go through different forums to check what's going on why this error is showing up and so on so when things go wrong they can go really wrong and that is uh that is the biggest challenge also uh please try to understand the concept behind it so it's a on windows at least it's a virtualization you have these small packed containers that are running on some minimal linux kernel and they are completely independent of your machine the only way to connect to them is through ports there is also something called volumes but you can read more about that online where you can map the storage of the container locally in your machine and play around with that so the the challenge is this sometimes unexpected behavior from the from the docker thank you uh can i can we use docker to mount a webpage to test or the web needs to be hosted outside the docker you can definitely uh mount the web page as well or any web application and the the name of this webinar is docker and test automation because docker in test automation was later we started it using later after our dev colleagues because dev was using it before us and they packed the application a lot of applications are packed today in docker containers that are run on the cloud so it is definitely possible and you will have to specify dockerfile how that how that application is going to be built and you if you have some database you need to connect to it either in different container or on that machine or different machine so you need to configure a little bit but definitely it's possible and you you should you should try it if you want to to go further and really master the docker thank you emmett for these nice answers and lovely overview are there any further questions please post them in the chat if you have anything else that you would like emma to address perhaps emilio could let us know about some of the recommendations when to start implementing docker in test automation how to start what is the first step and so on so one of the ways is that you can use my project to start with it playing around it's very easy basically you have seen everything uh the way you can use it you can rename the solution but if you want to start from the from the ground up i would say try with the with the some database server for example uh post postgre sql postgres so i i tried with it i was working on some on some project and uh i need to set up local uh database to install postgres in order to play around with it and i wanted i know that when you want to install some database server there is a lot of pain around that you have a lot of things that you need to configure and for example if you if you want to install postgres through the docker you say docker run postgres if you have a specific version of postgres you specify column that version so now this will pull the postgres and i will have postgres inside of the container that i can connect to so this is the simplest example that you can go through and you can use it in your daily life by installing some tools that you don't want to install on your local computer because you have to change numerous uh files inside your system so next time you do something something is definitely different you can't install some other program and so on so in this way you can save yourself and have this specific database inside of the container and just expose some port and it it's going to work the same as you install it on the on on your local machine but the only thing is that is not going to intervene intervene with your your system files and also some of the of the classic example are some web applications i don't know i i worked with angular a little bit building angular applications inside docker and uh also nginx uh as a as a server so you can you can create uh any architecture you you you imagine you can create through the docker uh so my my the the biggest uh pro for for the docker is that whatever you do inside of this container you can just delete them if you if you uh do something wrong on your local machine it can lead to the to the deleting everything on the operating system if you are if you are full of trying to fix it uh you can end up deleting i mean formatting operating system and installing again with docker you can play around in containers how much you like you can't ruin everything ruin anything um can the configuration part be replaced with script which will do the download and configure all dependencies for us uh configuration part i i'm not sure which configuration part uh because we dealt with a lot of configuration parts dockerfile docker compose i'm not sure if that person can clarify either or they they they want them to be unmuted so they can ask the question i don't know so alyssa would you kindly write in general okay in general the docker compose so can you repeat the whole question please of course so can the configuration part docker composed be replaced with script which will do the download and configure all dependencies for us uh it does that basically uh here when we specify this if i now if i let me show you so now if i uh docker compose pipeline i have selenium hub locally i have chrome locally but let me delete all of it so i can go docker system prone a this will delete everything from the docker i have yes i want yes okay so now it's deleting everything let's see how much so 2.3 gigabytes so if i say now docker compose let me not rewrite let me see where is the command okay docker compose hub it's fine now it's going to download everything it needs to pull selenium hub from the docker hub because the docker hub is like repository for example if you are using nougat for net core or net you have to download those nugets from somewhere you have no get.org you if you are using javascript uh node.js you have npm the same goes for docker everything you you try to use some image it will look if there is image locally if there is no that image locally then it will download that image so this is kind of already enough automated i don't know if we can go any further to automate any further and here also if this doesn't exist it's going to download it so now you can see it's downloading bunch of stuff for me automatically with only one command maybe you you didn't get the the right idea because all of these were already existing on my computer so i didn't have to download them before i just ran the same command before so now uh when i run when i ran again these things didn't need to be downloaded again because i have them locally so that's the only difference and uh when it comes to down downloading from the nougat here when i said restore restore does the same thing for net core basically it downloads all the nougat packages related these and it does that from the inside of the container it downloads from the from the nougat nuget.org all the all the ones so for example in demo test cs proj what do i have there i have microsoft.net sdk visual studio azure containers tools and unit and unit 3 adapter it needs to download all of these so everything is automatic thank you very much another question which i would like to ask you is we saw that you were using engage your devops as a platform do you have any recommendations is it better to use azure devops or abs or any other platform in that matter for this specific uh example let's say i mean for this specific example saying you have since you have seen me using azure devops it's if you didn't use any other it's probably good to start with it since you have seen how how it is used and they are giving this free trial that you can use uh i can the the other platform that i used and i can recommend is gitlab which gives you free for life usage but there is no this fancy ui for creating pipeline here you can create these jobs and it will generate you that that file let me see where is where it is yeah azure pipelines yaml file which is going to be included in your project for github it's the same principle it's only a different name gate club dash ci dot yaml for avs same just different prince the different name of the file i mean the syntax is not the same the syntax is specific to the cloud provider that you are using but i know about gitlab that they are offering uh free versions and the only drawback is that you need to have to configure more things manually uh and it's the these runners for running the test building everything are a lot slower because they are shared among all three free users so my recommendation might be to start with something that is free and then go to the to the to something that is paid and if you are student asia is is great uh avs gives even more i have avs subscriptions well it gives you 12 months like trial and some of the things are for one month some of the things are are for a certain amount but a lot of things are for 12 months so when it comes to accessibility uh if you're a student use azure if you are if you want to play around you can use github or abs for google cloud to be honest i i haven't i haven't used it last time i opened it was maybe when i was a student so i can't say a lot about it okay thank you very much i can see that there are no more questions for you today um i would like you i would like actually to thank you for this lovely overview in front of system verification and i would like to thank everyone who were included in this webinar and everyone who participated i hope this session helped you out of course we will share the recording to all the participants afterwards and i wish you all the success of course emmett um and everyone else so thank you everyone and have a nice day thanks for me as well and if you find that you have some questions you can drop me uh drop me a message on linkedin on the on on github or anywhere you can find me so uh i i'm eager to help any of you if you need help thank you again for participating
Info
Channel: System Verification
Views: 1,665
Rating: undefined out of 5
Keywords:
Id: Io2sVA74YrA
Channel Id: undefined
Length: 85min 39sec (5139 seconds)
Published: Tue Jun 15 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.