Thursday 6 November 2014

Its Time for change - Get rid of au3 and exe file for using AutoIT

     In this series now I am going to dicuss about how to get rid of au3 files and exe files for using AutoIT. We all know how to use AutoIT along with automation code. Its lengthy and tedious process as we have to write AutoIT code and convert them into exe files and maintain all exe files that you use in your code. 
      Lets try an approach which makes this procedure easy.AutoIT allows for GUI automation using a very simple syntax and can be useful for testing Windows applications. It is packaged with AutoItX which supports accessing AutoIt functions through COM objects.AutoItX4Java uses JACOB to access AutoItX through COM and strives to provide a native Java interface while maintaining the simplicity of AutoIt. Getting started is simple.

Requirements: 
1. AutoIT DLL that supports JACOB protocol jacob-1.17-M2-x86.dll 
2. autoitx4java.jar which uses JACOB a Java bridge to run activex components of Autoit (jacob-1.17-M2-x86.dll) 
Both can be freely downloaded from the below links           
http://code.google.com/p/autoitx4java/downloads/list 
http://sourceforge.net/projects/jacob-project/ or use Autoit.dll  that gets downloaded together with AutoIT installation in windows machine. 
          
Steps used to set up: 
1. Add jacob.jar and autoitx4java.jar to your library path.      
2. Place the jacob-1.15-M4-x64.dll file in your library path.(Create a "lib" folder in project space and place jacob-1.15-M4-x64.dll in the    folder)
3. Start using AutoItX.

//sample code for the above approach
File file = new File("lib", "jacob-1.18-M2-x86.dll"); //path to the jacob dll
System.setProperty(LibraryLoader.JACOB_DLL_PATH, file.getAbsolutePath());
AutoItX x = new AutoItX();
String notepad = "Untitled - Notepad";
String testString = "this is a test.";
AutoITutils.startApp("C:\\Windows\\system32\\notepad.exe");
AutoITutils.waitforAppToLoad(notepad);
AutoITutils.setText(notepad, "Edit1", testString);
String strtemp=AutoITutils.getTextfromField(notepad, "Edit1");
x.winWaitActive(notepad);
x.send(testString);
System.out.println(x.winExists(notepad, testString));        
x.winClose(notepad, testString);
       

2 comments: