Selenium can interact with the web application only. It cannot automate windows or flash-based objects. In situations where a window authentication pops up, Selenium is unable to handle it. A third-party tool like AutoIt, Sikuli comes to rescue here.
This blog targets automating Windows authentication popup using Sikuli.
When to use Sikuli?
Sikuli is an open-source tool for test automation. Using image recognition technique Sikuli identifies the control GUI components.
It can automate anything which is visible on the screen and is useful when there is no easy access to the GUI’s internal or source code.
Advantages of Sikuli
- Selenium web driver only supports web-based objects but using Sikuli, both windows and web-based objects can be managed
- Selenium web driver cannot support flash objects but using Sikuli we can handle flash objects
- Sikuli can be run on any platform Windows, Mac, Linux
- Sikuli can automate any test which is running on remote servers
- In some cases, if proper web elements are not available, then we can use Sikuli to identify the web elements from the screen
- Sikuli can be integrated with any other tool like Selenium, Cucumber
How to integrate Sikuli with Selenium?
We can integrate Sikuli with selenium in two different ways, which are detailed below:
Adding Sikuli jar file directly to the eclipse IDE
- Download the jar file from the below url https://mvnrepository.com/artifact/org.sikuli/sikuli-api
- Add External jar in the eclipse or any other IDE
Adding sikuli maven dependecny in POM.xml file
- If you are using maven project then copy the sikuli maven dependency from the below url https://mvnrepository.com/artifact/com.sikulix/sikulixapi/1.1.0
- Use the maven dependency in the project POM.xml file and build the project
How to automate the Windows Authentication popup using Sikuli?
- Open the url
- Take the screen shot of Username and store it in a local drive
- Take the screen shot of Password and store it in a local drive
- Take the screen shot of Sign in button and store it in a local drive
- Add the below code snippet for automating the Windows authentication pop up
Details of the code snippet
- First need is to create an object of screen class. The screen class will allow access to all the methods used by sikuli.
- Create an object of the pattern class. The pattern will allow the user to pass the reference of an image on which they want to perform the operation like click, double click, type etc.
When the program is executed, Selenium searches the images which were passed as a reference in the pattern object. After that, the methods available in the screen class for typing and clicking are used.
For operation like typing values in the username field, a pattern object is created for the username field and passed the reference of an image file (uname.png) to the pattern object. After that, using the method of screen class for typing the value in the username field, the action (type, click) will perform if the file exists.The same thing wil happen to typing the value in the Password field and clicking on SignIn button
Sikuli is a powerful tool and it works on any GUI. It can work on any platform (Windows/Linux/Mac) and can interact with virtual machines, remote desktop, and mobile simulators like Android and iPhone. Apart from automating windows based and flash-based application, Sikuli can be helpful in automating mobile testing using Android and iPhone emnulators. Sikuli sees a vast scope in use. It can be used to extract text from an image using its basic text recognition using OCR. While Selenium cannot automate CAPTCHA, using Sikuli we can automate the CAPTCHA in Selenium.