Appium – A Good Open Source Mobile App Testing Framework

In my opinion, in the next 5 to 10 years, nearly 50 to 60% of existing websites will be converted to mobile apps seeing how the usage of mobile apps is growing day-by-day. A challenge that will arise for mobile app developers is to test apps to ensure their performance. The offside of this is, manual testing, especially for each iteration, is an extremely cumbersome activity. Therefore, it is likely that most developers will opt for automating the software testing process.

Appium is the latest open-source framework that can be used to automate the execution of test scripts with multiple test cases for both Android and iOS platforms. Though there are a few other mobile test automation frameworks in the market, Appium has gained increasing popularity because of its simplicity.

Related: Meet the Exponential Growth, High Demand, And Requirement of Advanced Functionality with Innovation and Speed.

Appium framework can be used to automate Native, Hybrid, or Mobile browser web applications.

It works on the WebDriver JSON wire protocol.

Appium Workflow Diagram:

Appium workflow Diagram

How Appium interacts with iOS and Android Applications:

For automating iOS and Android mobile application testing, Appium uses the Apple Instrumentation library or Google UI Automator to stabilize the connection between Mac OS and iOS or Windows/Linux and Android. Instruments and UI Automator libraries provide application performance, memory analysis, and testing tools for dynamically tracing and profiling iOS and Android codes respectively.

It is a flexible and powerful tool that lets you track one or more processes and examine the collected data. In this way, instruments help you to understand the behavior of both user apps and operating systems.

Appium uses the XCTest framework which is developed by Apple in Swift or Objective-C Language.

More information about this instrument and UI Automator can be found at:

iOS – Apple Developer Tools

Android – Android UI Automator

Appium Architecture:

Appium is an HTTP server written in node.js which creates and handles multiple WebDriver sessions for different platforms like iOS and Android.

Appium starts a “test case” on the device that spawns a server and listens for proxied commands from the main Appium server. It is quite similar to the Selenium server which perceives HTTP requests from the Selenium client libraries and handles those requests in different ways depending upon the platforms. Each platform like iOS and Android follow different methods and mechanisms to run a test case on the device, and so Appium kind of hacks into it and run a test case after listening to commands from the Appium server.

Configurations that are required to run Appium on Windows:

Before download and install Appium in windows, make sure given prerequisites are fulfilled.

  1. JDK Installed
  2. Android SDK Installed
  3. Set ANDROID_HOME and Path Environment Variables
  4. Eclipse ADT Plugin Installed
  5. Node JS

Configurations that are required to run Appium on Mac:

  • Make sure to use Mac OSX version 10.7 and above
  • Firstly, you need to download the Appium app for Mac.
  • Move this app to your applications folder and then launch it using Mac Launchpad.
  • As Appium uses node.js internally, you also need to install node.js on the mac machine. This can be downloaded from http://nodejs.org/. It will download the node-v0.10.xx.pkg file which you need to install.
  • XCode 4.5 or higher version along with iPhone simulator SDK and Command Line Tools should be installed on the Mac machine.

Appium Advantages:

  1. Supports standard programming languages like Java, Ruby, C#, PHP, etc.
  2. Can be used for both iOS and Android platforms
  3. Supports automation of hybrid, native, and web mobile apps.
  4. Cross-platform
  5. Backend is Selenium; so you will get all of Selenium’s functionalities
  6. Does not require an APK for use.

Appium Disadvantages:

  1. Limited support for Android versions less than 4.1
  2. Appium documentation is not exhaustive
  3. Limited availability of tutorials.

Read Other Appium related blogs

How to Automate Testing for Android Native Apps Using Appium

Don’t miss my next blog on – Running Appium Automation Script on Android Emulators

Using Appium automation script to Check SQLite DB Content of a Device!

Automated Device Certification Testing On Cloud AWS Device Farm with Appium

Learn more about our app testing services / web app testing services

How to Programmatically Make your Android Phone Look Like an iPhone

In Android Operating System (OS) based on mobile phone or devices, the UI screen that appears first after the user presses the ‘Power on’ button is called the “Android Launcher Screen”. It is possible in Android to construct a custom launcher application, which can be used as a replacement for the default launcher application that comes along with Android phones. Unlike the iPhone, this is one of Android’s best features which lets you design your phone’s interface.

Android Launcher concept

The Launcher falls into one of two categories: ‘design’ or ‘smart’.

Design launchers focus on User Interface. You can change the entire layout of your Android phone’s home screen, application icon shape, icon drag and drop concepts, image gallery etc. You can customize everything it has to offer, including the themes, animations, layout, shortcuts and colors. Some of its interesting features include unlimited scrolling, customize app drawer layout, download-able themes and widget customization.

Smart Launchers learn the most relevant information about you which can be your wake up time, head out on your commute, work at the office, most favorite spot of city etc. You also can add custom gestures to your phone such as double-tapping the screen to open a specific application, web-page or specific setting.

Requirement

You need to have the following installed and configured on your development machine:

  • Android SDK and platform tools
  • Android Studio
  • An emulator or Android device running Android 2.2 or higher

Project Manifest.xml File Modification

In manifest.xml file add two activities. First activity displays the home screen and the second activity needs to display the applications that are installed on user’s device. It is also responsible for launching the installed applications. We don’t need any special configuration for this Activity.

Add the following two categories in Manifest.xml file to the intent-filter group. This intent-filter is associated with the Activity.

 <category android_name="android.intent.category.HOME" />
 <category android_name="android.intent.category.DEFAULT" />

We also need to set the android:launchMode to “singleTask” to make sure that only one instance of this Activity is held by the system at any time. To show the user’s wallpaper, set the theme to

android:theme=”@android:style/Theme.Wallpaper.NoTitleBar.Fullscreen”

 <activity
 android_name="ah.hathi.simplelauncher.HomeScreenActivity"
 android_label="Simple Launcher Home"
 android_theme="@android:style/Theme.Wallpaper.NoTitleBar.Fullscreen"
 android_launchMode="singleTask"
 android_stateNotNeeded="true">
 <intent-filter>
 <action android_name="android.intent.action.MAIN" />
 <category android_name="android.intent.category.HOME" />
 <category android_name="android.intent.category.DEFAULT" />
 </intent-filter>
 </activity>

Add one more activity in Manifest.xml file for displaying the applications that are installed on user’s device.

<activity
 android_name="ah.hathi.simplelauncher.AppsListActivity"
 android_theme="@android:style/Theme.NoTitleBar.Fullscreen" > </activity>

Launcher Main Activity Layouts

Add UI design code in Activity_HomeScreen.xml file. Here layout has a single Button that responds to click events. Clicking the button takes the user from home screen to the list of applications.

<RelativeLayout xmlns_android="http://schemas.android.com/apk/res/android"
 xmlns_tools="http://schemas.android.com/tools"
 android_layout_width="match_parent"
 android_layout_height="match_parent"
 tools_context=".HomeActivity" >

<Button
android:id=”@+id/home_screen_apps_button”
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”
android:layout_alignParentRight=”true”
android:layout_alignParentTop=”true”
android:layout_marginRight=”10dp”
android:layout_marginTop=”10dp”
android:text=”Show Apps”
android:onClick=”showApps”
/>
</RelativeLayout>

Next is to create an XML file for the AppListActivity class in the project’s res/layout folder and name it as activity_apps_list.xml. The layout contains a ListView that takes up the entire screen.

<?xml version="1.0" encoding="utf-8"?>
 <LinearLayout xmlns_android="http://schemas.android.com/apk/res/android"
 android_layout_width="match_parent"
 android_layout_height="match_parent"
 android_orientation="vertical" >

<ListView
android:id=”@+id/apps_list”
android:layout_width=”match_parent”
android:layout_height=”match_parent”
>
</ListView>

</LinearLayout>

Finally, create a third XML file in the same location and name it as list_item.xml. This file defines the layout of an item in the ListView

 <?xml version="1.0" encoding="utf-8"?>
 <RelativeLayout xmlns_android="http://schemas.android.com/apk/res/android"
 android_layout_width="match_parent"
 android_layout_height="match_parent"
 android_padding="10dp"
 >

<ImageView
android:id=”@+id/item_app_icon”
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”
android:layout_alignParentLeft=”true”
android:layout_centerVertical=”true”
/>

<TextView
android:id=”@+id/item_app_label”
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”
android:layout_toRightOf=”@+id/item_app_icon”
android:paddingLeft=”10dp”
/>

<TextView
android:id=”@+id/item_app_name”
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”
android:layout_below=”@+id/item_app_label”
android:layout_toRightOf=”@+id/item_app_icon”
android:paddingLeft=”10dp”
/>

</RelativeLayout>


Implementing the HomeScreenActivity Classes

With the layouts of the application created, it is time to create two Activity classes. When creating the two classes, make sure the name of each class matches the one you specified in the project manifest file earlier.

Create a new class named HomeScreenActivity and set android.app.Activity as its superclass.

Add this code in your HomeScreenActivity class or your main Activity class in onCreate method.

selectButton.setOnClickListener(new View.OnClickListener() {
 @Override
 public void onClick(View view) {

Intent i = new Intent(this, AppsListActivity.class);
startActivity(i);

}
});


We create an Intent for the AppsListActivity class and start it.

AppsListActivity Class

Create another Activity class named AppsListActivity and set android.app.Activity as its superclass. In the class’s onCreate method, we invoke setContentView, passing in the activity_apps_list layout we created earlier.

import android.app.Activity;
 import android.content.Intent;
 import android.os.Bundle;
 import android.view.View;

public class AppsListActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_apps_list);
}

}

AppDetail.java class file

Create a class named AppDetail that will contain the details of an application, its package name, label, and application icon. The interface is pretty basic as you can see below.

public class AppDetail {
 CharSequence label;
 CharSequence name;
 Drawable icon;
 }

Fetching installed Applications

In the LoadApplication method of the AppListActivity class, we use the queryIntentActivities method of the PackageMangaer class to fetch all the Intents that have a category of Intent.CATEGORY_LAUNCHER. The query returns a list of applications that can be launched by a launcher. We loop through the results of the query and add each item to a list named Apps.

private PackageManager manager;
 private List<AppDetail> apps;

private void loadApplication(){

manager = getPackageManager();
apps = new ArrayList<AppDetail>();

Intent i = new Intent(Intent.ACTION_MAIN, null);
i.addCategory(Intent.CATEGORY_LAUNCHER);

List<ResolveInfo> availableActivities = manager.queryIntentActivities(i, 0);
for(ResolveInfo ri:availableActivities){
AppDetail app = new AppDetail();
app.label = ri.loadLabel(manager);
app.name = ri.activityInfo.packageName;
app.icon = ri.activityInfo.loadIcon(manager);
apps.add(app);
}
}

List of Applications

The Apps variable containing all the details we need, we can show the list of applications using ListView class. We create a simple ArrayAdapter and override its getView method to render the list items. We then associate the ListView with the adapter.

private ListView list;
 private void loadListView(){
 list = (ListView)findViewById(R.id.apps_list);

ArrayAdapter<AppDetail> adapter = new ArrayAdapter<AppDetail>(this,
R.layout.list_item,
apps) {
@Override
public View getView(int position, View convertView, ViewGroup parent) {
if(convertView == null){
convertView = getLayoutInflater().inflate(R.layout.list_item, null);
}

ImageView appIcons = (ImageView)convertView.findViewById(R.id.item_app_icon);
appIcons.setImageDrawable(apps.get(position).icon);

TextView appLabels = (TextView)convertView.findViewById(R.id.item_app_label);
appLabels.setText(apps.get(position).label);

TextView appNames = (TextView)convertView.findViewById(R.id.item_app_name);
appNames.setText(apps.get(position).name);

return convertView;
}
};

list.setAdapter(adapter);
}

ListView OnClickListener Method for List item

When the user clicks an item in the ListView, corresponding application will be launched by our launcher. We use the getLaunchIntentForPackage method of the PackageManager class to create an Intent with which we start the application.

private void addonClickListener(){
 list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
 @Override
 public void onItemClick(AdapterView<?> av, View v, int pos ,long id) {
 Intent i = manager.getLaunchIntentForPackage(apps.get(pos).name.toString());
 AppsListActivity.this.startActivity(i);
 }    
 });<br > }

Putting It All Together

We need to invoke loadApplication, loadListView and AddClickListener in the onCreate method of AppsListActivity class as shown below.

protected void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
 setContentView(R.layout.activity_apps_list);

loadApplication();
loadListView();
addClickListener();
}

Conclusion

Build and run your application once more to see the result. You should now be able to see the applications that can be launched when you click a button on the home screen of our launcher. Click on an item to launch the corresponding applications. That’s it! Now, try to mimic the UI look and feel of iPhone in your launcher application as you have got complete control over everything!

Here’s a quick read to help you update Android apps outside of Google Play.