SAFS Robotium Remote Control Development


 Author: Carl Nagle
  Since: FEB 12, 2012
Updated: FEB 13, 2012 with recommended Robotium Package and Class names.
Updated: FEB 13, 2012 new robotium-messages.jar for Robotium Test Runner Project.
Updated: FEB 22, 2012 new safs-messages.jar for SAFS Test Runner Project.
Updated: MAR 27, 2012 new safsautoandroid.jar for Robotium Remote Control standalone.
Updated: DEC 13, 2012 new JAR dependencies for RobotiumTestRunner and SAFS Test Runner Projects.
Updated: MAR 13, 2013 new JAR dependencies for SAFS Test Runner Projects.
Updated: MAY 17, 2013 new JAR dependencies for both Controller and TestRunner Projects.

Copyright SAS Institute, Inc.
http://www.sas.com
General Public License (GPL)
http://www.opensource.org/licenses/gpl-license.php

This doc captures notes and setup information for developers providing SAFS/Robotium Remote Control features and functions. Below are the 3 separate development projects required for SAFS and/or Robotium Remote Control:

SAFS Robotium Remote Control Projects

  1. Development Project 1: Remote Control

    Fairly standard Java/Eclipse Project.
    As of Robotium 4.1, there is a new dependency on the standard Robotium JAR file: robotium-solo-4.1.jar, or later.
    That code is also referenced in Development Project 3.

    • For purely Robotium RC development, there are dependencies on:

      • safssockets.jar, or the sourcecode for:

          org.safs.sockets package
          org.safs.sockets.android package

      • safsautoandroid.jar, or the sourcecode for:

          org.safs.android.auto.lib package
          org.safs.android.auto.tools package

          org.safs.tools.CaseInsensitiveFile
          org.safs.tools.GenericProcessMonitor

          org.safs.tools.consoles.GenericProcessConsole
          org.safs.tools.consoles.GenericProcessCapture

          org.w3c.tools.codec.Base64Decoder
          org.w3c.tools.codec.Base64Encoder
          org.w3c.tools.codec.Base64FormatException

      • robotium-serializable.jar, or the sourcecode for:

          com.jayway.android.robotium.remotecontrol package
          Developer custom serializable classes (By, Condition, etc..)

      • robotium-remotecontrol.jar, or the sourcecode for:

          com.jayway.android.robotium.remotecontrol.solo package

      • robotium-solo.4.x.jar, or the sourcecode for:

          com.jayway.android.robotium.solo.By
          com.jayway.android.robotium.solo.Condition

    • For SAFS Robotium RC development you simply have the normal SAFS development dependencies plus:

      • robotium-remotecontrol.jar, or the sourcecode for:

          com.jayway.android.robotium.remotecontrol.solo package

      • robotium-solo.4.x.jar, or the sourcecode for:

          com.jayway.android.robotium.solo.By
          com.jayway.android.robotium.solo.Condition

      • robotium-serializable.jar, or the sourcecode for:

          com.jayway.android.robotium.remotecontrol package
          Developer custom serializable classes (By, Condition, etc..)

      • ddmlib.jar from the Android SDK tools\lib directory

    The code must compile and build.  Any changes to safssockets.jar must be exported to Development Projects 2 and 3 prior to their build operations.  The safssockets.jar, safsautoandroid.jar, and robotium-remotecontrol.jar are used by testers or developers wishing to write tests using Robotium Remote Control standalone--that is, without a full SAFS install.

    :SAFSSOCKETS_JAR -- used by Remote Control, TCP Messenger, and All TestRunner APKs
    %JRE%\jar cf safssockets.jar org\safs\sockets\*.*
    copy safssockets.jar %DEV_PROJECT_2%/libs
    copy safssockets.jar %DEV_PROJECT_3%/libs
    
    :SAFSAUTOANDROID_JAR -- used by Remote Control only
    %JRE%\jar cf safsautoandroid.jar org\safs\android\auto\*.*
    %JRE%\jar uf safsautoandroid.jar org\safs\tools\CaseInsensitiveFile.*
    %JRE%\jar uf safsautoandroid.jar org\safs\tools\GenericProcessMonitor.*
    %JRE%\jar uf safsautoandroid.jar org\safs\tools\consoles\GenericProcessConsole.*
    %JRE%\jar uf safsautoandroid.jar org\safs\tools\consoles\GenericProcessCapture.*
    %JRE%\jar uf safsautoandroid.jar org\w3c\tools\codec\*.*
    
    :ROBOTIUM_SERIALIZABLE_JAR
    %JRE%\jar cf robotium-serializable.jar com\jayway\android\robotium\remotecontrol\*.class
    copy robotium-serializable.jar %DEV_PROJECT_3%/libs
    
    
    :ROBOTIUM_REMOTECONTROL_JAR -- used by Remote Control only
    %JRE%\jar cf robotium-remotecontrol.jar com\jayway\android\robotium\remotecontrol\solo\*.*
    
    :ROBOTIUM_MESSAGES_JAR -- used by All TestRunner APKs
    %JRE%\jar cf robotium-messages.jar com\jayway\android\robotium\remotecontrol\solo\Message.*
    copy robotium-messages.jar %DEV_PROJECT_3%/libs
    
    :SAFS_MESSAGES_JAR -- used by SAFS TestRunner APK only
    %JRE%\jar cf safs-messages.jar org\safs\android\remotecontrol\SAFSMessage.*
    %JRE%\jar uf safs-messages.jar org\safs\text\FAILKEYS.* org\safs\text\GENKEYS.* org\safs\text\ResourceMessageInfo.*
    %JRE%\jar uf safs-messages.jar org\safs\text\CaseInsensitiveHashtable.* org\safs\text\FileLineReader.* org\safs\text\INIFileReader.* org\safs\text\INIFileReader$*.*
    copy safs-messages.jar %DEV_PROJECT_3%/libs
    
    :SAFS_GUICLASSDATA_JAR -- used by SAFS TestRunner APK only
    %JRE%\jar cf safs-guiclassdata.jar org\safs\GuiClassData.* org\safs\JavaConstant.* org\safs\IndependantLog.*
    %JRE%\jar uf safs-guiclassdata.jar org\safs\jvmagent\AgentClassLoader.* org\safs\logging\AbstractLogFacility.*
    %JRE%\jar uf safs-guiclassdata.jar org\safs\tools\drivers\DriverConstant.* org\safs\tools\CaseInsensitiveFile.*
    copy safs-guiclassdata.jar %DEV_PROJECT_3%/libs
    
    

  2. Development Project 2: SAFS TCP Messenger

    Standard Android "Service" Project.  The app is a Service, not an application with Activities.  It is a standalone application with no dependencies on Robotium or Robotium Remote Control.  But it does have dependencies on the classes in safssockets.jar. Additionally, the project builds a safstcpmessenger.jar file which becomes a dependency to Dev Project 3--or any Android application project wishing to use the TCP Messenger for remote/external TCP communication.

    The SAFS TCP Messenger is production stable and requires little or no change over time regardless of changes to Robotium, SAFS, or any other application wishing to exploit its TCP services.

    Development dependencies for the SAFS TCP Messenger in the project's /libs directory:

    • safssockets.jar, from Development Project 1.
    • org.safs.android.messenger; sourcecode.

    Important Android project setup notes:

    • ant.properties or local.properties: requires a single variable declaration added:

        safs.droid.automation.libs=<path.to.dev_project_3>/libs

    • build.xml: requires a post-compile operation creating a safstcpmessenger.jar file and copying to the /libs directory of Development Project 3:

          <target name="-post-compile">
              <jar destfile="${safs.droid.automation.libs}/safstcpmessenger.jar" >
                  <fileset dir="${out.classes.absolute.dir}" includes="**/MessageUtil.class" />
                  <fileset dir="${out.classes.absolute.dir}" includes="org/safs/android/messenger/client/*.*" />
              </jar>
          </target>
          

    • and, the AndroidManifest XML:

        <?xml version="1.0" encoding="utf-8"?>
        <manifest xmlns:android="http://schemas.android.com/apk/res/android"
              package="org.safs.android.messenger"
              android:versionCode="1"
              android:versionName="1.0">
            <application android:label="@string/app_name"
                         android:debuggable="true" >
        	    <service android:name="org.safs.android.messenger.MessengerService"
        	             android:icon="@drawable/bidi_arrows"
        	             android:enabled="true"
        	             android:exported="true"
        	             android:label="@string/app_name">
        	        <intent-filter>
        	        	<action android:name="org.safs.android.messenger.Connect" />
        	        	<action android:name="org.safs.android.messenger.Shutdown" />
        	        </intent-filter>
        	    </service>
            </application>
            <uses-permission android:name="android.permission.INTERNET"/>
            <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
        </manifest>
        

      Upon a successful build of the TCP Messenger APK it should be installed to replace any previous version of installed on the Android device or Emulator.

        ant debug
        adb install -r bin/safstcpmessenger-debug.apk

  3. Development Project 3: SAFS/Robotium Test Runner APK

    We are currently building a single APK that is either a Robotium Test Runner APK or a SAFS Test Runner.

    While Robotium is historically packaged up and referenced as a JAR file dependency in a tester or developer test APK, there is now significantly more Android test dependency when using Robotium Remote Control.  For example, now the test application must launch and use the SAFS TCP Messenger--usually through the InstrumentationTestRunner subclass RobotiumTestRunner, or its DSAFSTestRunner extension.

    Development dependencies for the Robotium Test Runner APK in the project's /libs directory:

    • android-support-v4.jar, from Android SDK--ONLY for pre-Android 4.0 APK development.
    • safssockets.jar, from Development Project 1.
    • safstcpmessenger.jar, from Development Project 2.
    • robotium-messages.jar, from Development Project 1.
    • robotium-solo-4.x.jar, standard Robotium dependency.

    Development package sourcecode for the Robotium Test Runner APK in the project's /src directory:

    • com.jayway.android.robotium.remotecontrol.client
    • com.jayway.android.robotium.remotecontrol.client.processor

    For the SAFS Test Runner APK, the dependencies in the project's /libs directory is the same, but has 2 additional JAR files:

    • safs-messages.jar, from Development Project 1.
    • safs-guiclassdata.jar, from a SAFS/Robotium Distribution.

    For the SAFS Test Runner APK, the package sourcecode in the project's /src directory is the same, but has these additional sourcecode packages specific to Android testing:

    • org.safs.android.engine package
    • org.safs.android.engine.processor package

    • Android: org.safs.robot package

    • Android: org.safs.tools package
    • Android: org.safs.tools.input package
    • Android: org.safs.tools.stringutils package

    For the SAFS Test Runner APK, the package resources in the project's /res/raw directory contains the following:

    • java_objects_map.dat
    • object_types_map.dat
    • safs_keycode_map.dat

    There are no abnormal build XML or property file setups for this Android project.   However, you do want to set the build.xml project name according to which APK we are building:

      <project name="RobotiumTestRunner" default="help">

    or

      <project name="SAFSTestRunner" default="help">

    Below is the typical Robotium Test Runner AndroidManifest XML:

      <?xml version="1.0" encoding="utf-8"?>
      <manifest xmlns:android="http://schemas.android.com/apk/res/android"
                package="com.jayway.android.robotium.remotecontrol.client"
                android:versionCode="1"
                android:versionName="1.0">
          <!-- We add an application tag here just so that we can indicate that
               this package needs to link against the android.test library,
               which is needed when building test cases. -->
          <uses-sdk android:minSdkVersion="10" />
          <application android:label="Robotium Test Runner"
                       android:debuggable="true" >
              <uses-library android:name="android.test.runner" />
          </application>
          <!--
          This declares that this application uses the instrumentation test runner targeting
          the package of com.example.android.spinner.  To run the tests use the command:
          "adb shell am instrument -w com.jayway.android.robotium.remotecontrol.client/com.jayway.android.robotium.remotecontrol.client.RobotiumTestRunner"
          -->
          <instrumentation android:name="com.jayway.android.robotium.remotecontrol.client.RobotiumTestRunner"
                           android:targetPackage="com.android.example.spinner"
                           android:label="General-Purpose Robotium Test Runner"/>
      </manifest>
      

    Below is the typical SAFS Test Runner AndroidManifest XML:

      <?xml version="1.0" encoding="utf-8"?>
      <manifest xmlns:android="http://schemas.android.com/apk/res/android"
                package="org.safs.android.engine"
                android:versionCode="1"
                android:versionName="1.0">
          <!-- We add an application tag here just so that we can indicate that
               this package needs to link against the android.test library,
               which is needed when building test cases. -->
          <uses-sdk android:minSdkVersion="10" />
          <application android:label="SAFS Test Runner"
                       android:debuggable="true" >
              <uses-library android:name="android.test.runner" />
          </application>
          <!--
          This declares that this application uses the instrumentation test runner targeting
          the package of com.example.android.spinner.  To run the tests use the command:
          "adb shell am instrument -w org.safs.android.engine/org.safs.android.engine.DSAFSTestRunner"
          -->
          <instrumentation android:name="org.safs.android.engine.DSAFSTestRunner"
                           android:targetPackage="com.android.example.spinner"
                           android:label="General-Purpose SAFS Test Runner"/>
      </manifest>
      

    The same Test APK can be used to test any android:targetPackage.  Simply update the Test APK AndroidManifest XML to identify the desired android:targetPackage and make sure both the Test APK and the target application APK are signed with the same debug or developer certificates.

    Upon a successful build of the Test APK it should be installed to replace any previous version of installed on the Android device or Emulator.

    For the Robotium Test Runner:

      ant debug
      adb install -r bin/RobotiumTestRunner-debug.apk

    For the SAFS Test Runner:

      ant debug
      adb install -r bin/SAFSTestRunner-debug.apk

  4. Once all 3 pieces of SAFS TCP Messenger, the Test Runner, and the target AUT APK are installed on the Android device or Emulator, launching the Test Runner automatically launches the SAFS TCP Messenger.  This is done via adb like below:

    For Robotium:

      adb shell am instrument -w com.jayway.android.robotium.remotecontrol.client/com.jayway.android.robotium.remotecontrol.client.RobotiumTestRunner

    For SAFS:

      adb shell am instrument -w org.safs.android.engine/org.safs.android.engine.DSAFSTestRunner

    The Test Runner and SAFS TCP Messenger are then waiting for a TCP connection and Remote Control from ANY remote client using the Robotium Remote Control API from Development Project 1.  There is a crude simple RemoteControlUI example provided in the org.safs.android source provided by SAFS.

    The developer should monitor "adb logcat" to see any debug information sent out by the SAFS TCP Messenger and the Test Runner.


Copyright SAS Institute, Inc., http://www.sas.com
General Public License (GPL) http://www.opensource.org/licenses/gpl-license.php