Seminar on Android Automation Using Robotium

Video is ready, Click Here to View ×

Robotium is an Android test automation framework that has full support for native and hybrid applications. Robotium makes it easy to write powerful and robust automatic black-box tests for Android applications. With the support of Robotium, test case developers can write function, system and acceptance test scenarios, spanning multiple Android activities.


o Robotium Background/ Short Introduction
o What we can do with Robotium
o What we can’t do with Robotium (Limitations)
o Requirements
o Getting Started (Installations and Configurations)
o Working Flow of a Robotium Project
o A Short Demo

Please find the PPT details from Slide Share link below –

Video is ready, Click Here to View ×

Presenter: Abhishek Swain, Mobile Testing Engineer, Mindfire Solutions

2 thoughts on “Seminar on Android Automation Using Robotium

  1. Hello all, I am Abhishek Swain, I am working in Mindfire Solutions since 7 months and today I am going to give the seminar on Robotium. Those are on GTM, my voice is clear? Ok, so going through the agenda of today, today we will have introduction of Robotium, that is what it is and why we are using that one. Then we will discuss on the features of this tool. Then we will discuss the limitations of this tool that currently it has. Then we will discuss about configuration etc. and then we will create a project and have a discussion on execution flow of this project and then we will have a demo.
    So Robotium is an open source project that is Java based . So it is hosted under google code and source code goes to GitHub. So founder and developer of this tool is one guy named Redas Rana and he developed this tool when he was working with Jayway. Now they  have their own company called Robotium Tech and they are maintaining this project  right now.
    Basically Robotium is a Java based library, it contains some functions, like we can use those functions to do all the user actions that we do in a mobile device. Like tap, touch and input something and slide. All those functions, we can have in this library to achieve those stuff. So user develops automation scripts using Java and Android software development tool, that is called adt(android development tool) bundle that comes with some API for testing as well.
    So what is done in Robotium that they have reused those API to create some robust functions so that we can use them to have our automation project on Android. So coming to the features of Robotium, now what we can do with Robotium. We can automate Android applications of native and hybrid type. So coming to what is native application and what is a hybrid application, like pure native application contains some native elements like buttons, text fields and all.
    Those APIs and views are provided with Android sdk and hybrid application is native app with some WebViews. Robotium can support activities, native views, web views, toast messages and almost all UI elements that we get from an Android application. What are activities is like in web application we see different pages.

    So we can have the synonymous thing here. Like one screen we will call  one activity. So what are activities, like comparing it with the web application, in a web application we call one page, that is one page is comparable to one activity in Android application. Native views are the views like buttons and text fields, that we generally see in Android applications. Those are called native views.
    Web views are web elements embedded in that  application. So those things are called web views. Toast messages that appear for a small time and then disappears. So I will show what are toast messages in one of my demo. Where we can run our automation script? We can run automation script in emulators as well as real devices.
    In emulators we can have all the versions of Android and we can have almost all possible size of the screen that is available presently in the market. So Robotium has the facility , we develop test scripts once and then run it over all kind of Android versions available. So robotium is independent of screen size and resolution. That is our automation script can run over different sizes of screen and also having different resolutions.
    Its not coordinate based. Like we are not targeting the elements by coordinates, so test script is robust. So it works on all versions of Android and works on all sizes of devices. Its a very good feature that it handles all the activities automatically. That is here pages are comparable to activities so we have multiple activity in an application. Robotium detects all the activities automatically.
    Suppose we are navigating from one activity to other then Robotium is going to detect that second activity automatically. We need not to mention the second activity. We just need to have the launcher activity name and that's it.
    Now coming to the limitations. We have some tools for web automation, like selenium. It supports all client libraries like Java, C sharp, ruby etc. languages are supported. But here we have a limitation, we need to write our automation test scripts using Java only. No other language bindings are there to use.
    There is another limitation of Robotium, like it doesn't support flash. That is we can't automate flash based views. Now question comes, do we need source code of the application we are going to test. The answer is No, we can have our automation script without the source code. We can also develop test scripts if we have the source code of the application under test, that is white box testing.
    Suppose we have source code in the same workspace and we want to have an automation script of that application. We can do it, and suppose we don't have the source code, but we have only the installer file of the Android platform, that is called apk. We can use that. We can develop almost all scenarios that we cover to develop our test scripts.
    Now what are the requirements to get started with Robotium. We need Android sdk. I have given this link, from here you an download, that is called an adt bundle (Android development tool) that comes with inbuilt eclipse. That is a customized version of eclipse with Android development tool plugin. And then we need Java and eclipse. And for building and dependency management we are using Maven.
    Maven plugin for eclipse is required to manage the dependencies and control the Maven project inside eclipse. These are the path settings that we need to have our project. Like Java home, that is basically the path setting for Java and Android home, we can set and in the system path we need to include 2 folders, that is tools and platform tools. These 2 folders comes with the Android sdk.
    Then we need to have Maven home in our path so that we can build our project with Maven commands. Now as I said, we can have our test run on emulators as well as real devices. Now how we can create emulators. Like now I am demonstrating, like how we can create emulators. This is the eclipse, that is the customized version which comes with Android sdk.
    Now to create one emulator, we have to navigate this way, Window-Android virtual device manager. Here we can create Android virtual devices, that is called emulator. Here we can give a name, then we need to select a device, like what screen sizes of devices we want and some predefined devices are there, like Nexus 7, 5 and all definitions like properties of these devices has been already set by google.
    So we can select them or we can select a screen type with the resolution. Then we need to select the Android version. We all are aware of that Android comes with different versions like 4.1, 4.2. So they have their own name like jelly bean, kitkat etc.
    Here we need to select the API version or Android version. Now like our system has different kinds of processors, like Intel and all. So mobile devices have processors like ARM and Intel Atom etc. those are for small devices. So we need to select the processor type that will be emulated in the system and the behaviour of that emulator will be according to that processor.
    So if we select ARM then the behavior of the emulator will be exactly like what the device should be doing if it has a ARM based processor. Then we can select hardware keyboard present like in the emulator we can give the input from our system only. So if you are checking this option, then we can give the input from the keyboard. Otherwise we have to use the soft keyboard that comes with the emulator.
    Here we can mention the RAM and Heap memory. That is a basic thing. Mobile devices have RAM so we can give it here and also mention the internal storage of the device. Then we can also emulate SD card in the emulator. Like in the mobile devices we have SD cards. So we can mention the size of SD card here.
    Question: You told about different kind of processors like ARM, what are those and why it is required?
    Response: Yes, exactly. Suppose we want to have the test run on a specific kind of device. Like we have samsung galaxy s3 and .. features of this. Like what is the processor type, what is the RAM etc. we can mention those things there so that we can have an environment exactly like samsung galaxy. Like one application can behave differently with different processor types.
    So if we are selecting ARM then the application in this emulator  will behave exactly like what it would be doing in real device having ARM. So this is the fact.
    Question: Emulators that you are creating is provided by android development tool?
    Response: This is Android specific and this is the inbuilt feature of Android sdk and we also have third party emulators like GenyMotion and all. If we want ready made configurations then we can use them also.
    Like this device I have created right now. You can see its listed under the devices. So we can create multiple devices over here and run multiple devices at the same time. So clicking on the start button, we will having one emulator, like this. So this way we can configure emulators. Now coming to real devices. Now real devices we can connect using a micro or mini usb cable, that depends on device type and to enable usb debugging we need to enable it in the real device.
    Like in settings we have an option of developer tools, we can go there and enable usb debugging so that we will be able to debug that device from this computer.
    Question: I can see some application icons on the Emulator opened , what are those?
    Response: Yes those are the pre installed applications. Like Android OS, and it has some inbuilt application like mail, like some stuff like settings and all those things you see in mobile. So those things come inbuilt and we can install our application we are going to test into that device. Then we can see the icon of that application inside that.
    Now, to test our application we need to  resign it. Why? Because the signature of both test project and application we are going to test must match. So what is signature, its nothing but information of the developer, like first and last names and other stuff. Those things need to be sent in both test application and application we are going to test. And if its mismatching then we can't open the application under test and test will fail.
    So, how to resign one apk file. We can have it from command line, we can have it from a tool called re-sign, that is basically jar files. Now I am demonstrating how to resign one apk application. This is one application called wordpress, this is an open source application, so I have chosen this one. To resign it I need to delete the signature information that it already has. To do that, I need to open it with any zip utility like 7Zip or WinZip.
    I need to delete this one, meta-inf folder. This folder contains all the signature information and certificate of the developer. I have directly deleted it this way. Then I need to resign this application. For resigning we have this command. Before this we need one file called debug.keystore. That is the certificate file that this Android eclipse generates automatically and that contains the signature information of the default user of the system.
    So to create that file we need to navigate this way. Users, .android so here we have debug.keystore, we need to copy this file and put it in same folder where apk file is. Now I need to mention the name of the apk file. So now this application is signed and we can check, again its exploring in zip utility. Here its signed with our signature.
    Second way is, there is a tool available called re-sign.jar. This is a jar file. This has a gui interface and we can just drag-drop the application here. And it will prompt to save the debug signed version of the application.
    Question: How debug.keystore generates?
    Response: No, that will be generated when compiled any Android application in this eclipse, then that gets simulated automatically. Now this is the signed version of our application. Now, how we can install the application to the emulator or device. We have certain commands for that. Like these are the example commands that we can use to interact with emulator or real device.
    Like adb devices, this is one command to check the devices that are currently connected to the system. Like I have only one emulator present, so its showing this thing only. Then if, we need to install this application to emulator. So we can use another command. Adb install then the application name. So it takes some time to get inserted in emulator.
    Question: If we are not re-signing the application, wht happens?
    Response: No, it will be installed successfully but when we will have a script run then it will throw one error like certificate mismatch or something like that.

    Question: What happens when multiple Emulators/devices connected?
    Response: No, then we need to mention the emulator, like we have some parameters like hypen E and hyphen D. We can use hypen E and we can mention emulator name there to instal it in a particular emulator. If we have connected a real device, then we need to mention, like adb instal hyphen D and the device name and then after the other stuff.
    If you will run directly this one, like adb instal without mentioning the device and that particular time we have multiple devices connected to this computer, then it will throw an error, like multiple devices connected. Now after the success message, we can check, the application has been installed to this emulator. So this is the application. So we have confirmed that this has been installed.
    So we have some other commands, like we need to uninstall some application. We can use a command, adb uninstall and the package name of that particular application. I will show how to get package name of these installed applications. And if we need to copy some file from our system to that emulator, that might me internal memory, that might be SD card. So we can use adb push and then the file name or the folder name and then we can mention the path to where we want to copy that file inside emulator.
    Suppose we need to copy one file from emulator to system, we can use this one adb pull. Now, I will show how to create one project and configure it and add the dependencies and all.
    Question: What is that apk file?
    Response: Apk is the build file of installer build of Android platform. Like we have exe and all msi in Windows platform. There in Android platform its apk. So this way we need to create one project, like we need to create an Android test project. Giving a project name. Now here we have 2 options like this project and an existing Android project. Like I said, we have have our automation script over, if we have the source code, we can also write the scripts if we don't have the source code.
    Now if you will select this project, then you are indicating that we don't have source code of the application under test in this workspace and you will be running this script on an application that already is installed to the emulator or device and when we are selecting this one, existing Android project, that means we are indicating that application that we are going to test, the source code of that complete project is available on this workspace.
    Here we will test an apk file so I am selecting this project. Now I need to convert this project to maven project so we can have dependency management. First I need to create the structure of maven project, like source main Java. Now to convert into maven project we need to instal the maven plugin for eclipse that I have already installed with this version of eclipse. So to convert it to maven project just I need to right click on this project name and then configure, then convert to maven project.
    Now with the .. file we need to add dependency of robotium. So this is dependency of robotium that I added to .. file so that library of robotium can be added to the .. path of this project. Now we need to create one package. And then we need to create one class file where we will write our automation scripts.
    Now how we will indicate the thing, which application we are going to test that is already installed with that emulator. For that we need package file of that application. So how to get that package name. We have several options for that, like we can run that application directly in the emulator and that package file will be indentified from a prospective that comes with Android eclispe, that is called hierarchy view. From hierarchy view we can have that.
    Now when you run that particular application in emulator we can see the package and present activity in left navigation bar. Here you can see my activity is over here, this is the homescreen of the application and here we have This is the package name and account, let me expand this one. So this is the highlighted one. You can see the stop that is after this class, this is the activity name.
    Here we have package like That we need to mention in manifest file of our Android test project. Here you can see, one thing, target package. It is the package name of the application we are going to target or on which we are going to have our test run. OK, now we are going to develop the automation script that we can run on that particular application. So to understand the workflow of this project, this project is based on Junit3. We are extensively using junit4 but its little different than this. To start with, we need to inherit one class that comes with Android sdk called activity instrumentation test case 2.
    Question: Why to inherit ActivityInstrumentationTestCase2?
    Response: Yes, I mean in junit 3 we have a feature, like everywhere we need to inherit test case, that is a class called test case. Means that facilitates you to write your automation scripts. As they have modified this junit3 to of their own, so instead of test case we are inheriting this class. Ok, now we have to define the launcher activity class name here. Like launcher activity class name, like I have demonstrated here in the hierarchy view prospective. Like this is the launcher activity, when we are launching the application we are calling this activity. So we need to mention the full class name of this.
    Now you can see I have one string variable called launcher activity class name and I am initializing it with the class name we got from hierarchy view. Here I have created one instance of solo. Solo is the main class of robotium. Like it contains all the functions that we are going to use while developing the automation script.
    So there is one static block. Like we know in Java static blocks gets executed at the loading time, that is before other blocks get executed these static blocks get into. So that we can initialize the things before we have something running. And this one is the constructor, so when instance of this test class will be created then this constructor will be invoked. So that laucher activity class, that means the screen of the Android application that we are going to test will be launched when this constructor will be invoked.
    Ok, now setup and teardown these are the inbuilt functions of Junit3. Like we have before and after those annotations are there in junit4. Before the execution of any test method, that before annoted method is executed and after that, but in junit3, that setup takes the place of before annotation and this teardown takes the place of after annotation. So whenever we are executing one test, then before execution of that test this setup method will be executed and when that test is finished no matter its passed or failed this teardown method will be executed.
    So in the setup we are initializing the solo instance we created. So here we have 2 methods, like get instrumentation and get activity. These 2 methods belongs to this class activity instrumentation test case 2. This is the cause, so we have extended activity instrumentation test case 2. Now coming to this function like get instrumentation.
    So what is instrumentation, its actually a class that is inbuilt in Android platform, which monitors all user actions that the automation script does and it reverts back the application. That means this is the mediator, that is monitors all actions that user is doing on a particular application or particular activity. So we are calling that class for this reason. And what get activity does, get activity launches the launcher activity when its called.
    If its present then its okay, if not, then it will launch that particular activity in the emulator. And in the tear down method, in the solo class we have one method called finish open activities. Like when one test is executed then you need to finish that activity. Like we need to restart again in that activity for the test. So its synonymous to close driver, quit driver in selenium.
    Now in junit 4 we develop test scripts using annotations, called tests. Here these annotations doesn't matter, I mean when its executed, the test methods are not recognized by annotations. Its recognized by  a keyword called test. If we are writing our test methods and in the test function that name starts with test, that means it indicates the execution unit that its a test method and this should be executed according to that.
    So if I want to click on this second button, this is add blog hosted at I want to click on this button. So now we have 2 options, like.. Now how we can get the locators from the activity. Like in selenium we have different stuffs like fire.. firepath and we have ID to get the locators. Like how we can target the elements over one activity. We have 2 options, we can use index like the first text field has index 0, second has index 1 and so on. We can use ID over there.
    When an Android application is created, then the developer assigns some ID to each element. So we can use those developer provided ID to target those elements. If we don't have the source code, so how to get the ID from the application. For that again, we have to use hierarchy view. So this is the activity and I need to target the elements on this activity. For that I just need to click over here. This loads all UI elements and its hierarchy to this view.
    Ok actually it takes sometime to load the view structure so… ok for some reason its not loading right now so we can test it. For now I am just targeting by index. Like you can see this is the second button so it has index one, like test button that method name I am giving. We can develop test functions like this, on button. We have 2 things here, like index we can pass, like 1 and if you want to pass the ID, then we can pass the ID as a string.
    Lets run it, while running we need to run it as Android junit test. So as I said its a customized version of junit3, so the name is Android junit. One thing we missed, like we need to check the build path if the robotium dependency has been added or not. Like this way you can go to build path and add all those things.
    Questions: Why that error was?
    Response: yeah, actually the jar file of the robotium is not added to the build path that's why it has thrown a class not found error.
    Questions: Wht to add jar of Robotium?
    Response: jar file of the robotium. Like the dependency of the selenium .
    Questions: What if we do not add it in build path.
    Response: Yes, it will throw error. Like I have added a maven dependency here for robotium. So that library is already added and while running we just need to add it to the build path so that the compiled file of the robotium library gets into the apk file getting generated and that will be installed in this emulator and that apk file is responsible to run the tests for our application under test.
    You can see from the logs, its installing robotium session.apk, that is the test project that we created. So it will install first then it will call the instrumentation class to start the activity that we are going to test and that activity will be launched in the emulator, then the test, like see this is the activity that has been launched and clicked on the second button.. see after clicking this screen opens.
    Now you can see this test method has been passed. So this way we can define our test methods. So from where we can get the API definitions or the functions that robotium is providing us. This is the link that I have provided over here. We can navigate to this link to have the Java Doc of that project and to have a brief eye on the packages that are available with robotium. Like By is a class that is synonymous to buy of that we were using in selenium.
    Basically its used to target on web elements. As I said, its complete support for web use also from a hybrid application point of view. Suppose we need to target some web elements like links or some stuff that is related to HTML content. Then this class is used, like, buy… those can be used. Conditions this package has only one method, that is called e satisfied. Inside that we can put some conditions like, if something is present or not, or something is happening after doing some stuffs  we can check the condition by this package and then solo is the major class of the robotium. Like it contains all the functionalities and almost 95 percent of the methods that we are going to use. We will get from this package solo.
    And solo.config, we can set the timeouts. If we are waiting for some text or for some button, we can set the timeout there. And screen shot file type or presently there are 2 types of screen shot supported with robotium. One is png and other is jpg. Timeout is also another class to define timeout of various functions. Like we have some functions wait for, get, those stuff can be controlled from this timeout library.
    And web element, this is the package from where we can interact with web elements that we have done with the buy class. Its the same thing. Now how we can run the test project. Like I have shown how we can run from the eclipse. We have option to run the things from the command line. So these commands can be used to run the test from the command line and we can specify one particular function also in this.
    Questions: What are the annotations in Robotium?
    Response: Yeah.
    I noticed something I missed. These are the annotations that is available with Android test project, like there are lots of annotations available. These are major used annotations. Like small test, medium test, large test. And this flaky test is interesting. Like if we are setting one tolerance, like 1, 2, 3 that way, and integer in which test method we are giving the tolerance that repeats for that much number that we are giving in the place of ..
    like in the first attempt that particular test is failed, then we have given the tolerance 2, then it will again run on that particular thing and it will check for the results. So as we said, the test methods gets detected from keyword called test. So why we will use these annotations, like small test, medium test and large test. We can have control over our test run by using annotations. Here you can see run configurations. You can mention which annotation you want to run.
    So robotium as demonstrated is fully supported by maven. We can also build this complete project using maven. For that we have a separate plugin called Android maven plugin that we need to use and also we can use continuous integration tools like jenkins which is also supported. I have prepared a small demo with 3-4 functions, I am just running it.
    From run configuration we can mention the device also. Like on this device we need to run the test. Like always prompt to pick device, this will prompt you with an window, like which device you want to be selected and then launch on all compatible devices that will launch the test on all compatible devices that has been connected or that kind of emulators that is already in the system. Or if we haven't opened an emulator or connected a device, then it can automatically open an emulator and run the device, that option can be selected from here.
    During this test run if you have any questions?
    Question: How it is recognized that which app to start in the Emulator?
    Response: Yes, I mean you just need to instal that apk to the emulator, and that is done. Then we need to create the test project and run over that. Because we know the bundle ID, the package name of that application, we know the launcher activity class name. That will mentioning if this test project and now while running it, that will automatically target that application.
    Questions: You told about two apk files?
    Response: Yeah, I mean here 2 apk come to the picture. One is that apk file  that is uat application under test that we are installing it. And second one gets generated while running our test project. Suppose, this one is our test project. When we run this one, then after compilation it generates one apk file that you can see here in the bin folder.
    Questions: Why we are not installing that 2nd apk?
    Response: No, we don't need to do anything. While running it from eclipse, it will automatically instal that test apk and it will run the test automatically. We can also do that, we can manually instal these files and then we can run the test files from command prompt. We can manually do that too but while running from eclipse it automatically does.
    Questions: What is this apk file getting generated?
    Response: Now see when you compile some Java program then some jar files get generated. So that is the outcome of that project. Here the outcome is an apk file, that is after compilation this apk file gets generated. And this Android adt plugin is configured such that while running it will generate this one in bin folder and it will automatically install to the emulator and launch the test. So we are not controlling that thing.
    So, we will get the reports in this format. Like we have customized this to a framework and this reports gets generated inside emulator and we can pull it from emulator and have these results.

Leave a Reply

Your email address will not be published. Required fields are marked *