简体   繁体   English

AutoItX功能无法在Eclipse中的Java中与Selenium WebDriver一起正常使用

[英]AutoItX functions not working properly with Selenium WebDriver in java in eclipse

Here are 2 standard programs on automating notepad & calculator applications that I found online. 这是我在网上找到的有关自动执行记事本和计算器应用程序的2个标准程序。 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. 我是AutoIt的新手,它尝试学习此脚本并直接在eclipse(java)中练习编码,而不使用autoIt脚本编辑器和编译等。

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. 在计算器代码中,winClose函数不适用于窗口句柄参数,而仅接受窗口标题。 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. 此外,@ SW_SHOW标志和winSetState函数中的其他此类参数也不会被识别并声明为“无法解析为变量。

DO I need to import anything? 我需要导入什么东西吗? The same problem is happening with Windows 8.1 (64 bit) and windows 7 (32 bit). Windows 8.1(64位)和Windows 7(32位)也会发生相同的问题。 I am using Eclipse Luna for Selenium WebDriver with TestNG. 我正在使用带有TestNG的Eclipse Luna for Selenium WebDriver。

Is the eclipse & java not compatible with all AutoItX functions? eclipse和java是否与所有AutoItX函数不兼容?

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)

I have successfully resolved this issue. 我已经成功解决了这个问题。 Needed to add @SW_SHOW tag in x.run("notepad.exe"); 需要在x.run("notepad.exe");添加@SW_SHOW标记x.run("notepad.exe"); command. 命令。 ie x.run("notepad.exe","",AutoItX.SW_SHOW); x.run("notepad.exe","",AutoItX.SW_SHOW); .

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM