1

如何在 Selenium Grid 设置上运行 AutoIT 脚本?

我在所有机器上都有 .exe 文件,但需要 Selenium 脚本来调用它以在网格的每个节点上运行,这可能吗?

4

3 回答 3

4

您的问题(在撰写本文时)对于网格部署的特定测试设置不是很详细。因此,无法提出确切的答案,因为这取决于您的环境是如何设置的。

最简单的方法是使用 PSExec.exe、telnet 或 SSH 从您的测试执行机器远程调用节点机器上的 AutoIt。下面给出了一个简单的例子,注意我没有测试过代码,但如果需要的话应该做一些小的调整。

String cmd = "C:\\LocalMachinePathTo\\psexec.exe \\\\%s -u %s -p %s -i C:\\GridNodeMachinePathTo\\autoit.exe";
Process p = Runtime.getRuntime().exec(String.format(cmd,gridNodeHostName,gridNodeWindowsLoginUserName,gridNodeWindowsLoginPassword);
p.waitFor();

这个简单的示例假设您使用网格节点机器的本地本地桌面(或控制台/头)会话来运行自动化测试,而不是使用与网格节点的远程桌面会话。如果是后者,那么您需要在 -i 参数之后向 psexec.exe 提供会话 ID。您可以在此处找到有关 PSExec.exe 的更多信息:

http://technet.microsoft.com/en-us/sysinternals/bb897553.aspx

给出的代码是一个简单的例子,你可能更喜欢添加额外的逻辑来检查测试是在本地执行还是在网格上执行,如果在本地执行,你的命令可以省略 psexec 的使用,直接调用 autoit.exe。

阅读这些博客文章以了解更多详细信息/了解如何在 Selenium 网格上运行 AutoIt:

https://autumnator.wordpress.com/2015/01/22/integrating-autoit-sikuli-and-other-tools-with-selenium-when-running-tests-in-selenium-grid/

https://autumnator.wordpress.com/2011/12/22/autoit-sikuli-and-other-tools-with-selenium-grid/

于 2015-01-12T04:23:05.283 回答
0

我通常将 autoit .exe 作为资源打包到 .jar 中。然后你可以做这样的事情:

    // locate an executable script in the resources
    URL res = getClass().getResource("/autoit/autoit_helloworld.exe");
    // locate the script in the filesystem
    File f = new File(res.file);
    assertTrue(f.canExecute());

    Process prog = Runtime.runtime.exec(f.canonicalPath);
    assertEquals(0, prog.waitFor());
于 2014-05-13T15:46:23.447 回答
0

这应该适合你:

String cmd = "C:\\PathToExe\\autoit.exe";
Process p = Runtime.getRuntime().exec(cmd);
p.waitFor();
于 2014-04-28T16:08:22.113 回答