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 :)

Monday, June 16, 2014

Python- Logging Architecture

Python Logging module helps in logging to multiple destination handlers.

It has a very simper architecture as below : -

(1)  Logger,LogObject,Handler and Formatter are the main Actor of this architecture.

(2) There are in total 5 types of severity Levels as defined below with severity in ASCENDING order: -
DEBUG
INFO
WARNING
ERROR
CRITICAL

(3) Logger,Handlers has severity levels

(4) Logger generally inspects the message and does the below 2 operation : -
   
     (4.1)Ignores the message if the message is less severe than the Logger

   (4.2) Otherwise creates LogRecord object from message and passes it to Handler.




(5) Handler responsible for the following 2 tasks : -
  • Outputs message - to a file, stream, socket or where ever you want it to go. You can add a Handler to the Logger by using the addHandler method of the Logger.
  • The Handler also has a level. Once the Handler receives the LogRecord from the Logger, it will ignore any LogRecord that has a severity level that is smaller than its own level. Otherwise it passes the LogRecord to its Formatter

 (6) Each Handler has one Formatter (which you can customize to your taste). The Formatter formats the LogRecord message to the desired format and sends the formatted text back to the Handler.


Putting It All Together :



Thanks . I hope it helps ;)