AutoIt is a freeware application that is designed to help automate Windows-based UIs. The normal procedure is to create AutoIT scripts using the built-in BASIC-like programming language like Win32. But this is not an optimal solution.
Instead of that Can we able to develop in Java? Answer is Yes! You Can!
You can access AutoIt through COM using Jacob, Which is Java Com Bridge.
This can be possible using our normal Eclipse IDE.
No need to install separate AutoIt. Just Register AutoItX3.dll.
Following are the steps to configure AutoIt.
Step 1: Open Eclipse. Create your new Java Project AutoIt.
Step 2: In the Windows directory where the AutoIT project is saved, create a new directory named lib.
Step 3: Download the JACOB Java COM bridge from
Step 4: Download the AutoIt Zip file option from
Step 5: Download the AutoItXJava.jar file from
Step 6: Extract Jacob zip file.
Step 7: Copy the jacob.jar, jacob-1.18-M2-x64.dll and jacob-1.18-M2-x64.dll filed and place them in the AutoIT>Lib folder we created earlier.
Step 8: Move downloaded file AutoItX4java.jar to AutoIt>Lib directory.
Now Your AutoIT>lib directory should now have these four files:
AutoItX4Java.jar
Jacob.jar
Jacob-1.18-M2-x64.dll
Jacob-1.18-M2-x86.dll
Create another folder under your project named tools/autoit
Navigate to the folder where you extracted AutoIt and copy the AutoItX3.dll, jacob-1.18-x64.dll, jacob-1.18-x86.dll into the tools/autoit directory.
In Eclipse, right click on the AutoIt project and click Refresh
Right click on the AutoIt project again and select Properties
Under the Java Build Path, click on the Libraries tab.
Click on the Add JARS. Button.
Navigate to the lib folder we created and add:
AutoItX4Java.jar
Jacob.jar
Now, Since We don't have installed AutoIt. We need to register it's dll file using following command.
regsvr32 your path/AutoItX3.dll
In My case:
regsvr32 E:/Automation/AutoIt/tools/autoit/AutoItX3.dll
Here You have done with AutoIt setup. You should now able to call AutoItX methods directly from Java. Let’s look at how this can be done
import java.awt.AWTException;
import java.awt.Robot;
import java.awt.event.KeyEvent;
import java.io.File;
import javax.swing.JOptionPane;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.Select;
import autoitx4java.AutoItX;
import com.jacob.com.LibraryLoader;
public class TestAutoIt {
/**
* @param args
* @throws InterruptedException
* @throws AWTException
*/
public static void main(String[] args) throws InterruptedException, AWTException {
// TODO Auto-generated method stub
//Declare instance driver for FireFox class
WebDriver driver=new FirefoxDriver();
File file = new File("lib", "jacob-1.18-x86.dll");
System.setProperty(LibraryLoader.JACOB_DLL_PATH, file.getAbsolutePath());
//Open url
driver.get("file:///F:/Automation%20Stuff/Form.html");
//Click on Browse button
driver.findElement(By.className("form-control-static")).click();
//Set Path for Jacob dll file
System.setProperty("jacob-1.18-x86.dll","E:/Automation/AutoIt/tools/autoit/jacob-1.18-x86.dll");
// Declare Object for AutoIt class AutoItX x = new AutoItX();
// Here File Upload window get active. x.winWaitActive("File Upload");
// Here Send Method is use for assigning file location.(currently It's Desktop)
x.send("Gopal.jpg");
Robot r = new Robot();
//Robot Class is use for selecting open button
r.keyPress(KeyEvent.VK_ENTER);
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
driver.findElement(By.id("upload")).click();
}
}
Now, Since We don't have installed AutoIt. We need to register it's dll file using following command.
regsvr32 your path/AutoItX3.dll
In My case:
regsvr32 E:/Automation/AutoIt/tools/autoit/AutoItX3.dll
Here You have done with AutoIt setup. You should now able to call AutoItX methods directly from Java. Let’s look at how this can be done
Upload File using AutoIt
import java.awt.Robot;
import java.awt.event.KeyEvent;
import java.io.File;
import javax.swing.JOptionPane;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.Select;
import autoitx4java.AutoItX;
import com.jacob.com.LibraryLoader;
public class TestAutoIt {
/**
* @param args
* @throws InterruptedException
* @throws AWTException
*/
public static void main(String[] args) throws InterruptedException, AWTException {
// TODO Auto-generated method stub
//Declare instance driver for FireFox class
WebDriver driver=new FirefoxDriver();
File file = new File("lib", "jacob-1.18-x86.dll");
System.setProperty(LibraryLoader.JACOB_DLL_PATH, file.getAbsolutePath());
//Open url
driver.get("file:///F:/Automation%20Stuff/Form.html");
//Click on Browse button
driver.findElement(By.className("form-control-static")).click();
//Set Path for Jacob dll file
System.setProperty("jacob-1.18-x86.dll","E:/Automation/AutoIt/tools/autoit/jacob-1.18-x86.dll");
// Declare Object for AutoIt class AutoItX x = new AutoItX();
// Here File Upload window get active. x.winWaitActive("File Upload");
// Here Send Method is use for assigning file location.(currently It's Desktop)
x.send("Gopal.jpg");
Robot r = new Robot();
//Robot Class is use for selecting open button
r.keyPress(KeyEvent.VK_ENTER);
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
driver.findElement(By.id("upload")).click();
}
}
Excellent narration!! Expecting more articles from you sir
ReplyDeleteThank yo so much... :)
DeleteThis comment has been removed by the author.
Delete