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.

4 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
  3. i have 2 windows if i want to switch from one window to another ,im using driver.switchto.window("abc"); but its not working pls anyone gide me

    ReplyDelete

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