Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I can't get the hello world example to work. #37

Open
doubleshow opened this issue Jun 13, 2013 · 3 comments
Open

I can't get the hello world example to work. #37

doubleshow opened this issue Jun 13, 2013 · 3 comments

Comments

@doubleshow
Copy link
Member

Original author: [email protected] (March 23, 2013 06:10:47)

What steps will reproduce the problem?
1.Run the Quick start code
2. Wait for the browser to open webpage
3.Exception in thread "main" org.sikuli.api.SikuliRuntimeException: Image file can not be loaded from http://code.google.com/images/code_logo.gif because Can't get input stream from URL!
at org.sikuli.api.ImageTarget.<init>(ImageTarget.java:46)
at HelloWorldExample.main(HelloWorldExample.java:25)

What is the expected output? What do you see instead?

Displaying "Hello World" next to the target and then clicking on it.

What version of the product are you using? On what operating system?
windows 7 32bit
jdk1.7.0_09
sikuli-api-1.0.2-standalone.jar

Please provide any additional information below.

I am using the following code

--- Code

import java.net.MalformedURLException;
import java.net.URL;
import org.sikuli.api.Target;
import org.sikuli.api.;
import org.sikuli.api.robot.Mouse;
import org.sikuli.api.robot.desktop.DesktopMouse;
import org.sikuli.api.visual.Canvas;
import org.sikuli.api.visual.DesktopCanvas;
import org.sikuli.api.ImageTarget;
import static org.sikuli.api.API.
;

public class HelloWorldExample {

    public static void main(String[] args) throws MalformedURLException {

            // Open the main page of Google Code in the default web browser
           API.browse(new URL(&quot;http://code.google.com&quot;));

            // Create a screen region object that corresponds to the default monitor in full screen 
            ScreenRegion s = new DesktopScreenRegion();

            // Specify an image as the target to find on the screen
            URL imageURL = new URL(&quot;http://code.google.com/images/code_logo.gif&quot;);                
            Target imageTarget = new ImageTarget(imageURL);

            // Wait for the target to become visible on the screen for at most 5 seconds
            // Once the target is visible, it returns a screen region object corresponding
            // to the region occupied by this target
            ScreenRegion r = s.wait(imageTarget,5000);

            // Display &quot;Hello World&quot; next to the found target for 3 seconds
            Canvas canvas = new DesktopCanvas();
            System.out.println(&quot;r: &quot; + r); 
            canvas.addLabel(r, &quot;Hello World&quot;).display(5);

            // Click the center of the found target
            Mouse mouse = new DesktopMouse();
            mouse.click(r.getCenter());
    }

}

Original issue: http://code.google.com/p/sikuli-api/issues/detail?id=37

@doubleshow
Copy link
Member Author

From [email protected] on June 04, 2013 22:05:34
Might be because of image resolution difference between how the image actually looks and how the image is getting rendered on the browser. Have you tried with a different set of website and image? Or instead of the URL, you can try saving it in the project workspace and calling the constructor of ImageTarget with a new File object like:

Target imageTarget = new ImageTarget(new File("img/code_logo.gif"));

@ExMateria
Copy link

I am having, seemingly, the same issue as roopapat. From the old google ticket I have asked about Proxy and the preliminary reply is that we don't have a proxy and when I try sites like whatsmyproxy I don't get anything back.

I also did attempt both of your suggestions of altering the set of website and image as well as saving the image to the project workspace and I keep getting the java.lang.NoClassDefFoundError

I'm trying to do this in Scala, so I'll place my code here in case I've botched something in my translation of the hello world example --

`import java.net.{MalformedURLException, URL}

import org.sikuli.api.API._
import org.sikuli.api.robot.Mouse
import org.sikuli.api.robot.desktop.DesktopMouse
import org.sikuli.api.visual.{DesktopCanvas, Canvas}
import org.sikuli.api.{ImageTarget, Target, DesktopScreenRegion, ScreenRegion}

/**

  • Created by epearson on 3/11/2016.
    */
    object awin {

    @throws(classOf[MalformedURLException])
    def main(args: Array[String]): Unit = {
    browse(new URL("https://developers.google.com/"))
    var s: ScreenRegion = new DesktopScreenRegion()
    var imageURL: URL = new URL("https://developers.google.com/ef4324f0ea/_static/ef4324f0ea/images/redesign-14/logo_lockup_2x.png")
    // println(s"image ${imageURL.getClass}")
    var imageTarget: Target = new ImageTarget(imageURL)
    // var imageTarget: Target = new ImageTarget(new File("y18.gif"))
    var r: ScreenRegion = s.wait(imageTarget, 20000)
    var canvas: Canvas = new DesktopCanvas()
    canvas.addLabel(r, "Hello World").display(3)
    var mouse: Mouse = new DesktopMouse()
    mouse.click(r.getCenter())
    }

}`

When I step through it the place where I perceive the problem to manifest (I'm a noob generally, so I don't know how much this would or wouldn't help) but it seems to happen when I get to AWTRobot's captureScreen method. that takes me to Robot's createScreenCapture method where checkScreenCaptureAllowed's

SecurityManager security = System.getSecurityManager(); has the value of TrapExit@7884

Any help you can offer on this, any at all, would be greatly appreciated.

I'm using Intellij 15.0.4 on a Windows 7 machine and I'm using Scala version 2.11.8 and my SBT dependencies are

`libraryDependencies ++= {
Seq(
"org.sikuli" % "sikuli-api" % "1.2.0",
"org.sikuli" % "sikuli-core" % "1.2.2"

)`

if any of that helps at all.

@ExMateria
Copy link

Okay. I just realized that there's this. https://github.com/RaiMan/SikuliX-2014 with it's api
http://mvnrepository.com/artifact/com.sikulix/sikulixapi/1.1.0

I will now try to stop barking up the wrong tree. Hopefully this will help someone else.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants