Java 从 Eclipse 执行 AutoIt 代码
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/23590413/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Execute AutoIt code from Eclipse
提问by Naseem
I am doing automation using Selenium WebDriver and want to handle a browser authentication window. I know Selenium does not support this on its own but I am able to using AutoIt. We have to share our code with the client, so can AutoIt code be managed from Eclipse? This is the code:
我正在使用 Selenium WebDriver 进行自动化并希望处理浏览器身份验证窗口。我知道 Selenium 本身不支持这一点,但我可以使用 AutoIt。我们必须与客户端共享我们的代码,那么可以从 Eclipse 管理 AutoIt 代码吗?这是代码:
WinWaitActive("Authentication Required", "", "120")
If WinExists("Authentication Required") Then
Send("username{TAB}")
Send("password{Enter}")
EndIf
Code to run the AutoIt.exe from Eclipse:
从 Eclipse 运行 AutoIt.exe 的代码:
Runtime.getRuntime().exec("C:\NewAutoIT.exe");
Is there any way to manage AutoIt code from Eclipse?
有没有办法从 Eclipse 管理 AutoIt 代码?
采纳答案by ron190
You should use library AutoItX4Java, it allows to execute AutoIt commands in Java.
您应该使用库AutoItX4Java,它允许在 Java 中执行 AutoIt 命令。
You need to install AutoIt and use the library Java COM Bridge, then you can program directly in Java. I made a post on my site a while ago, but here is a simple example:
您需要安装 AutoIt 并使用 Java COM Bridge 库,然后您可以直接在 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));