 Welcome everyone, welcome to yet another session on Android Automation Testing with APMM Ultimate and we have Roo with us. Hi everyone. We are really glad to have Roo here with us today. Thank you and welcome everyone. I'll start with a quick introduction about myself so that you understand why I'm talking about game automation. I've been a tester since 2002 and I think my first project was testing a mobile app and since then most of those 20 years have been somehow related to a mobile project, a mobile testing, mobile automation and in the last few years, over six years I've been doing a lot of specifically mobile game automation and game game testing in general and I'm also one of the main contributors for this alt unity tester tool which is an open source tool for game automation specifically for unity and my talk is going to show the use of this alt unity tester alongside Apium for doing game automation. I'll show a little bit of how that happens with the real game and the real Android device. My kind of journey towards game game development happened in Helsinki. I'm based in Helsinki and my company where I'm one of the founding members Altom is originally from Romania but we have offices here in Finland and in Helsinki I started working with a company a while ago called Bitbar. They are still active but they've been since acquired by smart there but they offer access to devices, real mobile Android and iOS devices in the cloud where you can run either run like your application and test it remotely or you can run automated tests mostly via Apium which is I think the most common platform for doing cross-platform automation for mobile. So I started working with them because they had a few clients that were developing mobile games and wanted to test their games on using automation and specifically Apium on devices in the cloud and they were running into some problems because Apium could only help them so much and this is what I'm going to try to show you here with this presentation. What are the limitations that we have and what are the solutions that we have access to at the moment for game automation? So most mobile games and games in general are built using a so-called game engine. My talk is focused specifically on Unity which is a game engine that offers a lot of built-in elements for developing a game. You have a lot of the physics world already built in, you have a lot of good character development support, character animations and so on and you write your game code in one single language and C sharp in Unity's case, you build your game within the Unity editor, you can test it within the Unity editor and then you can export it on many different platforms from consoles to PC and mobile as well, both iOS and Android and the problem with that is that while it's very convenient to have this cross-platform tool you also have the inconvenience of the not having access with tools like Apium to the game objects that are coming from within the game engine. And I'll try to show an example of this, I have here, okay it says that my screen sharing is paused, I wonder why, maybe I need to stop the... Is it? I don't know if this is something that, okay, does this work now? Can you see the Unity, I'll take tacto, I guess this is good now. We can see your presentation, can you share it again? Make it full screen now? But I was hoping, oh, so you don't see the full screen, okay, I need to share again then, I think. One second, I will share, I think I shared probably not the full screen, but just the, okay, so can you now see the full screen? I'll take tacto game. Okay, sorry about that. So this is the Unity editor, this is the main kind of environment where you would build your game and this is one of the games that we use as an example for teaching. It's a very simple take tacto game, I will press the play button here so that we can actually play the game and you can do this with all of the games, you can actually run them and play them within the Unity editor without having to install them on a target platform. So this is the game in action and this is how the game is built, we have all these elements here, we have the logo, some buttons, this is how they are arranged in the game and this is the hierarchy of elements that we have from the Unity editor. It's a bit small but hopefully they're not that important in detail what they are, just like we can see in, for example, in Chrome in the development tools, the DOM elements, this is how we see the game elements in Unity. And the game is very simple, we can click play now and just play a take tacto game, we could restart it, we could go back and there's another button here that's called share, if I click it here nothing actually happens within the Unity editor and this is one of those things where we just see something in the console but actually this is a button that on a real device would open a dialogue, like the native share dialogue that you would have where you could share this application to work via Bluetooth or messages or something like this but because this is a platform specific feature we won't see it within the Unity editor. So this is the point where we would try it on an actual platform, I will stop the playtime now and I'll show you. So if we wanted to build this from Unity on any of these platforms we could choose one of those and then just click build and it would create the build for iOS or for Xbox or and so on. Now I've already used Android and I want to show you the game also running on a real Android device, I won't do the build now but basically this creates an APK which is just like any other mobile app except you know it's a game but we can use, in this case I was going to show it by using the Appium inspector just to install this APK on the phone and I have, let me just open it here, the Visor app to try to show you also the mobile phone. I have the same phone over here on my desk connected to my Mac but just to kind of see it better here I, so you know if I do something here it's going to show up on the same in this Visor app. So I will start the session with Appium inspector that should install the application, we should see it here soon, installed AuticTacto, there it is and it should start it and show us, allow us to inspect it like we would with Appium. So I have Appium kind of running here in a terminal already, the Appium server. So okay we see the exact same app, I can play it here and of course this is happening on the device as well. Same thing, the only difference here is that when I click the share button this actually opens this native dialog that I explained earlier and I can click back and go back to it. So now if we try to inspect this app here is where the tricky part comes, so far this looks like any other Android app but if I try to kind of drill down to find the objects this is the kind of the only object that I see, it's a so-called game view, an Android view that contains all of the exported Unity objects so I don't have any access to any of these elements over here. What I would want to and from an automation point of view what I would like to interact with is all of these buttons that we also see over here in Unity but from the inspector we this is basically a black box but on the other hand what is not a black box is the native dialog here, if I refresh the inspector this will actually show all of the native elements in these we can use with Appium and we could interact with them and assert on them. So this part that wasn't available in the Unity editor is available using Appium. So if I go back to the presentation I will just put this again in slideshow but with the game companies that were trying to run automation with Appium on devices in the cloud, well we tried a few approaches and one of them was with image recognition but it didn't really work the way we or didn't have the flexibility and the speed that we wanted so what we were looking for was a solution that would give us access to this structure, to this hierarchy of game objects they are called in Unity on the device so we can access them from the code and when we started working on the alternative tester tool that I will show we realized that the moment we add a game object here in the scene of Unity within the game this knows everything about all of the other objects that are in there so if we could open if this object here could open a connection to the game as like a back door then from the tests we could basically from a script we could have an alt Unity driver we call it that would connect to this back door and would be able to interact with any of the elements so just like the Appium driver we would have an alt Unity driver that would then load a specific level find objects with different locators and then interact with them so this is the solution that we built and I have the link over here and I'll share it later on we'll look at this later on as well it supports C-sharp and Java and Python and I'm going to try now to show you what it would mean to actually write a couple of Python tests for this so within Unity we would need to install a package that would add that object to the to the game it's a package that you could import like you import a lot of any a lot of other Unity plugins it's a very typical way of adding functionality to your game and that gives us access to a few extra settings like we saw the one for building the Android we have here a build button that would actually give us a same game the exact same APK and the same game but it would also have this little object inserted in there that would allow us from the scripts to connect to the game and inspect the element so I already have another application built and I have set up here a very simple project in Python that uses a pytest to try to run a couple of tests that use both the apium driver and the alt Unity driver so this is a bit annoying I have the controls here so I need to move this a little bit so I have because we're using pytest we have a fixture that provides the drivers this provides sets up the the apium driver like I'm sure you're all familiar with the only thing special here is that we use the apk is the instrumented one so the one that has this little thing inside it and then we also have an alt Unity driver that is created in Conf test and they are available for our test over here the test does nothing yet so I will just start it in debug and we'll stop here on this break point and we can look at the at the game on the device let's see and then try to write a couple of tests for this game okay the application is now installed and it looks basically exactly the same as before the only difference is that we have this little object over here if we click on it it's going to tell us that there's a client connected this is the instrumented part that gives us a connection to the Unity elements through the alt Unity driver and assuming that we want to now write some tests that would for example first find the play button or make sure that it's on the page then click on this one to show the share dialogue and then just click back to close it we would have to kind of be mindful of which driver we use so first for the play button we would use the alt Unity driver because it's a Unity element and we would do find or wait for object for example wait for object by name in this case we can we can use by name we have a few other locators and the name for this we get it from the Unity editor this one is called play button over here so we can put that in there we could also copy the same thing and wait for the let me put this back wait for the share button instead of play I remember that that's the name of it and with this one we could also tap on it once we find it and now if when we tap the share button this would open the this dialogue and this is a dialogue that is native for which we would actually have to use the opium driver this time and we could use find element here I will kind of copy this because I have already saved it so we don't need to spend time trying to inspect it so this would basically wait to find this dialogue when it's open and we could have another step just to kind of show the integration with native actions we could with the opium driver click back so that we use this android back button that is specific for for android so I could I will stop this and restart the test now and we can we should see it running in also in debug so I'll try to do this step by step I see that we have a couple of questions but this is the kind of the last thing that I will show because we have just quite little time left so I will look at them in just a moment all right so we are here we are waiting to see the play button if I go over this okay the play button was found then it should look for the share button and tap on it so it found the share button tapped on it now we're moving on to the opium driver that should look for this element and then hopefully click back for the android and this is the whole test so very short demo but this kind of shows the the use of both of the drivers based on the need we could we could switch between native elements and and unity elements quite nicely in a test and and seamlessly interact with the with the application and and the game and we could do a lot of functional automation this way I didn't have any other this was my my main slides I'll leave this here for a bit if you want to check the link and I will see what questions we had here okay so someone somebody's asking is there any other way to get properties or only via unity the locators unity is the main the unity editor is the main way we also are working on an inspector that is similar to the one that opium has but it's that one is not open source and it's also something that you don't necessarily need but it's something that you it can ease your development work but unity editor works quite well for for this purpose at least hopefully this answers the question there's another question that says I still have a little bit of time how much effort does it take from developer side to add this in the build it's it's really it really doesn't take we can you can add that as part of your build it's just a one line command in most cases so it doesn't take a lot of effort from a developer's time to to build this okay I don't know if we do we have I think we are kind of out of time at the moment and let's it's time to wrap it up yeah it's really a nice to get your experience root thank you so much for that