MarappPrashanth / sikuli-api

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

Can't get the simple HelloWorldExample example working #9

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
I can't get the hello world example to work.
The following line returns a null value:
ScreenRegion r = s.wait(imageTarget, 5000);

I downloaded two dependencies manually because java complained about missing 
slf4 and log4j. Why aren't theses mentioned in the dependencies?

-------------------------------------------------------
---- What steps will reproduce the problem? ----
-------------------------------------------------------
1. Run the Quick start code
2. Wait for the browser to open webpage
3. wait for another 5 sec for s.wait(imageTarget, 5000);
4. Se the NullPointerException in the log

--- What is the expected output? ---
Displaying "Hello World" next to the target and then clicking on it.

-------------------------------------------------------
----What do you see instead? ----
-------------------------------------------------------
Output:

r: null
Exception in thread "main" java.lang.NullPointerException
    at org.sikuli.api.visual.Canvas.addLabel(Canvas.java:230)
    at HelloWorldExample.main(HelloWorldExample.java:37)

-------------------------------------------------------
--- What version of the product are you using? On what operating system?
-------------------------------------------------------
windows 7 64bit
jdk6 64-bit
sikuli-api-1.0.2-standalone.jar

-------------------------------------------------------
-- Please provide any additional information below. --
-------------------------------------------------------

I am using the following code. The complete Eclipse project: 
http://ge.tt/7HBAtdS/v/0?c

-------------------------------------------------------
--- Code 
-------------------------------------------------------
import java.net.MalformedURLException;
import java.net.URL;

import org.sikuli.api.API;
import org.sikuli.api.DesktopScreenRegion;
import org.sikuli.api.ImageTarget;
import org.sikuli.api.ScreenRegion;
import org.sikuli.api.Target;
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;

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(3);

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

Original issue reported on code.google.com by marton...@gmail.com on 30 Nov 2012 at 11:18

GoogleCodeExporter commented 8 years ago
I am also facing the same issue , I got the SLF4J issue resolved by adding the 
corresponding JAR . But not able to get the Null Pointer cleared . I have tried 
adding s.find also yet to no avail.

Original comment by anup....@gmail.com on 5 Dec 2012 at 6:08

GoogleCodeExporter commented 8 years ago

Original comment by doubles...@gmail.com on 7 Dec 2012 at 11:05

GoogleCodeExporter commented 8 years ago
null pointer means Sikuli isn't able to see the image on the screen. 
can you please provide a screenshot of the screen when Sikuli is trying to find 
the logo of google code? 
Thanks!

Original comment by doubles...@gmail.com on 7 Dec 2012 at 11:11

GoogleCodeExporter commented 8 years ago
Screenshot of my entire desktop. It is taken when I am using a dual screen 
setup.

Original comment by marton...@gmail.com on 7 Dec 2012 at 11:23

Attachments:

GoogleCodeExporter commented 8 years ago
can you try two things?
1. Test with a single monitor configuration.
2. Try
ScreenRegion s = new DesktopScreenRegion();
s.setScreen(new DesktopScreen(1));

please let us know whether if either (or both) solutions work

Original comment by doubles...@gmail.com on 7 Dec 2012 at 7:32

GoogleCodeExporter commented 8 years ago
OMG!
I am so sorry! Both at home and work I had a browser zoom-level set at 
something other then 100% That is why it did not find anything >_<

The code from my first post works as it should when the browser zoom-level is 
set to 100%. The Hello world is showing up and the mouse is clicking on the 
logo.

Thank you for the support! And I apologize again for searching for somehting 
that was not broken.

Now I can start playing with this API :)

Original comment by marton...@gmail.com on 7 Dec 2012 at 8:06

GoogleCodeExporter commented 8 years ago

Original comment by doubles...@gmail.com on 7 Dec 2012 at 8:19

GoogleCodeExporter commented 8 years ago
Even I can't get the hello world example to work.
I followed the same steps. I am getting error

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)

Original comment by roopapat...@gmail.com on 23 Mar 2013 at 6:00

GoogleCodeExporter commented 8 years ago
It sounds like a network connection issue. My test code in the first post is 
still working for me.
Are you behind a proxy? Slow internet connection? etc.

Try this code snippet to test if it is a network issue.
-----------------------------------------------------
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
public static void main(String[] args) {
    try {
        URL imageURL = new URL("http://code.google.com/images/code_logo.gif");
        Object ob = imageURL.getContent();
        System.out.println("This object should be an image class of some sort: " + ob);
    } catch (MalformedURLException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
}
-----------------------------------------------------

I get the following output:
"This object should be an image class of some sort: 
sun.awt.image.URLImageSource@587bd9f2"

Original comment by marton...@gmail.com on 23 Mar 2013 at 1:54

GoogleCodeExporter commented 8 years ago
Thank you.. now its working for me tooo!!!!!!!!1111

Original comment by roopapat...@gmail.com on 24 Mar 2013 at 4:03

GoogleCodeExporter commented 8 years ago
I am trying this code 1st time and its not working and getting smae errors. 
could you please help me where i am getting wrong

Original comment by er.deep...@gmail.com on 29 Aug 2013 at 6:04

GoogleCodeExporter commented 8 years ago
Answer to @er.deep...@gmail.com
There are two kind of errors mentioned in this ticket. You have to be more 
specific.

Have you tried to download my eclipse project mentioned at the top? 
http://ge.tt/7HBAtdS/v/0?c

For example: 

-[ Error 1 ]-
Exception in thread "main" java.lang.NullPointerException
    at org.sikuli.api.visual.Canvas.addLabel(Canvas.java:230)
    at HelloWorldExample.main(HelloWorldExample.java:37)

-[ Error 2 ]-
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)

Original comment by marton...@gmail.com on 29 Aug 2013 at 12:52

GoogleCodeExporter commented 8 years ago
I came across same issue. find is returning null and my zoom level on the 
browser is set to 100%. sikuli script worked reliably but i can't get the find 
working in sikuli API. what am i doing wrong? it is the same example posted in 
this thread is what i am using.

Original comment by mala.mun...@gmail.com on 3 Mar 2014 at 8:12

GoogleCodeExporter commented 8 years ago
s.setScreen(new DesktopScreen(1));

This only seems to work if I move my browser to the main screen manually first 
and even then this code here doesn't seem to do anything 

                Canvas canvas = new DesktopCanvas();
                canvas.addLabel(r, "Hello World").display(3);

Original comment by Peter.la...@googlemail.com on 12 Nov 2014 at 2:20