Question #169859 on Sikuli changed:
https://answers.launchpad.net/sikuli/+question/169859

    Status: Answered => Open

Raymond Gonzales is still having a problem:
You have been a major help.

Is there anyway to adapt your example so that I can run it in a Java
project?  I have tried and am stuck with instantiating an AndroidScreen
object. I will walk you through what i have done

I am on a Mac running Snow Leopard....

Firstly I created a project in eclipse and added the following jars to my 
project build path from the projects lib folder:
junit-4.8.2.jar
sikuli-script.jar (RC 3)
android-robot-0.1.jar
monkeyrunner.jar
android.jar
guava-r09.jar
sdklib.jar
ddmlib.jar

Then I created a source folder called:
test

I then created a package called:
com.company.androidautomation.tests

I added one Java file to the package called:
TestAndroid

Here is the code I added to the TestAndroid java class:

CONTENTS OF TestAndroid CLASS:
------------------------------------------------------------------

package com.company.androidautomation.tests;

import org.junit.Test;
import com.android.monkeyrunner.MonkeyDevice;
import com.android.monkeyrunner.adb.AdbBackend;
import com.android.monkeyrunner.core.IMonkeyDevice;
import org.sikuli.script.android.AndroidRobot;
import org.sikuli.script.android.AndroidScreen;
import org.sikuli.script.android.MonkeyPlugin;

public class TestAndroid{


        @Test
        public void test() throws Exception {

                AdbBackend adb = new AdbBackend();
                MonkeyDevice monkeyDevice;
                IMonkeyDevice iMonkeyDevice = adb.waitForConnection();
                monkeyDevice = new MonkeyDevice(iMonkeyDevice);
                AndroidRobot robot = new AndroidRobot(monkeyDevice);
                MonkeyPlugin monkey = new MonkeyPlugin();
                
                iMonkeyDevice.type("go");
              
                iMonkeyDevice.type("\n");
              
                AndroidScreen scr = new AndroidScreen();

        }

}

------------------------------------------------------------------
I have to go into the Run Configurations for my class (right click on the class 
go to Run As > Run Configurations), select the Arguments tab and then in VM 
arguments text box, I paste the following so that my project knows about my 
android sdk location:

-cp /Users/[HOME DIRECTORY 
NAME]/workspace/AndroidTest/lib/sikuli-script.jar:/Users/[HOME DIRECTORY 
NAME]/workspace/AndroidTest/lib/android-robot-0.1.jar:/Users/[HOME DIRECTORY 
NAME]/android-sdk-mac_x86/tools/lib/monkeyrunner.jar
-Djava.ext.dirs=/Users/[HOME DIRECTORY NAME]/android-sdk-mac_x86/tools/lib 
-Djava.library.path=/Users/[HOME DIRECTORY NAME]/android-sdk-mac_x86/tools/lib 
-Dcom.android.monkeyrunner.bindir=/Users/[HOME DIRECTORY 
NAME]/android-sdk-mac_x86/tools


------------------------------------------------------------------

I then start the emulator myself and go to google.com and select a text
box manually to prep for my test

------------------------------------------------------------------

The problem occurs when the Andoird scr object tries to get
instantiated.  When the AndroidScreen tries to make a connection to the
emulator, the connection will time out and I get the following errors:

Sep 19, 2011 11:05:25 AM com.android.monkeyrunner.MonkeyManager 
sendMonkeyEventAndGetResponse
INFO: Monkey Command: wake.
Sep 19, 2011 11:05:25 AM com.android.monkeyrunner.MonkeyManager 
sendMonkeyEventAndGetResponse
INFO: Monkey Command: type go.
Sep 19, 2011 11:05:25 AM com.android.monkeyrunner.MonkeyManager 
sendMonkeyEventAndGetResponse
INFO: Monkey Command: press enter.
java.lang.NullPointerException
        at 
com.android.monkeyrunner.MonkeyRunner.waitForConnection(MonkeyRunner.java:78)
        at 
org.sikuli.script.android.AndroidScreen.initRobots(AndroidScreen.java:30)
        at org.sikuli.script.android.AndroidScreen.<init>(AndroidScreen.java:55)
        at 
com.company.androidautomation.tests.TestAndroid.test(TestAndroid.java:28)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at 
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at 
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at 
org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
        at 
org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
        at 
org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
        at 
org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
        at 
org.junit.runners.BlockJUnit4ClassRunner.runNotIgnored(BlockJUnit4ClassRunner.java:79)
        at 
org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:71)
        at 
org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:49)
        at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
        at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
        at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
        at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
        at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
        at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
        at 
org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:49)
        at 
org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
        at 
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
        at 
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
        at 
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
        at 
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
[error] no connection to android device.

Here is another stack trace that I get from jUnit:

java.lang.NoSuchMethodError: 
com.android.monkeyrunner.MonkeyDevice.getProperty(Ljava/lang/String;)Ljava/lang/String;
        at 
org.sikuli.script.android.AndroidScreen.getBounds(AndroidScreen.java:47)
        at org.sikuli.script.android.AndroidScreen.<init>(AndroidScreen.java:56)
        at 
com.company.androidautomation.tests.TestAndroid.test(TestAndroid.java:28)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at 
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at 
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at 
org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
        at 
org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
        at 
org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
        at 
org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
        at 
org.junit.runners.BlockJUnit4ClassRunner.runNotIgnored(BlockJUnit4ClassRunner.java:79)
        at 
org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:71)
        at 
org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:49)
        at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
        at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
        at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
        at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
        at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
        at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
        at 
org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:49)
        at 
org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
        at 
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
        at 
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
        at 
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
        at 
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)

-- 
You received this question notification because you are a member of
Sikuli Drivers, which is an answer contact for Sikuli.

_______________________________________________
Mailing list: https://launchpad.net/~sikuli-driver
Post to     : [email protected]
Unsubscribe : https://launchpad.net/~sikuli-driver
More help   : https://help.launchpad.net/ListHelp

Reply via email to