Can't get onAppear to work.

Asked by Spencer Keller

Hello,

I'm evaluating SikuliX (V1.1.0) as a possible testing tool for our automation test effort. At present I'm writing all of my tests in Java as I know the language much better than Python. So here's my problem, my event handles never seem to get called. The code below is running on Windows 7 and the two images are of the Windows Start button and the color picker from Paint. When I run this program it clicks the start button and the Windows start menu appears I then manually click on Paint and it appears. I would assume that as soon as Paint appeared my handler would be called but it is not. I've tried a couple of the onAppear, onVanish, onChange and I can't seem to get any of them to work. Any help or working Java examples would be appreciated.

Thanks,
Spence

import org.sikuli.script.ObserveEvent;
import org.sikuli.script.ObserverCallBack;
import org.sikuli.script.Screen;

public class SikulixEval
   {
   public static void main(String[] args)
      {
      Screen screen = new Screen();
      try
         {
         screen.onAppear("images/ColorPicker.png", new ObserverCallBack()
            {
               @Override
               public void appeared(ObserveEvent event)
                  {
                  try
                     {
                     System.out.println("Handler called.");
                     }
                  catch (Exception exc)
                     {
                     }
                  }
            });
         screen.click("images/StartButton.png");
         Thread.sleep(10000);
         }
      catch (Exception e)
         {
         }
      System.out.println("Finished.");
      }
   }

Question information

Language:
English Edit question
Status:
Solved
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Solved by:
Spencer Keller
Solved:
Last query:
Last reply:
Revision history for this message
Spencer Keller (spencer-keller) said :
#1

I figured it out from the JavaDoc. I was not starting an observer thread. Duh.

Thanks,
Spence
---------------------------------

import org.sikuli.script.ObserveEvent;
import org.sikuli.script.ObserverCallBack;
import org.sikuli.script.Screen;

public class SikulixEval
   {
   public static void main(String[] args)
      {
      Screen screen = new Screen();
      try
         {
         screen.onAppear("images/ColorPicker.png", new ObserverCallBack()
            {
               @Override
               public void appeared(ObserveEvent event)
                  {
                  try
                     {
                     System.out.println("Handler called.");
                     event.getRegion().stopObserver();
                     }
                  catch (Exception exc)
                     {
                     }
                  }
            });
         screen.click("images/StartButton.png");
         Thread.sleep(5000);
         screen.observe(); // <----- Started an observer.
         Thread.sleep(10000);
         }
      catch (Exception e)
         {
         }
      System.out.println("Finished.");
      }
   }