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
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
Testing Requirements 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
Mobile Testing
Mobile Testing - Types  UI testing  Functional testing  Interrupt testing Internal interrupts External interrupts  Device specific testing  Performance testing  Security testing  Compatibility testing  Localization and i18n testing  Automation testing  Network testing  Sound testing
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
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.
Automation & Frameworks Keyword-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 Framework The 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.
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
Selenium Components 1. Selenium IDE 2. Selenium 1.0 – Remote Control 3. Selenium 2.0 – WebDriver 4. Selenium Grid
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.
1. Selenium IDE – Test Case
Selenium IDE – Export Test Case
Java / Junit 4 / Webdriver tests
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.
Selenium RC Architecture
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.
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.
4. Grid Architecture
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.
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 !
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
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.
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.
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.
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
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.
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
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.
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'.
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
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,
Selendroid Inspector
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
Thank You …  By Vikas Thange (Automation Testing consultant) vikasthange@gmail.com

Android Automation Testing with Selendroid

  • 1.
  • 2.
    Agenda  Testing?  MobileTesting  Types & challenges  Selenium  IDE  RC  Webdriver  Grid  Webdriver Demo  Selendroid  Selendroid Architecture  Selendroid standalone & server  Selendroid Capabilities & Inspector  Selendroid Demo
  • 3.
    Testing • A processof 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
  • 4.
    Testing Requirements Capture Analysis Test planning & ScenarioDesign 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
  • 5.
  • 6.
    Mobile Testing -Types  UI testing  Functional testing  Interrupt testing Internal interrupts External interrupts  Device specific testing  Performance testing  Security testing  Compatibility testing  Localization and i18n testing  Automation testing  Network testing  Sound testing
  • 7.
    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
  • 8.
    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.
  • 9.
    Automation & Frameworks Keyword-DrivenTest 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 Framework The 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.
  • 10.
    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
  • 11.
    Selenium Components 1. SeleniumIDE 2. Selenium 1.0 – Remote Control 3. Selenium 2.0 – WebDriver 4. Selenium Grid
  • 12.
    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.
  • 14.
    1. Selenium IDE– Test Case
  • 15.
    Selenium IDE –Export Test Case
  • 16.
    Java / Junit4 / Webdriver tests
  • 17.
    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.
  • 18.
  • 19.
    3. WebDriver  Drivinga 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.
  • 20.
    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.
  • 21.
  • 22.
    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.
  • 23.
    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 !
  • 24.
    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
  • 25.
    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.
  • 26.
    Selendroid-Server  Selendroid-server isthe 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.
  • 27.
    Selendroid-Standalone  Central driverclass 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.
  • 28.
    Getting an AUTready 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
  • 29.
    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.
  • 30.
    First Tests  Inorder 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
  • 31.
    Desired Capabilities (SelendroidCapabilities)  Mandatoryproperties  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.
  • 32.
    Desired Capabilities (SelendroidCapabilities)  Fortesting 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'.
  • 33.
    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
  • 34.
    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,
  • 35.
  • 36.
    Selendroid Inspector  Ithelps 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
  • 37.
    Thank You … By Vikas Thange (Automation Testing consultant) vikasthange@gmail.com

Editor's Notes

  • #19 http://docs.seleniumhq.org/projects/remote-control/
  • #22 http://www.guru99.com/introduction-to-selenium-grid.html
  • #25 http://selendroid.io/setup.html
  • #26 http://selendroid.io/setup.html
  • #27 http://selendroid.io/setup.html
  • #28 http://selendroid.io/setup.html
  • #29 http://selendroid.io/setup.html
  • #30 http://selendroid.io/setup.html