My favorites | Sign in
Project Home Downloads Wiki Issues Source
Search
for
AndroidMakeAnAppTestable  
How to configure your build and AndroidManifest.xml file to enable testing your app with Android NativeDriver
Featured
Updated Jul 17, 2011 by d...@google.com

Making an Android App Testable with NativeDriver

The Android NativeDriver (AND) works as instrumentation in your app. It starts a Jetty server on the device which listens for WebDriver JSON protocol requests. In order to make an application run this instrumentation, and respond to these WebDriver requests:

  1. Link server-standalone.jar to your application (if you already have an eclipse Android project for your test target, right click the project, Build Path -> Configure Build Path... -> Libraries -> Add JARs or Add External JARs). If you have not built the server-standalone.jar file yet, follow the steps under Build the NativeDriver libraries in the Getting Started documentation.
  2. In the app's AndroidManifest.xml file, add the following elements in the <manifest> element:

      <instrumentation android:targetPackage="{app_package_name}"
       android:name="com.google.android.testing.nativedriver.server.ServerInstrumentation" />
      <uses-permission android:name="android.permission.INTERNET" />
      <uses-permission android:name="android.permission.WAKE_LOCK" />
      <uses-permission android:name="android.permission.DISABLE_KEYGUARD" />

    The first element enables the instrumentation against your application. {app_package_name} is the name of the package as specified by the manifest element's package attribute. The other lines are permissions to enable testing by AND:

    • INTERNET - allows the Jetty server to start and listen for web requests. If this is missing, the ServerInstrumentation cannot start all.
    • WAKE_LOCK - allows AND to hold a wake lock, which prevents the screen from sleeping and locking as a result of inactivity. This is optional.
    • DISABLE_KEYGUARD - allows AND to disable the screen lock when the ServerInstrumentation starts. This is optional.
    If the optional permissions are omitted, you may have to interact with the device manually to by-pass the key guard or wake up the device.
  3. Build the application apk and install it to the device.
  4. Start the instrumentation by running this at the command line:

    adb shell am instrument {app_package_name}/com.google.android.testing.nativedriver.server.ServerInstrumentation

  5. Enable port forwarding with this command:

    adb forward tcp:54129 tcp:54129

  6. You can confirm that the instrumentation is started by running adb logcat and looking for a line like this:

    I/com.google.android.testing.nativedriver.server.ServerInstrumentation(  273): Jetty started on port 54129

After following these steps you can run a NativeDriver test on the emulator host machine, or the machine connected to the device. For a sample test, see one of the JUnit sample tests. The test code must be linked to client-standalone.jar.

Comment by chenfei1...@gmail.com, Jul 12, 2011

I have “server-standalone.jar”,but How to Link server-standalone.jar to my application. could you take example?thanks

Comment by niloy....@gmail.com, Jul 15, 2011

the things what is described in above is not so clear to me. is there any simplified and step by step process for this ??

Comment by project member d...@google.com, Jul 17, 2011

> How to Link server-standalone.jar to my application. could you take example? If you already have an eclipse Android project (of your test target), right click the project, Build Path -> Configure Build Path... -> Libraries -> Add JARs or Add External JARs.

Comment by project member d...@google.com, Jul 17, 2011

>the things what is described in above is not so clear to me. is there any simplified and step by step process for this ?? <p>This is a step by step process. Would you please tell us which step you feel unclear? Thank you.

Comment by ant...@gmail.com, Jul 18, 2011

How to write cross-app test? Test base on instrumentation will lose control when the application invokes system service like phone call or SMS. And are there any mechanism to test app that I don't have project source?

Comment by pudur.ra...@gmail.com, Jul 25, 2011

when i run the command for instrumenting the server i get the following exception. what step or configuration i'm missing.? Pleasse i have "linked" server-standalone.jar to the simplelayouts porject.. W/dalvikvm( 223): Exception Ljava/util/MissingResourceException?; thrown during Ljavax/servlet/GenericServlet?;.<clinit>

W/dalvikvm( 223): threadid=15: thread exiting with uncaught exception (group=0x4000fe68)

E/AndroidRuntime?( 223): Uncaught handler: thread Instr: com.google.android.testing.nativedriver.server.ServerInstrumentation? exiting due to uncaught exception

E/AndroidRuntime?( 223): java.lang.ExceptionInInitializerError?

E/AndroidRuntime?( 223): at com.google.android.testing.nativedriver.server.ServerInstrumentation?.createHandler(Unknown Source)

E/AndroidRuntime?( 223): at com.google.android.testing.nativedriver.server.ServerInstrumentation?.startJetty(Unknown Source)

E/AndroidRuntime?( 223): at com.google.android.testing.nativedriver.server.ServerInstrumentation?.onStart(Unknown Source)

E/AndroidRuntime?( 223): at android.app.Instrumentation$InstrumentationThread?.run(Instrumentation.java:1507)

E/AndroidRuntime?( 223): Caused by: java.util.MissingResourceException?

E/AndroidRuntime?( 223): at java.util.ResourceBundle?.getBundleImpl(ResourceBundle?.java:172)

E/AndroidRuntime?( 223): at java.util.ResourceBundle?.getBundle(ResourceBundle?.java:90)

E/AndroidRuntime?( 223): at javax.servlet.GenericServlet?.<clinit>(GenericServlet?.java:64)

E/AndroidRuntime?( 223): ... 4 more

I/Process ( 46): Sending signal. PID: 223 SIG: 3

W/ActivityManager?( 46): Error in app com.google.android.testing.nativedriver.simplelayouts running instrumentation ComponentInfo?{com.google.android.testing.nativedriver.simplelayouts/com.google.android.testing.nativedriver.server.ServerInstrumentation?}:

W/ActivityManager?( 46): java.lang.ExceptionInInitializerError?

W/ActivityManager?( 46): java.lang.ExceptionInInitializerError?

D/ActivityManager?( 46): Uninstalling process com.google.android.testing.nativedriver.simplelayouts

D/ActivityManager?( 46): Force removing process ProcessRecord?{43494b60 223:com.google.android.testing.nativedriver.simplelayouts/10018} (com.google.android.testing.nativedriver.simplelayouts/10018)

Comment by hy...@163.com, Aug 1, 2011

can I get Toast in a app?

Comment by qingjie...@gmail.com, Aug 10, 2011

I've added the client-standalone.jar and server-standalone by Build Path -> Configure Build Path... -> Libraries -> Add External JARs,but then there disappeared a problem ,which said"Conversion to Dalvik format failed with error 1",do you know where is the problem ?

Comment by apack1...@gmail.com, Aug 21, 2011

can i get toast in a app?

Comment by alcantar...@gmail.com, Sep 4, 2011

qingjie: Usually that is fixed by a Project -> Clean and then -> Build. But what you probably did was to put both the application files and the test files in a single project. So you have both the server-standalone.jar and client-standalone.jar in the same project.

Delete the test files and the client-standalone.jar from the "simplelayouts" project and re-import the files for the "android-test" project.

Maybe step 6 should be split and a 7th added: "Repeat the import process for the nativedriver/android/test directory."

Comment by iulia....@threepillarglobal.com, Oct 11, 2011

Hello I cannot run my test application. I run the command: adb forward tcp:54129 tcp:54129 and looking into logcat i found the folowing line: I/com.google.android.testing.nativedriver.server.ServerInstrumentation?( 293): Jetty started on port 54129 It seams that the number is 293 instead of 273. do you think that this could influence my tests?

I got the following error:

org.openqa.selenium.WebDriverException?: org.apache.http.conn.HttpHostConnectException?: Connection to http://localhost:54129 refused I/TestRunner?( 351): System info: os.name: 'Linux', os.arch: 'armv5tejl', os.version: '2.6.29-00261-g0097074-dirty', java.version: '0'

do you have a solution for this? Thank you very much!!1

Comment by andreas_...@hotmail.com, Oct 18, 2011

Hey, trying to include it to rhodes, but I get following error from adb logcat: I/ActivityManager?( 59): Start proc com.rhomobile.rhodesapplication1 for added application com.rhomobile.rhodesapplication1: pid=389 uid=10033 gids={3003} D/AndroidRuntime?( 383): Shutting down VM D/dalvikvm( 383): Debugger has detached; object registry had 1 entries I/dalvikvm( 383): JNI: AttachCurrentThread? (from ???.???) I/AndroidRuntime?( 383): NOTE: attach of thread 'Binder Thread #3' failed D/dalvikvm( 389): Trying to load lib /data/data/com.rhomobile.rhodesapplication 1/lib/librhodes.so 0x4817bcb0 W/System.err( 389): 2011-10-18 08:44:10.637:INFO::Logging to STDERR via org.mor tbay.log.StdErrLog? D/dalvikvm( 389): Added shared lib /data/data/com.rhomobile.rhodesapplication1/ lib/librhodes.so 0x4817bcb0 I/ActivityThread?( 389): Publishing provider com.rhomobile.rhodesapplication1: c om.rhomobile.rhodes.LocalFileProvider? W/dalvikvm( 389): Exception Ljava/util/MissingResourceException?; thrown during Ljavax/servlet/GenericServlet?;.<clinit> W/dalvikvm( 389): threadid=7: thread exiting with uncaught exception (group=0x4 001d800) E/AndroidRuntime?( 389): FATAL EXCEPTION: Instr: com.google.android.testing.nati vedriver.server.ServerInstrumentation? E/AndroidRuntime?( 389): java.lang.ExceptionInInitializerError? E/AndroidRuntime?( 389): at com.google.android.testing.nativedriver.serve r.ServerInstrumentation?.createHandler(Unknown Source) E/AndroidRuntime?( 389): at com.google.android.testing.nativedriver.serve r.ServerInstrumentation?.startJetty(Unknown Source) E/AndroidRuntime?( 389): at com.google.android.testing.nativedriver.serve r.ServerInstrumentation?.onStart(Unknown Source) E/AndroidRuntime?( 389): at android.app.Instrumentation$InstrumentationTh? read.run(Instrumentation.java:1447) E/AndroidRuntime?( 389): Caused by: java.util.MissingResourceException?: Can't fi nd resource for bundle javax.servlet.LocalStrings?, key en_US E/AndroidRuntime?( 389): at java.util.ResourceBundle?.getBundleImpl(Resour ceBundle.java:244) E/AndroidRuntime?( 389): at java.util.ResourceBundle?.getBundle(ResourceBu? ndle.java:133) E/AndroidRuntime?( 389): at javax.servlet.GenericServlet?.<clinit>(Generic Servlet.java:64) E/AndroidRuntime?( 389): ... 4 more W/ActivityManager?( 59): Error in app com.rhomobile.rhodesapplication1 running instrumentation ComponentInfo?{com.rhomobile.rhodesapplication1/com.google.androi d.testing.nativedriver.server.ServerInstrumentation?}: W/ActivityManager?( 59): java.util.MissingResourceException? W/ActivityManager?( 59): java.util.MissingResourceException?: Can't find resou rce for bundle javax.servlet.LocalStrings?, key en_US I/ActivityManager?( 59): Force stopping package com.rhomobile.rhodesapplication 1 uid=10033 I/Process ( 59): Sending signal. PID: 389 SIG: 9 D/SntpClient?( 59): request time failed: java.net.SocketException?: Address fami ly not supported by protocol

Maybe someone can help me. Thanks

Comment by mouras...@gmail.com, Oct 31, 2011

I'm having a ClassNotFoundException? (com.google.android.testing.nativedriver.server.ServerInstrumentation?) when starting the Instrumentation. I've already added the server-standalone.jar to the "libs" folder, build path, etc... and still no good. Did anyone have this problem and knows how to solve it?

Much appreciated! Mourasman

Comment by surya.ma...@gmail.com, Apr 1, 2012

I'm facing "ClassNotFoundException?: com.google.android.testing.nativedriver.server.ServerIns? trumentation" while starting instrumentation - adb shell am instrument {app_package_name}/com.google.android.testing.nativedriver.server.ServerInstrumentation?.

Please post if anyone fixed the issue.

Thanks.

Comment by Yhh.ru...@gmail.com, May 16, 2012

can i get the toast in the test project?

Comment by Yhh.ru...@gmail.com, May 16, 2012

when i click a button with nativeDriver in windows,it doesn't work? why?


Sign in to add a comment
Powered by Google Project Hosting