MrChaz
MrChaz

Reputation: 1085

uiAutomator failing on 4.1.2 device

When playing with the Android uiAutomator I've run into an issue when trying to run the tests on a 4.1.2 device. When using the code from the enter link description here an exception is thrown when attempting to scroll the apps tray.

I originally thought it was caused by compiling against api 17 rather than 16 but that doesn't seem to be true. Anyone else encountered this?

Exception raised:

[exec] java.lang.reflect.InvocationTargetException [exec] at java.lang.reflect.Method.invokeNative(Native Method) [exec] at java.lang.reflect.Method.invoke(Method.java:511) [exec] at com.example.runTests(Runner.java:124) [exec] at com.example.testExecutor(Runner.java:60) [exec] at java.lang.reflect.Method.invokeNative(Native Method) [exec] at java.lang.reflect.Method.invoke(Method.java:511) [exec] at junit.framework.TestCase.runTest(TestCase.java:168) [exec] at junit.framework.TestCase.runBare(TestCase.java:134) [exec] at junit.framework.TestResult$1.protect(TestResult.java:115) [exec] at junit.framework.TestResult.runProtected(TestResult.java:133) [exec] at junit.framework.TestResult.run(TestResult.java:118) [exec] at junit.framework.TestCase.run(TestCase.java:124) [exec] at com.android.uiautomator.testrunner.UiAutomatorTestRunner.start(UiAutomatorTestRunner.java:124) [exec] at com.android.uiautomator.testrunner.UiAutomatorTestRunner.run(UiAutomatorTestRunner.java:85) [exec] at com.android.commands.uiautomator.RunTestCommand.run(RunTestCommand.java:76) [exec] at com.android.commands.uiautomator.Launcher.main(Launcher.java:83) [exec] at com.android.internal.os.RuntimeInit.nativeFinishInit(Native Method) [exec] at com.android.internal.os.RuntimeInit.main(RuntimeInit.java:235) [exec] at dalvik.system.NativeStart.main(Native Method) [exec] Caused by: java.lang.NoSuchMethodError: com.android.uiautomator.core.UiScrollable.setAsHorizontalList [exec] at com.example.Runner.launchAppFromHomeScreen(Test.java:45) [exec] ... 19 more

Upvotes: 4

Views: 4665

Answers (3)

Quick learner
Quick learner

Reputation: 709

Hello even i faced the same issue then first i deleted the build.xml which i had and created the new build.xml file then ant build then run. it works for me try the same..

Upvotes: 0

Aria4Larry
Aria4Larry

Reputation: 116

UIAutomator's codes has changes:

4.1.1 method : public void setAsHorizontalList ()
4.2 method : public UIScrollable setAsHorizontalList ()

It's maybe you are using API-17's UIAutomator to build the tests but running on a API-16 device. Try using the corresponding UIAutomator.jar

Upvotes: 7

JulianHarty
JulianHarty

Reputation: 3286

From my experiments this week with UI Automator it's still seems immature, with the best support available with android-17 as your target and with a device running 4.2.1. I tried using my Galaxy S device which has 4.1.2 installed and had similar errors to those you report.

FYI: I think there's a bug in Android 4.2.2 that stops scrollIntoView(...) calls from swiping more than once. I've reported the problem to Google https://groups.google.com/forum/?fromgroups=#!topic/adt-dev/TjeewtpNWf8

I found the demo app http://developer.android.com/tools/testing/testing_ui.html worked on my device with Android 4.2.1 You might need to tweak the code slightly, however the method calls do work.

Upvotes: 1

Related Questions