28
Android Automation Using Robotium Presenter : Abhishek Swain, Mindfire Solutions

Android Automation Using Robotium

Embed Size (px)

DESCRIPTION

This presentation would help give a jump start guide on Robotium for getting started with Android automation should join this Seminar.

Citation preview

Page 1: Android Automation Using Robotium

Android Automation Using Robotium

Presenter : Abhishek Swain, Mindfire Solutions

Page 2: Android Automation Using Robotium

About Me: Abhishek Swain, Software QA EngineerMindfire Solutions

Skills : Robotium , Appium , Selenium WebDriver , Maven , Junit , SQL ....

Certifications : ISTQB Foundation Level, V-Skills Selenium Certified

Connect Me :Facebook : http://www.facebook.com/jikun55LinkedIn : http://in.linkedin.com/pub/abhishek-swain/58/8a/829/

Contact Me :Email : [email protected] /[email protected]: mfsi_abhishekswain

Page 3: Android Automation Using Robotium

Agenda

Introduction Features of Robotium Limitations Configurations and Creating a project Discussion on project work flow Short Demo

Page 4: Android Automation Using Robotium

Short Introduction

Open Source Project hosted under Google code (Source Code : GitHub)

Founder and Developer : Redas Rana (Jayway) Now Project maintained by Robotium Tech Basically its a JAVA jar Library containing robust

functions User develops automation scripts using JAVA Android SDK Library(android.test) provided for

testing is used with Robotium

Page 5: Android Automation Using Robotium

What We can do with Robotium:Features List: Can write Automation scripts for Native as well as

Hybrid android applications Supports Activities, Native Views, Web Views,

Toasts and Almost all UI Elements Can test against Emulators as well as real devices One script for all versions of Android  Independent of Device screen resolution and Size  Not co-ordinate based, so Robust Multiple Activities handled automatically

Page 6: Android Automation Using Robotium

Limitations : 

No other Client Library supported except Java No Support for Flash

Page 7: Android Automation Using Robotium

Do we need Source Code ??

Automation Scripts can be written without source code – Complete support for Blackbox Testing

We need the installer build of android platform  i.e apk file

Can also be written if we have Source code – Hence supports Whitebox Testing

Page 8: Android Automation Using Robotium

Requirements :

Android SDK   Download Link: http://developer.android.com/sdk/index.html

Java JDK Eclipse Maven Maven Plugin for Eclipse        Installation Link :http://download.eclipse.org/technology/m2e/releases

Installations: 

Page 9: Android Automation Using Robotium

Requirements :

JAVA_HOME Path of 'bin' directory in System path

ANDROID_HOMEPath of 'Tools' & 'Platform-Tools' in System Path

MAVEN_HOMEPath of 'bin' directory in System path

Configurations/Environment Variables: 

Page 10: Android Automation Using Robotium

Creating Emulators & Configuring Real Device

Emulator: 1. Can be created from 'Android Virtual Device Manager' that is a part Android

SDK

2. Can also be created from command line after necessary path settings

Real Devices:1. Enable USB Debugging from settings in device

2. Connect using micro/mini USB Cable with PC

3. Install necessary drivers for USB debugging according to device manufacturer

Page 11: Android Automation Using Robotium

Re-Signing APK

Signature of both AUT and Test project must match, so Re-Signing necessary

Unsign .apk Re-sign it with debug.keystore

Command : jarsigner -verbose -sigalg MD5withRSA -digestalg SHA1 -keystore debug.keystore [AUT_name].apk androiddebugkey

Default Password: android Resign Jar Tool can also be used

Page 12: Android Automation Using Robotium

Installing app to Emulators/Device & Some basic commands 

Check for connected/available devicesadb devices

Install app to Device/Emulatoradb install [AUT_name].apk

Uninstall appadb uninstall [application package name]

copy file from PC to Device/Emulatoradb push [file_path]/[File_name_with_extension]

copy file from Device/Emulator to PCadb pull [file_path_on_device]/[File_name_with_extension] [folder_path_PC]

Page 13: Android Automation Using Robotium

Creating Android Test Project

Create a new Android Test Project from Eclipse

File --> New --> Android Test Project

Convert it to a Maven Project

Add the following Dependency of Robotium to pom.xml

       <dependency>            <groupId>com.jayway.android.robotium</groupId>            <artifactId>robotium-solo</artifactId>            <version>5.0.1</version>        </dependency>

Page 14: Android Automation Using Robotium

Configuring Android Test Project

Define Target Package in AndroidManifest.xml

How to get Activity class names of AUT ?

From Hierarchy ViewerFrom Dev Tools - Package ExplorerFrom Logcat

Page 15: Android Automation Using Robotium

Developing Test Script :

Inherit ActivityInstrumentationTestCase2 in the TestClass

public Class TestClass_Name extends ActivityInstrumentationTestCase2

Continued..

Page 16: Android Automation Using Robotium

Developing Test Script :

Create instance of Solo class Define launcher activity class name Define setUp() and tearDown() methods Define test methods

Page 17: Android Automation Using Robotium

Understanding Workflow of Android Test Project

Based on Junit - Android Junit Test is the customized version of Junit3

Methods :setUp() and tearDown()

Test Function Naming ConventionMust start with keyword 'test' e.g testLogin()

What happens while Executing :Two apk files gets installed : AUT apk and Test Project apk

Page 18: Android Automation Using Robotium

How Android Junit3 Different from Junit4

setUp() and tearDown() take the roles of @Before and @After of Junit4

Test Function Naming ConventionMust start with keyword 'test' e.g testLogin()

With Junit4 methods annoted with @Test recognized as test methods

Page 19: Android Automation Using Robotium

Annotations Available with Android Junit Test Project

Most Frequently Used Annotations:

@Smoke@SmallTest@MediumTest@LargeTest@FlakyTest(tolerance=n)

To execute a particular Group of test methods annotations are useful

Can be specified while running test from Eclipse and command line

Page 20: Android Automation Using Robotium

How to Target Elements on Activity

By Indexe.g solo.enterText(0,"some text");

By Ide.g solo.getView("Id_Of_Element");solo.enterText((EdiText)solo.getView("Id_Of_Element")," some text");

Page 21: Android Automation Using Robotium

How To Get Ids ??

If we have Source code of AUT, Ids can be identified from code

If we don't have Source Code, Hierarchy Viewer can be used which Comes with Android SDK

Page 22: Android Automation Using Robotium

Robotium Classes and API Definitions

Classes:

ByConditionRobotiumUtilsSoloSolo.ConfigSolo.Config.ScreenshotFileTypeTimeoutWebElement

API Documentation Link:http://robotium.googlecode.com/svn/doc/index.html

Page 23: Android Automation Using Robotium

Modes Of Running Tests

From Eclipse : As Android Junit TestAnnotations, Target Devices can be mentioned in Run Configurations

From CommandLine: 

adb shell am instrument -w -e size [small/Medium/Large] Testprojectpackagename/android.test.InstrumentationTestRunner Particular Classes or Particular Functions can also be specified from command Line

 adb shell am instrument -w  -e class [class_name_with_package] Testprojectpackagename/android.test.InstrumentationTestRunner

Page 24: Android Automation Using Robotium

Support For Build Tools and CI Integration Servers

Can be used with Build Tools like Maven , Ant etc Android-Maven-Plugin is used to Build with Maven Can be integrated with Continuous Integration (CI)

server like Jenkins/Hudson

Page 25: Android Automation Using Robotium

Demo : 

Page 26: Android Automation Using Robotium

Questions ?? 

Page 27: Android Automation Using Robotium
Page 28: Android Automation Using Robotium

www.mindfiresolutions.com

https://www.facebook.com/MindfireSolutions

http://www.linkedin.com/company/mindfire-solutions

http://twitter.com/mindfires