Re: Is uiautomator supported on the emulator?

3,776 views
Skip to first unread message

Guang Zhu

unread,
Nov 20, 2012, 5:07:18 PM11/20/12
to adt...@googlegroups.com
Hi Walter,

Thanks for trying this!

UI Automator has been verified and tested mostly on physical devices. I'll take a look at the issues on emulators.

The problem with x86 image seems to be that the image is still using an older version of shell. The second problem with NoSuchMethodError will need a closer look to determine the root cause.


On Fri, Nov 16, 2012 at 3:42 PM, Walter Lowe <jeb...@gmail.com> wrote:
Hi,

I've been playing around with uiautomator for the past few days and it seems like it will be very useful.  Going forward, I'd like to run my tests on the emulator instead of real devices.  However I haven't been able to get this working yet.

My first attempt was on an x86 image of Android 4.1.2 and it yields the following result:

$ adb shell uiautomator runtest LearnUITesting.jar -c SchoolListSearchTest
[: not found
[: not found
[: not found
uiautomator: 70: Syntax error: Bad substitution

I couldn't figure out what's triggering this error.  I'm pretty sure my test setup is fine because uiautomator runs flawlessly on my Galaxy Nexus.

Next I attempted to test using the Google APIs ARM image for 4.2.  This time the test starts but then I get an immediate Exception when setting up my UiScrollable:
$ adb shell uiautomator runtest LearnUITesting.jar -c SchoolListSearchTest
INSTRUMENTATION_STATUS: current=1
INSTRUMENTATION_STATUS: id=UiAutomatorTestRunner
INSTRUMENTATION_STATUS: class=SchoolListSearchTest
INSTRUMENTATION_STATUS: stream=
SchoolListSearchTest:
INSTRUMENTATION_STATUS: numtests=1
INSTRUMENTATION_STATUS: test=testSearch
INSTRUMENTATION_STATUS_CODE: 1
INSTRUMENTATION_STATUS: current=1
INSTRUMENTATION_STATUS: id=UiAutomatorTestRunner
INSTRUMENTATION_STATUS: class=SchoolListSearchTest
INSTRUMENTATION_STATUS: stream=
Error in testSearch:
java.lang.NoSuchMethodError: com.android.uiautomator.core.UiScrollable.setAsHorizontalList
    at SchoolListSearchTest.testSearch(SchoolListSearchTest.java:21)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at com.android.uiautomator.testrunner.UiAutomatorTestRunner.start(UiAutomatorTestRunner.java:124)
    at com.android.uiautomator.testrunner.UiAutomatorTestRunner.run(UiAutomatorTestRunner.java:85)
    at com.android.commands.uiautomator.RunTestCommand.run(RunTestCommand.java:76)
    at com.android.commands.uiautomator.Launcher.main(Launcher.java:83)
    at com.android.internal.os.RuntimeInit.nativeFinishInit(Native Method)
    at com.android.internal.os.RuntimeInit.main(RuntimeInit.java:235)
    at dalvik.system.NativeStart.main(Native Method)

INSTRUMENTATION_STATUS: numtests=1
INSTRUMENTATION_STATUS: stack=java.lang.NoSuchMethodError: com.android.uiautomator.core.UiScrollable.setAsHorizontalList
    at SchoolListSearchTest.testSearch(SchoolListSearchTest.java:21)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at com.android.uiautomator.testrunner.UiAutomatorTestRunner.start(UiAutomatorTestRunner.java:124)
    at com.android.uiautomator.testrunner.UiAutomatorTestRunner.run(UiAutomatorTestRunner.java:85)
    at com.android.commands.uiautomator.RunTestCommand.run(RunTestCommand.java:76)
    at com.android.commands.uiautomator.Launcher.main(Launcher.java:83)
    at com.android.internal.os.RuntimeInit.nativeFinishInit(Native Method)
    at com.android.internal.os.RuntimeInit.main(RuntimeInit.java:235)
    at dalvik.system.NativeStart.main(Native Method)

INSTRUMENTATION_STATUS: test=testSearch
INSTRUMENTATION_STATUS_CODE: -1
INSTRUMENTATION_STATUS: stream=
Test results for UiAutomatorTestRunner=.E
Time: 4.95

FAILURES!!!
Tests run: 1,  Failures: 0,  Errors: 1


INSTRUMENTATION_STATUS_CODE: -1


Any ideas about what could be going on here?

Walter



--
Guang Zhu
Android Test Engineering
Google Inc.

Please keep all discussions on related Google Groups, no direct emails. Thanks!

Tester T

unread,
Nov 20, 2012, 5:30:11 PM11/20/12
to adt...@googlegroups.com
Cannot take the Screenshot with uiautomatorviewer.

I have followed the below method: 
  • Connect your Android device to your development machine
  • Open a terminal window and navigate to <android-sdk>/tools/
  • Run the tool with this command:
    $ uiautomatorviewer
Please find the attachment too.

I get the shown cmd window when i open the uiautomationviewer & the error popup when i click screenshot.
I wanted to add a note.. The message in cmd says,
"The System cannot find the path"..

I am using Windows 7 and the device is Samsung Galaxy Nexus (Android version 4.1.2). I have not installed my app yet. 
My "Developer Options" is set to ON. My "USB Debugging" and "Protect USB Storage" is also selected.
Even my colleagues have the same issue.

Thanks in advance,
Jazz
ss.png

Walter Lowe

unread,
Nov 26, 2012, 2:37:37 PM11/26/12
to adt...@googlegroups.com
HI Guang,

Thanks for your reply.  Unfortunately, I don't have too much time to look into this directly at the moment but I'd like to revisit this in the future.  I'll report back to you if I'm able to figure anything out.

Thanks,
Walter

Christopher Orr

unread,
Nov 28, 2012, 7:12:29 AM11/28/12
to adt...@googlegroups.com
Have you tried it on a non-x86 emulator (I haven't so far)?

Russell Collins has a post here where he has it working on an emulator:
http://everybodytests.blogspot.de/2012/11/uiautomator-and-watchers-adding-async.html

Regards,
Chris

Kshitij Aggarwal

unread,
Jan 11, 2013, 12:04:10 AM1/11/13
to adt...@googlegroups.com
Chen,

I just moved on to Robotium framework for now. I was doing a feasibility test between uiautomator and robotium, and robotium fits my need better as it integrates with the existing jUnit.

-Kshitij

On Friday, January 11, 2013 7:58:26 AM UTC+5:30, Chen Yingliu wrote:
I am facing exactly the same problem as you. Didn't you figure out any solution yet? I am using Galaxy S III upgraded to Jelly Bean and emualtor, and AndroVM, all have the same problem.

On Tuesday, January 8, 2013 2:39:05 AM UTC-8, Kshitij Aggarwal wrote:
Actually im facing this problem on both device and emulator. I was able to run it on emulator initially. But when I installed some apps to make the app list span more then one page, it started giving me the error.

Guang Zhu

unread,
Mar 25, 2013, 8:52:06 PM3/25/13
to adt...@googlegroups.com
Hi all,

Apologies for the late reply! Two issues have been brought up in this thread:

1. Can't run uiautomator in x86 emulator:
This is because x86 emulator is still using an older variant of shell ('ash' vs a more recent bash-like variant 'mksh'). We are working with Intel to address this issue, and for now, the best workaround is to use ARM emulator

2. NoSuchMethodError from com.android.uiautomator.core.UiScrollable.setAsHorizontalList:
This is caused by an API backwards compatibility issue: the method signature (return type) changed from API Leve 16 to 17. This happened due to an oversight. You'll see this if you use any of the following methods:
     UiScrollable.setSwipeDeadZonePercentage
     UiScrollable.setMaxSearchSwipes
     UiScrollable.setAsVerticalList
     UiScrollable.setAsHorizontalList
The workaround: if you intend to test against API Level 16 with the functions above, the test jar needs to be compiled with API Level 16 SDK, and it won't run on API Level 17 devices; from API Level 17 and later, test jars compiled out of an older platform should always work on a later platform.

Thanks,
Guang Zhu

On Mon, Mar 25, 2013 at 10:15 AM, kinjal patel <kinjal...@gmail.com> wrote:
I have faced this issue when I was working with Uiautomator. I found that if you are working with API 16 device add the jar from "\android-sdk\platforms\android-16" and Build with the target 8.
It will work for me.

Thanks,
Kinjal Patel
You received this message because you are subscribed to the Google Groups "adt-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to adt-dev+u...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Harish [India]

unread,
Dec 4, 2013, 11:52:48 PM12/4/13
to adt...@googlegroups.com
Hi jazz,
 
 
I had faced same problems, i overcome with the below change.
Pelase try this,
 
Tools.jar file might be missing in your JDK.
copy 'tools.jar' to jdk/lib folder
 
Thanks
Reply all
Reply to author
Forward
0 new messages