5

recent i tryied getting started with android uiautomation testing.

The tutorial from the developer site I've worked through a few times and after having some problems and solving them now I have got a bigger issue.

I created a project, imported the two jar files and builded a java testcase scenario (the one from the tutorial.) after that I created an uitest projekt with shell command line. updated the build.xml created a jar file and pushed it onto my device.

As far as good everything worked nicely upon this point.

But tryin to run my tests with the command line:

adb -s <ANDROID_SERIAL> shell uiautomator runtest DeviceUnlocker.jar -c c.d.d.DeviceUnlocker

I only get the error:

INSTRUMENTATION_RESULT: shortMsg = java.lang.RuntimeException
INSTRUMENTATION_RESULT: longMsg=Didn't find class "c.d.d.DeviceUnlockingPseudoCodeTest on Path: /system/framework/android.test.runner.jar: /system/framework/uiautomator.jar:: /data/local/tmp/DeviceUnlocker.jar

INSTRUMENTATION_CODE: 0

Community
  • 1
  • 1
Erik Mueller
  • 330
  • 4
  • 10
  • can you please post part of your code ? – Rilwan Oct 15 '13 at 10:00
  • the parts of my code were espacially the one from the developer site [Android Developer](http://developer.android.com/tools/testing/testing_ui.html)and form this site: [EveryOneTests](http://everybodytests.blogspot.de/2013/01/unlocking-your-android-test-devices.html) The only other code parts from myself were adding the build.xml file with the code from my answer – Erik Mueller Oct 15 '13 at 11:50
  • please post logcat dump also so we can check where is RuntimeException coming. – neeraj t Dec 10 '13 at 13:11
  • @ErikMueller Did you manage to get a valid answer? I see a lot of answers but none accepted. I have a similar problem but none of these worked, so I left a question here http://stackoverflow.com/q/32200292/347119. Thanks if you can help me somehow. – Edison Spencer Aug 25 '15 at 13:24
  • @EdisonSpencer none of the posted worked for me. But I had to say, that I havent tried in recent times. It may be that some errors have been resolved in recent updates from android sdk. are you running the tests inside eclipse or android studio? A college of me did got the tests to work by writing some bash scripts. – Erik Mueller Aug 31 '15 at 07:47
  • Hi @ErikMueller, I was following the steps shown here (https://goo.gl/LxaJWN), so what I did was create an Eclipse Project and add the relevant dependencies. But now the application project have been exported to Android Studio, maybe I should try using the "test" package created by Android Studio? Can your colleague say something on my post? Thanks – Edison Spencer Aug 31 '15 at 08:10
  • Finally UI Automation has been ported to Android Studio, so try to run your tests under Android Studio, it's a lot less complicated! – Erik Mueller Nov 23 '15 at 14:20

6 Answers6

1

okay the easiest way is to only create inside eclipse a new android junit projekt.

i think this is more or less equal to uiautomator. and i think you might have the same oportunities ... correct me if i'm wrong...

uiautomator is still not running... and i also found some bugs in the uibuild.xml from android itself

<target name="test" description="Runs tests"> <!-- todo: fix this --> <fail message="Launching tests from Ant not supported yet" />

     <exec executable="${adb}" failonerror="true">
        <arg line="${adb.device.arg}" />
        <arg value="shell" />
        <arg value="uiautomator" />
        <arg value="runtest" />
        <arg value="${out.filename}" />
        <arg value="-e" />
        <arg value="class" />
        <arg value="com.android.uiautomator.samples.skeleton.DemoTestCase" />
    </exec>
</target>`

thanks for your help. for me uiautomator is no option anymore. regards

Erik Mueller
  • 330
  • 4
  • 10
0
  1. new JavaProjekt (import JUnit android.jar uiautomator.jar
  2. create packages c.d.d
  3. Copy TestCase Device Unlocking pseudoTestCase into Projekt
  4. run cmd 4.1. "set ANDROID_HOME=" to sdk location 4.2. \tools\ android create uitestprojekt -n name -t "android-16" -p projPath
  5. edit build.xml that was created from create command: added code:

<delete dir="jar"/>

<mkdir dir="jar" />

<javac destdir="bin" encoding="UTF-8" debug="on" target="1.6" includeantruntime="false"> 
    <src path="src" /> 
</javac> 
<jar destfile="jar/uiautomator.jar"> 
     <fileset dir="bin" /> 
</jar>
  1. run as antbuild
  2. cmd -> cd ANDROID_HOME-> cd platform-tools
  3. adb push /jar/uiautomator.jar data/local/tmp
  4. adb -s shell uiautomator runtest DeviceUnlocker.jar -c c.d.d.DeviceUnlocker

that were all steps i've done

thanks

Erik Mueller
  • 330
  • 4
  • 10
  • did it compile properly ? was it showing any line with `[javac]` ? your project path mentioned in the `create` command is correct ? try `ant clean build` ? Still fails--> then could you just try some basic code(say just wake up device) alone in your class and run..Because i had the similar issue, then i had to clear all the above `?` one by one. and it works for me. – Rilwan Oct 16 '13 at 16:31
  • well after running this line in shell about a houndret times i think i got my link right also copy pasting the link brought no efford. well i run the ant build in eclipse ide because my system environment variable was not set for ant and i had no idea where to find it inside eclipse. what were you cleaning above? i can only see a questionmark :-) – Erik Mueller Oct 17 '13 at 05:15
  • and yes in eclipse it shows the lines javac and building jarfile – Erik Mueller Oct 17 '13 at 05:17
  • did you try it from `shell` or `cmd`, outside eclipse. ? – Rilwan Oct 20 '13 at 07:45
  • cmd y is there any difference? by mentioning this question i've seen by now that there is besides the cmd also a shell.. waow wtf i've never seen that before – Erik Mueller Oct 22 '13 at 08:37
0

Make sure you've compiled the java classes into android dex!

I've met the same issue when put a pure java "jar" package to /data/tmp/.

Assume your project is device-unlock:

cd device-unlock
android create uitest-project -n device-unlock -t 1 -p .
and build

Now you'll find the dexed jar package in bin/device-unlock.jar, open it with zip you'll see a classes.dex.

With this jar, it should be ok to continue your test.

Evans Y.
  • 4,209
  • 6
  • 35
  • 43
0

I had the exact same problem and made a quick haxx to fix it:

Solve it by:

  1. go to you UiautomationTest project and from the bin/ folder copy the classfile(s). In my case I copied the whole folderstructure com/poc/MyTest.class
  2. go to the App-Under-Test project and in the bin/ folder past the class data. In my case the com/poc/MyTest.class is merged with the existing classes under com/
  3. Re-build the UiAutomation project with "ant build"
  4. re-deploy and now you can run it!

This is just a workaround but it identified the root case - that the testcase class is excluded from the UiAutomator buildstep

gemigis
  • 186
  • 4
0

While running the uiautomator Tests command run it in the below way

Example:

adb shell uiautomator runtest LaunchSettings.jar -c com.uia.example.my.LaunchSettings
adb shell uiautomator runtest "jar name" -c "packagename"."Classname"

This should work.

Carlo Cannas
  • 3,206
  • 19
  • 22
0

Best way to check this problem is to run this command without using -c <classpath>#<testMethod> and check if it works. If it works check for the class name that it prints in the terminal is the one that's used with -c

adb -s shell uiautomator runtest DeviceUnlocker.jar
Qiu
  • 5,651
  • 10
  • 49
  • 56
arunkumarreddy
  • 159
  • 1
  • 7