How to wait image (clip) before perform any sikuli action

To accomplish any action on image(clip) using sikuli I created below two methods:

public boolean isImagePresent(String image)
    {
        boolean status = false;
        screen = new Screen();
        try {
            screen.find(image);
            status = true;
        } catch (FindFailed e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return status;
    }   

    public void waitForImage(String image, int time) throws InterruptedException{
        for(int i=0; i<time; i++){
            if(isImagePresent(image)){
                break;
            }
            else{
                Thread.sleep(1000);
            }
        }
    }

Call waitForImage() function into your java code as below:

waitForImage("imageName", 20);

Where "imageName" is image clip and second argument is time to wait.

3 comments:

  1. It is awesome.....Thanks a lot....this function solved my issue so quickly

    ReplyDelete
  2. hi, does sikuli work on mobile apps ?? i have to test the image present on map . please guide .

    ReplyDelete

Leave your comments, queries, suggestion I will try to provide solution