0

Here are 2 standard programs on automating notepad & calculator applications that I found online. I am new to AutoIt and trying to learn this script and practice coding directly in eclipse (java) without using autoIt script editor and compiling etc.

Problem is while the Calculator code is running fine, the notepad application is not opening at all. In fact, notepad is showing as an application running in background in task manager, but is not displayed. I also tried the wordpad, it is also not opening.

In calculator code, winClose function is not working with window handle argument but accepting only window Title. Also the @SW_SHOW flag and other such arguments in winSetState function are not being recognized and stated as "cannot be resolved to a variable.

DO I need to import anything? The same problem is happening with Windows 8.1 (64 bit) and windows 7 (32 bit). I am using Eclipse Luna for Selenium WebDriver with TestNG.

Is the eclipse & java not compatible with all AutoItX functions?

package autoit_trial;

import java.io.File;
import org.testng.Assert;
import autoitx4java.AutoItX;
import com.jacob.com.LibraryLoader;

public class Calculator {

    public static void main(String[] args) {

    File file = new File("lib","jacob-1.18-M2-x64.dll");
    System.setProperty(LibraryLoader.JACOB_DLL_PATH, file.getAbsolutePath());
    AutoItX x = new AutoItX();    
    /*
    x.run("calc.exe");
    x.winActivate("Calculator");
    x.winWaitActive("Calculator");
    x.controlClick("Calculator", "", "133");
    x.sleep(1000);
    x.controlClick("Calculator", "", "92");
    x.sleep(1000);
    x.controlClick("Calculator", "", "137");
    x.sleep(1000);
    x.controlClick("Calculator", "", "121");
    x.sleep(1000);
    String winhand = x.winGetHandle("Calculator","");
    System.out.println(winhand);
    x.winClose("Calculator","");
    */
    x.run("notepad.exe");
    String notepad = "Untitled - Notepad";
    String testString = "this is a test.";
    x.winActivate(notepad);
    // x.winSetState(notepad, testString, @SW_SHOW);
    x.winWaitActive(notepad,"",10);
    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)); 

    } 
}

this is the error on running the code above

Exception in thread "main" java.lang.AssertionError: expected [true] but found [false]
at org.testng.Assert.fail(Assert.java:94)
at org.testng.Assert.failNotEquals(Assert.java:494)
at org.testng.Assert.assertTrue(Assert.java:42)
at org.testng.Assert.assertTrue(Assert.java:52)
at autoit_trial.Calculator.main(Calculator.java:39)
2
  • I have written the above Calculator and Notepad code in AutoIT script and run the resultant autoIt exe file in java using java.lang.Runtime. It works fine in autoIt script but in java the first line itself is not working i.e x.run("notepad.exe"); Commented Jan 27, 2015 at 6:28
  • I have successfully resolved the issue today. Needed to add @SW_SHOW tag in x.run("notepad.exe"); command. i.e. x.run("notepad.exe","",AutoItX.SW_SHOW); Hence I am closing this question here. Commented Jan 27, 2015 at 7:50

1 Answer 1

1

I have successfully resolved this issue. Needed to add @SW_SHOW tag in x.run("notepad.exe"); command. i.e. x.run("notepad.exe","",AutoItX.SW_SHOW);.

Sign up to request clarification or add additional context in comments.

2 Comments

All the commands in the above program are working fine, except window handle. Function x.winGetHandle("Calculator") returns a string depicting the windowhandle. The java functions are working fine with window title as string argument but do not work with window handle string. The command w.winClose(windowhandle) is not working. AutoIt script in .au3 format works fine with window handles but in AutoItX4Java it does not work. How do I handle multiple OS windows such as notepad etc. with same title. How to make window handle work properly in java ?
No vote in nearly 6 years? I voted it, because this solved my problem! Additionally now I know where to find (a few) AutoIt constants in the .NET wrapper. I didn't found out this before. Thanks! (remark: Just a half hour ago I asked the AutoIt team to add constants to the wrapper library.)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.