Favourite Quote

Every artist was first an amateur. - Ralph Waldo Emerson The more difficulties one has to encounter, within and without, the more significant and the higher in inspiration his life will be. - Horace Bushnell

Tuesday, February 19, 2013

Selenium WebDriver and AutoIT


It is often possible in this web world that we get to work with objects which is either out of box,flash or webpages that are added with extra layer of security like a single sign-on for example windows credentials

Also another example is if one works with Microsoft technologies or Oracle CRM Web Applications which are only compatible with IE browsers there LOV(List of Values) popup , not to forget the modal popup

In the above situations it's hard to achieve or progress with automation with Selenium RC/Selenium WebDriver

Hence the simplest and fairly easy option is AutoIT

What is AutoIt ?

AutoIt v3 is a freeware BASIC-like scripting language designed for automating the Windows GUI and general scripting. It uses a combination of simulated keystrokes, mouse movement and window/control manipulation in order to automate tasks in a way not possible or reliable with other languages (e.g. VBScript and SendKeys). AutoIt is also very small, self-contained and will run on all versions of Windows out-of-the-box with no annoying "runtimes" required!

Let's get started with having AutoIt installed on your local box

Download latest version of AutoIt from the official release page here

It's better you download AutoIt Full Installation which will help you in scripting & compiling as well

Once installation is completed you should see the application being installed in your All Programs or which ever location you have installed

Now, let's get started - What is that we are trying to automate or use AutoIt for

Given this Scenario : Of Logging in the windows Authentication to your webapplication

Just like the below screen shot



Now that is quiet a common to have a windows authentication if it's a product built by Microsoft themselves ;)

Here is how the AutoIt Script should look

WinWaitActive("Connect to yourservername","","60") If WinExists("Connect to yourservername") Then ControlSend("Connect to yourservername","", "[CLASS:Edit; INSTANCE:2]","DomainName\username") ControlSend("Connect to yourservername","", "[CLASS:Edit; INSTANCE:3]","Password") ControlClick("Connect to yourservername","","[CLASS:Button; INSTANCE:3,button[,clicks[,153[,223]]]]") EndIf

Once you have the above script compiled - You are all ready to use them in your webDriver / selenium RC script

I assume it should be able to work with both .Net & Java

For now i have just tried only on with WebDriver Java Bindings

So here's the code that goes in your webDriver script

@BeforeClass public static void setUp() { System.setProperty("webdriver.ie.driver", "C:\\Eclipse\\Selenium\\IEDriverServer.exe"); driver = new InternetExplorerDriver(); driver.get("your url"); try { Runtime.getRuntime().exec("C:\\Eclipse\\Selenium\\Autentication.exe"); } catch (IOException e) { e.printStackTrace(); } }

You are all set now : both the code snippets together should help in working on Windows Authentication

If you are keen on learning about how & when should i use working on Image recognition

Read my next post on using Sikuli for doing the same functionality or different scenario

No comments:

Post a Comment