从Eclipse执行AutoIt代码

3

我正在使用Selenium WebDriver进行自动化,想要处理浏览器身份验证窗口。我知道Selenium自己不支持这个功能,但我可以使用AutoIt实现。我们需要与客户共享代码,那么AutoIt代码是否可以从Eclipse中管理?以下是代码:

WinWaitActive("Authentication Required", "", "120")
If WinExists("Authentication Required") Then
   Send("username{TAB}")
   Send("password{Enter}")
EndIf

在 Eclipse 中运行 AutoIt.exe 的代码:

Runtime.getRuntime().exec("C:\\NewAutoIT.exe");

有没有办法从Eclipse管理AutoIt代码?
1个回答

10

您应该使用AutoItX4Java库,它允许在Java中执行AutoIt命令。

您需要安装AutoIt并使用Java COM桥接器库,然后可以直接在Java中编程。我之前在我的网站上发布了一篇文章,但这里是一个简单的示例:

    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 test.";
    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));

1
谢谢Ron...我成功地在我的项目中使用Jacob实现了AutoiTX。只想补充一点,就是运行这个程序还需要在机器上安装Auto IT。 - Naseem
1
那是个好观点,Naseem。如果这个软件被销售,你必须确保依赖项在安装程序中得到覆盖。这很容易被忽略。 - Hesein Burg
以下是关于此事的详细解释和细节。https://www.joecolantonio.com/2014/07/02/selenium-autoit-how-to-automate-non-browser-based-functionality/ - Sariq Shaikh

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接