 Hi everyone, thanks for taking your time and coming to this talk. Today we'll talk about some dockerizing opium server stuff, and later I will show also how to dockerize the emulators. Have you been in the previous talk in this room with the Diego? I guess there will be some similar stuff, and Diego was talking about the infrastructure. I will present how to do it in local machines, some part of it, and I guess I will present some solutions from the Diego projects that he was contributing. My name is Sarkis. This is my second time in Bangalore. After three years I returned back to this wonderful India city. Right now I'm working for the Pixar, which is a creative photo editing tool, which has more than 137 millions active users per month. We are dealing with the automation system, and this is one of the solutions that we are trying to implement in our company also, to have a better automation in terms of the smooth releases. Right now I'm leading the whole quality insurance team in Pixar, and I have the director of the quality insurance position there. So let's go start it. Today's agenda is like we'll talk about the introduction, why actually we need what is the purpose of doing this stuff. We'll get similar with the Appium docker. We'll run tests on a real device using the dockerized Appium server. We'll set up it with the docker-compose file to make it easier. Rather we will use Android emulator inside the docker. I will show some tricks, how to connect via Wi-Fi or how to simulate the SMS. Then in the end we'll connect it to the Selenium hub with the host, and then we'll run the tests through the docker, the Appium docker and the emulator inside the docker. We'll connect everything together and we'll run everything dockerized. And then I hope we'll have a short time for the question and answer, if we'll not manage just ping me outside. And also I would like to offer you, if you have a question in the middle, just raise your hand, I will stop. We'll talk about the question and later we'll continue. Because there are a lot of technical stuff and better to ping me on the spot instead of waiting in the end zone. The worst case that I will do it will be like, I will talk about that a bit later. I'll show you what's happening. So actually why we need this? This is one of the testing pyramids. I hate the testing pyramid on Verdi, but this one is a bit different. This is more related to the mobile testing one. And if you take a look at this pyramid, you will see that there is one part here, like the simulators and emulators should be more than the real devices and the devices. This is also about talking about shifting left. So as left as early, we are finding the bugs as cheaper there are. So this is also the one. If you have a test on the simulators and we are running them continuously and more frequently, we will catch the bugs more in the left part instead of. So today we will talk about this part, about the simulators and the emulators, how we can organize this part. This is all about the local environments because there are other options like journey motion that you can use, but this is already like cloud services. So today we are talking about the local ones. So this will help us to get the quick setup of the automation environment. We will speed up our opium tests. We will automate the steps done by them automatically and we will be able to run on the real device and on the emulators. So what is the opium? I will skip this one because if you are here, everyone here, we are like, no, the basic of what is the opium, what is doing actually, how it's doing. And this is the simple high-level architecture of how it's opium working. There's a test runner. There is opium adb and it's connected to the device via USB. So actually what we are doing with this solution, we are taking this part and putting it inside the docker container. So this part is the adb with the opium living in the container. We just connect it to the test runner and then to the device. Actually, this part also could be the correct. So it can be living in another docker container. This one is in another docker container. We are just connecting them together. So there is one thing that you need to have Linux OS to make it easier to spin it up, everything. And it's a bit hard to make it work on the macOS. So why I'm going in the details with the steps how you can set up on the macOS. But if you understand how you can set up in macOS, it's super easy to do in the Linux machine. So first of all, we need a docker and docker machine. So when you install it's in the mac, usually they are coming together, docker-compose, docker-machine, and docker. And just you go on checking the version. So I already shared my slides in the conf-engine. So everything you will have later. Just to ping me if you have a question even later. So what we are really doing in the virtual box, we are creating the Linux machine. And inside the Linux machine we are creating all the other infrastructure. So the docker machine which is creates virtual box, and we are giving the name. And this is how we're command running. And when it's starting the VM, you will see this in your virtual box. So this means that we are locally, we create it in the virtual box, we create one Linux machine. And to be able later to create the visibility between this image and the USB ports, we need to enable the USB port. For that we need to stop the machine, and then we need to turn on the USB. So this virtual machine will have the visibility to the USB ports. And you will need to install the USB 2.0 controller, which is like there is an extension pack, you can download it and install it if you have an issue with it. So basically it's done. You can do it from the UI also. You just go to property, you go to ports, USB, you just tick this box, which says that we are enabling USB ports for this machine. And after that we're just saying the start opium machine, and here we have the machine which has the visibility with the ports. After this all, we need to connect the device. And when you connect the device to the host machine and coming to the same configuration page, you will see there which kind of devices are connected to it. And we are adding the Android to this machine, which creates the visibility to the device and the machine. So as we are going to run the test through the Docker machine, we need to kill our local ADB server and connect it from inside the Docker machine, which we are killing, and then we are just doing the Docker machine SSH to the opium test machine. And here we are, and then we are executing the command ADB devices from the inside the virtual box. And when we do this, it says that there is a attached device, which is actually attached to your host and there is a bridge connected to the machine. So right now we have the virtual machine which is connected and the phone connected to the virtual machine. Like after the command running, you will see on your screen that the USB debugging wants to connect. You just need to press allow as usual. So after this one, there is a Docker, a Dockerized opium container, which we can run with the Docker run command and this will create a container with the opium. When you run this, you will see that the container opium is running on the specific port and it's ready to use after the run. So right now we have everything ready to run the test through the Docker opium. But as the opium server is living inside the Docker machine, we need to give the visibility of the OPEC file. So it should have a visibility to take and install on a device. So this is the command where you can just copy the file inside the container. This is copying a specific file and moving it to the specific location in the container. So we are moving it to the OPT and then the name is the Pixar APK. After this, we just need to show that our application is here and the rest is the capabilities that you used to do. And then we're just running the test, I'm just mapping to the Docker run. So this is the situation when I connect the real device to the host machine. I created the virtual box. Inside the virtual box, there is a Docker opium running. I moved the application file to the Docker container to have the visibility and then point my tests to that server and it's run through the Docker. Is it clear what we are talking about? It's really fun. Running test is from the local machine. Yeah, it's in the local machine. So as I said in the beginning, there is a way also to Dockerize the test runner part, but that's another story. It's not related to this. Good. So I believe that all of you know about the Selenium host, Selenium Hub Grid. So when you want to connect this opium server which is running inside the Docker to the specific Selenium host, while you are running the Docker run command, you just need to connect to the grid. True. We are passing the opium host. We are passing the opium port and then Selenium host on the port. And with passing these parameters, we will connect it like it's the same command with the specific parameters. We are connecting the specific opium server to the Selenium host. And to not every time collect this, do you know what is the Docker compost? It's just a way of easy running the Docker containers. You just collect all your parameters inside the YAML file and you just call Docker compost up and it creates all the infrastructure for you with the Docker. So there is also an example of it. In the end, I will share with you the GitHub link where I have some small framework created in the page objects pattern and there is also all these files that you can reuse it. So we just call Docker compost up. You see that in this Docker compost, we say that we will need one Selenium hub and we will need an Android opium which depends on Selenium hub, which means that when you call Docker compost up, it will up the Selenium hub and it will wait until it succeeds. And then after that, this dependency talks about it. After that, it will start to run the opium and make a connection. And after that, you will have all the Selenium hub and then an opium registered in the Selenium hub. Later in the end, I will show the working example. There is a way to connect your device via Wi-Fi to the host. Did you try it ever? Did it work for you? Yeah. As long as you have a stable Wi-Fi connection in the office, that's the cool stuff. You are putting somewhere and charging and then connecting via Wi-Fi and then you don't care about the phone. Yeah, there are some, but if you do the basic stuff, it's like with the opium, it worked for me. And this is the steps how you can do it. It's just fun and the easy stuff that you can do and then in a certain situation, you can use it. You just call the command adb tcp ip on the 555 where adb lives and then you turn off your phone from the host machine and then you do adb connect and the device ip and then when you do the adb devices, you will see your device there without connecting to the host machine physically. And yep, this is the steps how you can do it. Yep, you just do this adb tcp ip and then it will start successfully and then connect to the ip and then adb devices, you will see, just instead of the id, you will see your device id, device id here. And after that, you can just the same way run the test. This is connected with Wi-Fi and you will see that it's running the device with the ip, not the id. Good, here we are. All these tests that I'm showing you here, the codes are available in a github, it's public. So you can go to my github account and just see the code and the test that I wrote here. Okay, now it's the morph part when we create the emulators inside the Docker container and then connecting to the same opium server which makes it completely dockerized. So this is also why we need to do this. We run the mobile and the website. It works for the mobile apps and the websites. It runs unit tests in any time you want and then it can run opium, espresso, robotium. It's not only opium. And then it's run monkey tests, thread tests, and the SMS testing. This is, again, an open source project and there is a link under it. So if you want to go to the details, more specific documentation, you just click on the link and you will see all the documentation there. Actually, this is the project that has the integration with the journey motion. Yeah. So this advantage is that you don't need a BNC anything. You will see your emulator inside your browser just connecting by the port and there is the ability to connect again to the Selenium grid. It supports also real device so you can connect your real device and the screen will be visible inside the web page. Again, no BNC. There is the ability to record all the run of the tests. It integrates it also with the cloud solutions like the journey motion cloud and its open source. So we are open to contribute them. So there is a specific amount of the emulators that you can create here. So it's mainly all the Nexus phones and the Galaxy S7, S7 Edge and the S6. This is the capacity that you can use. These are all available for it. So how we are running it? Here there is one tricky stuff. You cannot do this on a Mac because it needs a nested visualization on. You need the Linux machine here. All the recordings that I'm showing you it was created on the Ubuntu machine and it's worked fast and easy there but no way to do it on the Mac. Just make sure that all the machines that you are using the nested visualization is on. There is also in the documentation. So we are running it. We are mapping the back 6080 port. We are mapping the two ports for the ADBs and then giving the name of the device. In this particular example we are running Samsung Galaxy S6 and here it's run, it needs some time and then inside the browser you are connecting to the host IP with the 6080 port or a emulator inside the browser. It's super easy, fast and it's really easy to spin up the environment. I didn't get it. You can run in several containers. I don't think that it's the best idea but yep, you can use the generation cloud. Of course there's a solution coming here but in every container we are spinning up one emulator and it's isolated and it has a specific port and it has a specific port for each container so to see a specific emulator. So if you want to connect the real device you do the same, you just call the real device like Docker containers and then connecting the real device to the host machine and you will see the screen sharing inside the browser as you see for the emulator. And if you want to control the device inside the Docker container we are just connecting with the ADB giving the host and then the port and then you will control through the ADB inside the Docker container. So you have access from your host machine to do that. Okay, so there is another thing to how you can simulate the SMS. So it's super easy. In this case you just take the authentication token from the container and then you are doing the Telnet container IP and 5554 and then authenticating with the authentication token copied the upstairs and then sending the SMS. I don't know why the phones get smaller but they were equal. There was a time that they were equal. So it's super easy. So you can copy authentication token and then we are telling that to a local host and then 5554 and when it's connected they are saying it's okay. We are authenticating with the token that we already got from there. Just authenticate and that's all and then you are sending the SMS. SMS send, you are giving the number which from it will send and then you are giving some text and then you get the SMS. This really makes it easy to test the scenarios when you need some SMS configuration or you need some SMS token to send and then your application have to read from the SMS. Sometimes when it's sending the verification code there is a feature that it can automatically fill from the SMS. So these parts can be used for testing that kind of scenarios. So Selenium Hub, we already talked a bit before but let's go a bit deeper here. So everyone I just know about the Selenium Hub is a smart proxy server which is controlling the connected browsers and also Android devices. To run the Selenium Hub this is the basic command. This is the project where Diego was contributing talking about today. When you run it, you get it up. After that, let's just revise what we have all together. So we have the opium, use the opium, Docker, Emulator and the Selenium Grid. Yes, see now we talk about it. So let's combine all these solutions to have the one solution how we can all together run. This is the Docker Compos file for this case. If you take a look, we have the Selenium Hub. We have an opium and we have the Emulator which means that when we just run this Docker Compos app it automatically will create these three containers and they will have the visibility to each other. So this is like Docker Compos app. The minus there is like hiding the log and then it creates the Selenium Hub. When it's done, it creates the opium server and then after that it creates the Emulator and after that we have these three containers running on the spot. When we run this one and then we go localhost 444 which is the Selenium Hub, you will see here that there is one available Android device waiting for the test. And of course you can do it more. Like every container can be connected to the Emulator and all together can be like not in the Selenium Hub. And here what you see, this is the VNC connected from the browser. You see the opium server is running there and the device is ready to run the tests. And then you just run the tests and see what's happening there. So all the tests are passed inside the Docker through the Android Docker. All right. So this is the main part. I would like to show you also where is my mouse. The GitHub where you can find all the examples on the spot. There is the opium page objects. So here you can find all the codes that I used. There is two Docker Compose files. One is the last one that we... This is the first one which is for the real device. And the next one is the last one which is creating the Selenium Hub opium server and then the Emulator. And here you can see all the code and the configurations that you will need. And if you have any questions, just take me. How I can actually show this one. I will put this one, the link of this to the comp engine. Good. So if you have a question, just go ahead. The virtual... Because of the opium server which is running in the Docker, it has some issue with the macOS. So we are with the virtual box. I'm creating the Linux machine and inside the Linux then up like making the Docker container. So directly to the macOS there are some issues and I connect it also to the contributors and they created some steps how to do with the virtual box. Yeah, yeah, yeah. The same issue is there. Yeah, which doesn't work on the mac machine also. Let me find... I was like digging into a bit more and then I talked to the contributors who were creating it and they said that you need to use the one. Let me find out. So the main part when I was... This was the main source of course. And here you can see that setting up on macOS is going to the virtual machine. I was creating this one already five months ago and I was digging into the reason but I don't remember right now what was the exact reason. But later I can revise the memory and find out if I will duplicate the same stuff I will remember what was the issue. But the fact was that there was impossible to connect it to the... to make it work the Docker container originally on the mac. So we use this way. Another question? Yep, yeah. I create like the PC and install there like Ubuntu server and then just SSH to that machine and create all the stuff there, which is like simpler. And the same thing if you used the same machine you can use the Docker Android without the Docker virtual box. So it can work also there. So you can have one powerful machine and put everything there. There is also a possibility to do exactly the same in the clouds but if you are going to pay to the cloud it's better to use the cloud emulators which is faster and easier. Any other question? So last but not least, this is my contact. In any case you want to contact me. Any question, anything to discuss? How we do any experience sharing? I will be happy to chat with you to find a solution together and then exchange the experience. Thank you very much for coming. I hope this was useful for you guys. This is the... If you are interested in just using the presentation step by step you can go. I try to do it on a sequence of the steps to make it work in your machine. So after it works on your machines later you can develop and make it nicer and a better solution for you. But this is just a basic step how you can start working with it. Thank you very much for coming.