AutoItX4Java - Java AutoIt Bridge

AutoIt is a very useful automation scripting language for Microsoft Windows. It allows for GUI automation using a very simple syntax and can be useful for testing applications. It is packaged with AutoItX which supports accessing AutoIt functions through COM objects.

I just created a new project on Google Code for Java AutoItX bindings. The project is called AutoItX4Java and uses the JACOB Java COM Bridge to access AutoItX functions. Currently the project is in an unstable state but hopefully as time goes on things will get better tested.

Using AutoItX4Java is simple:
  1. Download JACOB.
  2. Download and install AutoIt. (or register the dll. See below)
  3. Add jacob.jar and autoitx4java.jar to your library path.
  4. Place the jacob-1.15-M4-x64.dll file in your library path.

A simple example of using this library is below:
        File file = new File("lib", "jacob-1.15-M4-x64.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 text.";
        x.run("notepad.exe");
        x.winActivate(notepad);
        x.winWaitActive(notepad);
        x.send(testString);
        Assert.assertTrue(x.winExists(notepad, testString));
        x.winClose(notepad, testString);
        x.winWaitActive("Notepad");
        x.send("{ALT}n");
        Assert.assertFalse(x.winExists(notepad, testString));
Troubleshooting: Be sure to use the correct version of the Jacob and AutoItX3 dlls. Both come in x86 and x64 versions.

If you need to test whether AutoItX is setup, just enter powershell and do the following:
$x = New-Object -comObject "AutoItX3.Control"
$x.run("Notepad.exe")
If that does not work ensure the AutoItX3.dll is loaded.
regsvr32.exe AutoItX3.dll
or
regsvr32.exe AutoItX3_x64.dll
You will also have to be in the x64 version of powershell for this test to work.

If your program never stops you can control how Jacob threading works as described here:
        ComThread.InitMTA();
        AutoItX x = new AutoItX();
        x.run("calc.exe");
        ComThread.Release();

Comments

  1. Hi, Very nice explanation. However where i can download required autoitjar file?

    ReplyDelete
    Replies
    1. i am getting below error.
      java.lang.UnsatisfiedLinkError: Can't load library: C:\WINDOWS\system32jacob-1.15-M4-x64.dll
      at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1706)

      Please advice

      Delete
  2. Could you give the sources of jar?

    ReplyDelete
    Replies
    1. you can check http://code.google.com/p/autoitx4java/source/checkout

      Delete
  3. how do I automate Excel (Open/Edit/Close) using autoitx4java in eclipse

    ReplyDelete
  4. This comment has been removed by the author.

    ReplyDelete
  5. This comment has been removed by the author.

    ReplyDelete

Post a Comment

Popular posts from this blog

The SQL Server and .Net equivalent of PHP and MySQL's SHA1 function

RTL8723AU Realtek driver fails after linux update fix.