Android Automation Testing with Selendroid

37
Android Automation Testing with Selendroid

Transcript of Android Automation Testing with Selendroid

Page 1: Android Automation Testing with Selendroid

Android Automation Testing with Selendroid

Page 2: Android Automation Testing with Selendroid

Agenda

Testing? Mobile Testing Types & challenges Selenium

IDE RC Webdriver Grid Webdriver Demo

Selendroid Selendroid Architecture Selendroid standalone & server Selendroid Capabilities & Inspector Selendroid Demo

Page 3: Android Automation Testing with Selendroid

Testing

• A process of demonstrating that errors are not present ?

OR• A way of establishing confidence that a program

does what it is supposed to do ?OR

• A means of achieving an error-free program by finding all errors ?

A “DESTRUCTIVE”, yet creative process

Page 4: Android Automation Testing with Selendroid

TestingRequirements

Capture

Analysis

Test planning & Scenario

Design

Test Case Development

Test Execution

Test Result Analysis

Test Cycle Closure

Defect Fixing Cycle

Defects

New Version

The Scenarios Design and the Test Case Development could normally start in parallel with the Development Cycle.Test Execution Synchs up with the Development Cycle during the functional Testing Phases

Page 5: Android Automation Testing with Selendroid

Mobile Testing

Page 6: Android Automation Testing with Selendroid

Mobile Testing - Types UI testing Functional testing Interrupt testing

Internal interruptsExternal interrupts

Device specific testing Performance testing Security testing Compatibility testing Localization and i18n testing Automation testing Network testing Sound testing

Page 7: Android Automation Testing with Selendroid

Mobile Testing – Challenges Devices – The biggest Mobile Testing challenge

Diversity of the Mobile OSs and there flavors

Diversity in Hardware Configuration

Network related challenges

Competitive market

Change in market trend

Page 8: Android Automation Testing with Selendroid

Automation & Frameworks Why Automation? Frameworks –

Test Script Modularity• This can be achieved by creating small, independent scripts that

represent modules, sections, and functions of the application-under-test and later can be combined in a hierarchical fashion to construct larger tests.

Test Library Architecture• The test library architecture framework is very similar to the test

script modularity framework but it divides the AUT into procedures and functions or objects and methods instead of scripts.

Data-Driven Test Automation Framework• A data-driven framework is where test input and output values

are read from data files (ODBC sources, CVS files, Excel files, ADO objects, and such) and are loaded into variables in captured or manually coded scripts.

Page 9: Android Automation Testing with Selendroid

Automation & FrameworksKeyword-Driven Test Automation Framework This requires the development of data tables and

keywords, independent of the test automation tool used to execute them and the test script code that "drives" the AUT and the data.

Hybrid Test Automation FrameworkThe most commonly implemented

framework is a combination of all of the above techniques, pulling from their strengths and trying to mitigate their weaknesses.

The most successful automation frameworks generally accommodate both Keyword-Driven testing as well as Data-Driven scripts.

This allows data driven scripts to take advantage of the powerful libraries and utilities that usually accompany a keyword driven architecture.

The framework utilities can make the data driven scripts more compact and less prone to failure than they otherwise would have been.

Page 10: Android Automation Testing with Selendroid

Introduction To selenium What is selenium?

Selenium is a suite of tools to automate web browsers across many platforms.

Portable software testing framework for web apps. Test can be written in Java, C#, Groovy, Perl, PHP, Python and

Ruby. Tests can be executed on all modern browsers Platform Independent Open source software Latest release v2.44 (as on 23rd Oct 2014) Selenium extended to selendroid and ios-driver to automate mobile

applications

Page 11: Android Automation Testing with Selendroid

Selenium Components

1. Selenium IDE2. Selenium 1.0 – Remote Control3. Selenium 2.0 – WebDriver4. Selenium Grid

Page 12: Android Automation Testing with Selendroid

1. Selenium IDE

Helps you to develop Selenium test cases Easy to use firefox plug-in Supports record and playback Command , Target & Value Test Cases & test suites saved in “html” format Tests can be exported in other formats like java,

C# , php etc using formatters.

Page 13: Android Automation Testing with Selendroid
Page 14: Android Automation Testing with Selendroid

1. Selenium IDE – Test Case

Page 15: Android Automation Testing with Selendroid

Selenium IDE – Export Test Case

Page 16: Android Automation Testing with Selendroid

Java / Junit 4 / Webdriver tests

Page 17: Android Automation Testing with Selendroid

2. Remote Control

Selenium Remote Control (RC) is a test tool that allows you to write automated web application UI tests in any programming language against any HTTP website using any mainstream JavaScript-enabled browser.

Selenium RC comes in two parts.  A server which automatically launches and kills

browsers, and acts as a HTTP proxy for web requests from them.

Client libraries for your favorite computer language.

Page 18: Android Automation Testing with Selendroid

Selenium RC Architecture

Page 19: Android Automation Testing with Selendroid

3. WebDriver

Driving a browser natively as a user would either locally or on a remote machine using the Selenium Server

Selenium 1.0 + WebDriver = Selenium 2.0 WebDriver is designed in a simpler and more

concise programming interface along with addressing some limitations in the Selenium-RC API.

Page 20: Android Automation Testing with Selendroid

4. Selenium Grid

Selenium-Grid allows you run your tests on different machines against different browsers in parallel.

That is, running multiple tests at the same time against different machines running different browsers and operating systems.

Selenium-Grid support distributed test execution. It allows for running your tests in a distributed test execution environment.

Page 21: Android Automation Testing with Selendroid

4. Grid Architecture

Page 22: Android Automation Testing with Selendroid

Introduction To Selendroid Selendroid is a test automation framework which drives off the UI

of Android native and hybrid applications (apps) and the mobile web.

Tests are written using the Selenium 2 client API - that's it! Selendroid can be used on emulators and real devices and can be

integrated as a node into the Selenium Grid for scaling and parallel testing.

Page 23: Android Automation Testing with Selendroid

Features of Selendroid

Full compatibility with the JSON Wire Protocol/Selenium 3 Ready. No modification of app under test required in order to automate it Testing the mobile web using built in Android driver webview app Same concept for automating native or hybrid apps UI elements can be found by different locator types Gestures are supported: Advanced User Interactions API Selendroid can interact with multiple Android devices (emulators or

hardware devices) at the same time Existing Emulators are started automatically Full integration as a node into Selenium Grid for scaling and

parallel testing Multiple Android target API support (10 to 19) Built in Inspector to simplify test case development. Selendroid can be extended at runtime with your own extensions !

Page 24: Android Automation Testing with Selendroid

Getting Started with Selendroid System Requirements

Mac / Linux / Windows Java SDK (min 1.6)

Set JAVA_HOME

Latest Android-SDK http://developer.android.com/sdk/index.html Set ANDROID_HOME

Android Virtual Device or Android Hardware Device Selendroid standalone server

Page 25: Android Automation Testing with Selendroid

Selendroid Architecture

Major Components Selendroid-Client - the java client library (based on the selenium java client). Selendroid-Server - that is running beside your app on the Android device. AndroidDriver-App - a built in Android driver webview app to test the mobile web. Selendroid-Standalone - manages different Android devices by installing the selendroid-

server and the app under test.

Page 26: Android Automation Testing with Selendroid

Selendroid-Server

Selendroid-server is the main component responsible for the app automation.

The central driver class is DefaultSelendroidDriver. This class is responsible for doing the common activities (like taking screenshots) for both contexts NATIVE_APP and WEBVIEW

The web view related driver class is SelendroidWebDriver and native class is SelendroidNativeDriver.

Page 27: Android Automation Testing with Selendroid

Selendroid-Standalone

Central driver class is SelendroidStandaloneDriver that acts as a proxy between the selendroid-client and the selendroid-server

Starts an Android emulator, creates for the app under test a customized

selendroid-server and installs everything on the device. After the session

is initialized on the device, subsequent requests are directly forwarded to the

server on the device and the response routed back to the client.

Page 28: Android Automation Testing with Selendroid

Getting an AUT ready for automation Selendroid can be used to test already build apps.

(.apk) The .apk file must be existing on machine where

selendroid-standalone server will be stared. customized selendroid-server for the app under

test (AUT) will be created Both apps (selendroid-server and AUT) must be

signed with the same certificate in order to install the apks on the device

Page 29: Android Automation Testing with Selendroid

Launching Selendroid Java –jar <<selendroidstandalone.jar>> –app <<myApp.apk>>

java

-jar selendroid-standalone-0.12.0-with-dependencies.jar

-app selendroid-test-app-0.12.0.apk Selendroid-standalone will start a http server on port 4444 It will scan all AVDs that the user has created. The Android target version and the screen size will be identified. If an emulator is running, it can be used If there are Android hardware devices plugged in, they will also

be added to the device store. Check application status on :

http://localhost:4444/wd/hub/status.

Page 30: Android Automation Testing with Selendroid

First Tests

In order to create a new test session in the desired capabilities, the appId of the app under test must be provided in the format: io.selendroid.testapp:0.12.0.

Based on that information a matching Android device will be identified, otherwise the test session will throw an error and not start

After the found device has been initialized, a customized selendroid-server will be created and automatically installed on the device.

The app under test will also be installed and the selendroid-server on the device will then be automatically started.

After the test session has been successfully initialized, the test commands such as 'find an element' and 'element interactions' are routed to this device. If the test session has ended, the emulator will stop automatically

Page 31: Android Automation Testing with Selendroid

Desired Capabilities (SelendroidCapabilities) Mandatory properties new SelendroidCapabilities( ... ):

This requests an app for the test session without any preference about emulator or hardware device.

SelendroidCapabilities.emulator( ... ): This requests an emulator and will fail the test session if

no emulator is available. SelendroidCapabilities.device( ... )

This requests a hardware device and will fail the test session if no device is plugged in.

SelendroidCapabilities.android( ... ) This starts a mobile web testing session.

Page 32: Android Automation Testing with Selendroid

Desired Capabilities (SelendroidCapabilities) For testing native or hybrid apps:

aut Specify the app id of the app under test (aut). E.g.

io.selendroid.testapp:0.12.0 For testing Mobile Web:

browserName Value must be android to start the 'Android driver

webview app'.

Page 33: Android Automation Testing with Selendroid

Desired Capabilities (SelendroidCapabilities)Optional Properties emulator

If True, an emulator will be requested. If False, a hardware device will be requested.

platformVersion Specify the Android target API version of the device.

E.g. for KitKat it is: 19 locale

Specify the locale of an emulator to be used in the test session. During the start the locale will be automatically configured. E.g. de_CH

Page 34: Android Automation Testing with Selendroid

Desired Capabilities (SelendroidCapabilities)Optional Properties screenSize

Specify the screen size of the device: e.g. 720x1280 display

Specify the display number that is used to start the emulator on. Supported only in Linux platforms. E.g. 1

preSessionAdbCommands Specify a list of adb commands that will be executed

on the target device before selendroid-server will be started. E.g. shell setprop name selendroid,

Page 35: Android Automation Testing with Selendroid

Selendroid Inspector

Page 36: Android Automation Testing with Selendroid

Selendroid Inspector

It helps to inspect current state of app’s UI. http://localhost:4444/inspector Features

View hierarchy View UI element properties UI screenshot with view locator Record the click actions Display the source html of a web view XPath helper

Page 37: Android Automation Testing with Selendroid

Thank You …

By Vikas Thange(Automation Testing consultant)[email protected]