12
Dec 12

## Robotframework Android Automation

Introduction

This is going to be a very quick tutorial to demonstrate that Robotframewok can be used to automate Android based smart phone applications. In this tutorial we are going to use Robotframework Android library which sits on top of Calabash Android framework. I tried it myself and was able to make it run however the downside is that it was not as reliable as I was expecting. For example, the setup procedure is flaky and takes time but I think it can be solved by separating the setup part from the test case part. The part that I did not personally like is clicking on text was not working consistently which is bad. Before we start I would like to repeat by saying I did not put much time on this experiment and I can not be so sure if the "not so good" results I got were because of the tools stack selection or were just my own mistakes. I would leave it to the reader to explore it more. The idea is to show that Robotframework is such an amazing automation tool that can be extended to do all kinds of test automation. As far as Android automation is concerned one can try other tools for example Robotium, Monkey Runner or even Sikuli. Let us get started by following the steps below:

Installation

1. I am assuming Windows 7 operating system
2. I assume you have Robotframework and RIDE already installed. For detailed information about installing these tools please refer to the following post
3. Install Robotframework Android library:
pip install --upgrade robotframework-androidlibrary
4. Robotframework Android library is based on Calabash Android which is in turn based on Ruby. You can get Ruby from here
5. Add Ruby bin directory to your path environment variable for example:
C:\\Ruby193\\bin to PATH environment variable
6. Install Calabash Android:
gem install --version '= 0.3.2' calabash-android
7. Install Android SDK. You can get it from here
8. Set the environment variable ANDROID_HOME and make it point to android SDK for example:
C:\\Users\\username\\AppData\\Local\\Android\\android-sdk
9. Add JDK bin directory to path environment variable for example:
C:\\Program Files (x86)\\Java\\jdk1.6.0_34\\bin
10. Download zip command for windows from here and save it into some directory that is included in system path
11. Create a key store which is used in signing JAR files:
keytool -genkey -v
-storepass android -alias androiddebugkey -keypass android
-dname \"CN=Android Debug,O=Android,C=US\"
12. For some reason I got an error while resigning the android APK file. I fixed that by removing:
-sigalg MD5withRSA -digestalg SHA1

from:

C:\\Ruby193\\lib\\ruby\gems\\1.9.1\\gems\\calabash-android-0.3.2\\bin\\calabash-android-build.rb

as I mentioned earlier this is nothing but an experiment and I did not invest enough time
to see if this could have any side effects. I just wanted to get rid off the annoying error
message.

Android SDK Commands

Behind the scenes Robotframework Android library and Calabash Android framework invoke commands provided by Android SDK. Take a look at the following commands in order to get a feeling of what they do. I am going to be using the ApiDemos.apk sample application. You can download the apk file from here

1. Make sure the following bat file exists:

%ANDROID_HOME%\\tools\\android.bat

2. To search for SDK updates:

%ANDROID_HOME%\\tools\\android list sdk --no-ui

3. To install updates apply:

%ANDROID_HOME%\\tools\\android update sdk --filter 1,2 --no-ui

where 1 and 2 are update numbers (you can get the numbers by applying the command in step 2)

4. Create an Android virtual device:

%ANDROID_HOME%\\tools\\android --silent create avd --name EM_NAME --target android-8 --force

where android-8 is the target API number and force is used to overwrite existing configuration

5. Start emulator

%ANDROID_HOME%\\tools\\emulator -avd EM_NAME -no-window

no-wondow option is used to supress the GUI and run it heedlessly

6. Invoke Android Debug Bridge (adb command):

%ANDROID_HOME%\\platform-tools\\adb wait-for-device

It is a command line tool that lets you communicate with an emulator instance or connected Android device. For more information about adb command click here.

7. If you want to download an installed app (in the form of an APK file) from emulator or device:

%ANDROID_HOME%\\platform-tools\\adb pull ApiDemos.apk

8. To unsign an APK file you can apply the command:

zip -d ApiDemos.apk META-INF\\*

9. In order to resign an APK file:

jarsigner -verbose
-keystore C:\\Users\\usename\\.android\\debug.keystore
-storepass android -keypass android ApiDemos.apk androiddebugkey

10. To build an instrumentation app:

calabash-android build ApiDemos.apk

11. To uninstall the app:

%ANDROID_HOME%\\platform-tools\\adb uninstall com.example.android.apis
%ANDROID_HOME%\\platform-tools\\adb uninstall com.example.android.apis.test

12. To install the app:

%ANDROID_HOME%\\platform-tools\\adb install -r C:\\robot\\suites\\apidemos\\test_servers\\ee2408368326bcd060d3e7e0bceb5dea_0.3.2.apk
%ANDROID_HOME%\\platform-tools\\adb install -r C:\\robot\\suites\\apidemos\\ApiDemos.apk

where [C:\\robot\\suites\\apidemos] is some directory containing the sample APK file. In this case it is the same directory containing robotframework test suite while [test_servers] is the directory created by calabash Android when building the instrumentation app (in this case: ee2408368326bcd060d3e7e0bceb5dea_0.3.2.apk)

Robotframework Syntax

Here is how the Robotframework test suite look like. Please note that the text was formatted to better fit in the page so if you just copy and paste, it might need minor editing to work with Robotframework. For example some long lines were broken into multiple lines:

*** Settings ***
Suite Setup       Setup Suite
Test Timeout       10 minutes
# This is used to invoke Android calls
Library       AndroidLibrary
# This is used to execute system calls
Library       OperatingSystem

*** Variables ***
${EMULATOR_NAME} my-emulator # Android target API level${API_LEVEL}       8
${HEADLESS} False *** Test Cases *** # Simple test case to touch text then varify some text on screen Touch Text Capture Screenshot Touch Text Text Capture Screenshot Touch Text Linkify Capture Screenshot Screen Should Contain http Capture Screenshot *** Keywords *** # Helper keyword to execute system commands # The keyword Run And Return Rc And Output is imported # from the OperatingSystem Robotframework built in library Execute [Arguments]${command}
${rc}${output} =
Run And Return Rc And Output       ${command} Should Be Equal As Integers${rc}       0

# Th Setup Suite keyword is a one to one mapping to
# the commands in the previos section
# It does the following:
# 1. Make sure the Android SDK exists
# 2. Create the virtual device
# 3. Start the emulator
# 4. Sign the APK file
# 5. Build the instrumentation app
# 6. Install the application under test
# 7. Start then connect with test server
Setup Suite
Android SDK Should Exist
# Update Android SDK
Create Android Virtual Device
${HEADLESS_BOOL}= Convert To Boolean${HEADLESS}
Start Emulator
${EMULATOR_NAME} no_window=${HEADLESS_BOOL}
# Pull ApiDemos.apk from Device
Re-Sign ApiDemos.apk with Debug Keystore
Build Instrumentation App
Install App
Wait For Device
Start Testserver with apk       ApiDemos.apk
Wait Until Keyword Succeeds
1min       5sec       Connect To Testserver

Android SDK Should Exist
File Should Exist       %{ANDROID_HOME}\\tools\\android.bat

Update Android SDK
Execute
%{ANDROID_HOME}\\tools\\android list sdk --no-ui
Execute
%{ANDROID_HOME}\\tools\\android update sdk --filter 1,2 --no-ui

Create Android Virtual Device
Execute       echo no | %{ANDROID_HOME}\\tools\\android
--silent create avd --name ${EM_NAME} --target android-${API_LEVEL} --force

Pull ApiDemos.apk from Device
[Timeout]       5 minutes
Wait For Device
Remove File       ApiDemos.apk
Wait Until Keyword Succeeds       30 seconds       5 seconds
Execute

Re-Sign ApiDemos.apk with Debug Keystore
File Should Exist       ApiDemos.apk
Execute       zip -d ApiDemos.apk META-INF\\*
Execute       jarsigner -verbose
-storepass android -keypass android ApiDemos.apk androiddebugkey

Build Instrumentation App
Remove Directory
${EXECDIR}\\test_servers\\ recursive=True Execute calabash-android build ApiDemos.apk${TEST_SERVERS}=
List Directory       ${EXECDIR}\\test_servers\\ # Get the generated instrumentation APK file name Set Global Variable${TEST_APK}       ${TEST_SERVERS[0]} Install App [Timeout] 5 minutes Uninstall Application com.example.android.apis Uninstall Application com.example.android.apis.test # Path to the generated instrumentation APK file Install Application${EXECDIR}\\test_servers\\${TEST_APK} # Path to the application APK file Install Application${EXECDIR}\\ApiDemos.apk


Robotframework Android Library Keywords

Here is the full list of Robotframework Android library supported keywords. That is it. Thanks for reading.

keywords: ,
17
Nov 12

## Microkernel vs. Monolithic OS Architectures

Introduction

Computer operating systems have been around for more than half a century so there is not much to add to the definition. Whether you are in the software industry or the academia, I assume you know what an operating system means but in few words an OS is the piece of software that sits between computing hardware and user applications. In this article, I am going to summarize and contrast some of the most popular operating systems architectures from a high level perspective.

Generally speaking, an operating system consists of two parts: a privileged mode called kernel space and unprivileged mode called user space. The separation is a need rather than an option otherwise process protection cannot be achieved. Depending on which processes run in what space, we can classify operating systems into three main architectures: Monolithic kernel, Microkernel and Hybrid or modular kernel operating systems. Let us now explore these architectures and see the good and bad about each one of them.

Monolithic Kernel

You can think of a monolithic kernel OS as a single large static binary file process running entirely in a single address space. Basic OS services such as process management, memory management, interrupt handling, IO communication, file system, device drivers, networking, etc all run in kernel space. Entire services are loaded on boot up and reside in memory and work is done using system calls. Linux is an example on a monolithic kernel based OS.

Generally speaking a monolithic OS kernel is faster due to small source and compiled code size. Less code means also less bugs and security issues.

Monolithic OS being a single big pile of code has disadvantages. For example, making changes is not easy and testing takes more time. It is hard to maintain, patch or extend. Bug fixing or adding new features requires the compilation of the whole source code which is a time and resource consuming process.

Microkernel

The idea behind microkernel OS is to reduce the kernel to only basic process communication and IO control and let other system services run in user space just like any other normal processes. These services are called servers and kept separate and run in different address spaces. Contrary to monolithic OS where services are directly invoked, communication in a microkernel is done via message passing (inter process communication IPC).  Mac OS and WinNT are two examples on microkernel OS architecture.

Here some advantages to the microkernel OS architecture…

1. Service separation has the advantage that if one service (called a server) fails others can still work so reliability is the primary feature. For example if a device driver crashes does not cause the entire system to crash. Only that driver need to be restarted rather than having the entire system die. This means more persistence as one server can be substituted with another. It also means maintenance is easier.
2. Different services are built into special modules which can be loaded or unloaded when needed. Patches can be tested separately then swapped to take over on a production instance.
3. Message passing allows independent communication and allows extensibility
4. The fact that there is no need to reboot the kernel implies rapid test and development.
5. Easy and faster integration with 3d party modules.

Here are some disadvantages to the microkernel approach…

1. Memory foot print is large
2. Potential performance loss (more software interfaces due to message passing)
3. Message passing bugs are not easy to fix
4. Process management is complex

Hybrid kernel

The hybrid approach is derived from the best of both micro and monolithic kernel architectures. Instead of loading the whole thing into memory, core modules are loaded dynamically to memory on demand. One disadvantage is that a module may destabilize a running kernel.

The Linus Torvalds Andrew Tanenbaum Debate

Linus Torvalds the main guy behind Linux is a strong proponent of monolithic kernels while Andrew Tanenbaum the creator of Minix OS is a supporter of microkernel. Tanenbaum says that microkernel is a better design principle especially when reliability is of uttermost importance. According to Tanenbaum, reliability scores over performance gains because microkernels allow building self healing systems.

Conclusion

I will conclude this article by saying there is no OS architecture that is better than the other in the general sense. I think comparing monolithic operating system is like comparing two different types of transportation for example a car and a bus where each meets different needs.

keywords: , ,
29
Oct 12

## Running GUI Tests in Minimized Windows Remote Desktop

Suppose that you have a remote Windows machine for example a virtual Windows machine in a test automation farm. You can use Windows remote desktop client to connect to that machine and monitor test automation progress. There should be no problem if you close the remote session if you are testing a background process however if you want to interact with the GUI then the moment you close the remote session then you are not going to be able to do that any more even if you keep the client running in a minimized window. To avoid this problem and keep the remote desktop window minimized while receiving input from the remote machine follow the steps below:

Login to the computer from which you want to connect to the remote VM
Close all open remote desktop sessions
Click Start
Click Run
Type "regedit"
Press Enter
Go to "HKEY_CURRENT_USER\\Software\\Microsoft\\Terminal Server Client"
Create a DWORD value named "RemoteDesktop_SuppressWhenMinimized"
Set value to 2
Close the Registry Editor.

keywords: