Search This Blog

Tuesday, June 17, 2014

Sikuli- Not Compulsory But Necessary

Why We Need Sikuli :

There are certain genuine issues that we face while automating web applications using Selenium Webdriver.For eg: -

(1) Compose Mail : - Adding Attachment
(2) Downloading PDF
(3) Printing Page

The reason is as simple as Selenium cant handle window based pop ups .

Lets Get Started :

Now a solution would be not going for finding xpath and locating elements instead locate elements using some unique property.So Sikuli came to existence by detecting components using image based screenshots.

Its as simple as saying , Give the image to Sikuli and Tell me what needs to done and thats it.

Example : A java library if Sikuli is available here

Below is the code to click on a element when image of the element is given to it.

public static String hitOKbtn(String path) {

        try {
            //Create and initialize an instance of Screen object  
            Screen screen = new Screen();

            //Add image path 
            Pattern image = new Pattern(path);

            //Wait 10ms for image
            screen.wait(image, 10);

            //Click on the image
            screen.click(image);

        }catch(Throwable t) {
            // report error
            System.out.println("Error while clicking on element -"+t.getMessage());

            APPLICATION_LOGS.debug("Error while clicking on element -"+t.getMessage());

            return "Fail";
        }

        return "Pass";
    }

Thanks.I hope it helps :)

No comments:

Post a Comment