tradt / sikuli-api

Automatically exported from code.google.com/p/sikuli-api
0 stars 0 forks source link

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

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
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("http://code.google.com"));

                // 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("http://code.google.com/images/code_logo.gif");                
                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 "Hello World" next to the found target for 3 seconds
                Canvas canvas = new DesktopCanvas();
                System.out.println("r: " + r); 
                canvas.addLabel(r, "Hello World").display(5);

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

Original issue reported on code.google.com by roopapat...@gmail.com on 23 Mar 2013 at 6:10

GoogleCodeExporter commented 9 years ago
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"));

Original comment by o.bell...@gmail.com on 4 Jun 2013 at 10:05

GoogleCodeExporter commented 9 years ago

Original comment by doubles...@gmail.com on 13 Jun 2013 at 9:46

GoogleCodeExporter commented 9 years ago
I encountered the same issue with you, but i run the program at my office, the 
PC connected the network via the Proxy server. So when I added the the proxy 
configuration to the program like below:

System.setProperty("http.proxyHost", "proxy server of you");  
System.setProperty("http.proxyPort", "8080"); 

Run the program, it can work normal

Original comment by davidyan...@gmail.com on 27 May 2014 at 6:19