Thursday, March 03, 2011

Using JNative to load AutoITX.dll

I am working on JNative to load AutoITX.dll, and get my complex UI methods work for WebDriver.

First download JNative.jar from website then add JNative.jar to your build path.

Download your AutoITX from http://www.autoitscript.com/site/autoit/downloads/
2 useful docs which you can refer to:
Function reference
http://www.autoitscript.com/autoit3/docs/functions.htm
and AutoITX Help doc -> DLL interface introduction(Find it after installing AutoITV3)

Then start to create your own method based on AutoITX great Functions which in AutoITX.dll

Here is a sample code to create mouse move methods in Java

 package org;  
 import org.xvolks.jnative.JNative;  
 import org.xvolks.jnative.exceptions.NativeException;  
 public class LoadDllSample {  
      public static void main(String[] args) throws IllegalAccessException {  
           // TODO Auto-generated method stub            
           try {  
                GetMyMouseMove(100, 100 ,40);  
           } catch (NativeException e) {  
                // TODO Auto-generated catch block  
                e.printStackTrace();  
           }  
      }  
      /*  
       *      AutoItX Interface For AU3_MouseMove() Function  
            AU3_API long WINAPI AU3_MouseMove(long nX, long nY, long nSpeed);  
       */  
      public static void GetMyMouseMove(int x, int y, int s) throws NativeException, IllegalAccessException{  
           JNative nGetMyMouseMove = new JNative("C:\\Program Files\\AutoIt3\\AutoItX\\AutoItX3.dll", "AU3_MouseMove");  //load .dll file and specific func
           nGetMyMouseMove.setParameter(0,x);//The screen x coordinate to move the mouse to.  
           nGetMyMouseMove.setParameter(1,y);//The screen y coordinate to move the mouse to.  
           nGetMyMouseMove.setParameter(2,s);//The speed s to move the mouse (optional)  
           nGetMyMouseMove.invoke();  
           return;  
      }  
 }  

I will work on more functions and hope they may help my WebDriver automation tests soon :) Enjoy!

Update: The source code has been uploaded to my github, check it out if you like : https://github.com/joychester/AutoIT-in-Java

No comments:

Post a Comment